GetFromFile without FileInfo (#1913)

* GetFromFile without FileInfo

* Implement missing interface member
This commit is contained in:
RyouBakura 2024-07-24 20:07:23 +02:00 committed by GitHub
parent 426eaec0f2
commit def28b37c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View file

@ -45,6 +45,10 @@ internal sealed partial class TextureManager
ISharedImmediateTexture ITextureProvider.GetFromFile(FileInfo file) => ISharedImmediateTexture ITextureProvider.GetFromFile(FileInfo file) =>
this.Shared.GetFromFile(file); this.Shared.GetFromFile(file);
/// <inheritdoc/>
public ISharedImmediateTexture GetFromFileAbsolute(string fullPath) =>
this.Shared.GetFromFileAbsolute(fullPath);
/// <inheritdoc/> /// <inheritdoc/>
ISharedImmediateTexture ITextureProvider.GetFromManifestResource(Assembly assembly, string name) => ISharedImmediateTexture ITextureProvider.GetFromManifestResource(Assembly assembly, string name) =>
this.Shared.GetFromManifestResource(assembly, name); this.Shared.GetFromManifestResource(assembly, name);
@ -141,7 +145,12 @@ internal sealed partial class TextureManager
/// <inheritdoc cref="ITextureProvider.GetFromFile(FileInfo)"/> /// <inheritdoc cref="ITextureProvider.GetFromFile(FileInfo)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public SharedImmediateTexture.PureImpl GetFromFile(FileInfo file) => public SharedImmediateTexture.PureImpl GetFromFile(FileInfo file) =>
this.fileDict.GetOrAdd(file.FullName, FileSystemSharedImmediateTexture.CreatePlaceholder) this.GetFromFileAbsolute(file.FullName);
/// <inheritdoc cref="ITextureProvider.GetFromFileAbsolute(string)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public SharedImmediateTexture.PureImpl GetFromFileAbsolute(string fullPath) =>
this.fileDict.GetOrAdd(fullPath, FileSystemSharedImmediateTexture.CreatePlaceholder)
.PublicUseInstance; .PublicUseInstance;
/// <inheritdoc cref="ITextureProvider.GetFromManifestResource"/> /// <inheritdoc cref="ITextureProvider.GetFromManifestResource"/>

View file

@ -313,6 +313,14 @@ internal sealed class TextureManagerPluginScoped
return shared; return shared;
} }
/// <inheritdoc/>
public ISharedImmediateTexture GetFromFileAbsolute(string fullPath)
{
var shared = this.ManagerOrThrow.Shared.GetFromFileAbsolute(fullPath);
shared.AddOwnerPlugin(this.plugin);
return shared;
}
/// <inheritdoc/> /// <inheritdoc/>
public ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name) public ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name)
{ {

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -232,6 +232,15 @@ public interface ITextureProvider
/// </remarks> /// </remarks>
ISharedImmediateTexture GetFromFile(FileInfo file); ISharedImmediateTexture GetFromFile(FileInfo file);
/// <summary>Gets a shared texture corresponding to the given file on the filesystem.</summary>
/// <param name="fullPath">The file on the filesystem to load. Requires a full path.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
/// <remarks>
/// <para>This function does not throw exceptions.</para>
/// <para>Caching the returned object is not recommended. Performance benefit will be minimal.</para>
/// </remarks>
ISharedImmediateTexture GetFromFileAbsolute(string fullPath);
/// <summary>Gets a shared texture corresponding to the given file of the assembly manifest resources.</summary> /// <summary>Gets a shared texture corresponding to the given file of the assembly manifest resources.</summary>
/// <param name="assembly">The assembly containing manifest resources.</param> /// <param name="assembly">The assembly containing manifest resources.</param>
/// <param name="name">The case-sensitive name of the manifest resource being requested.</param> /// <param name="name">The case-sensitive name of the manifest resource being requested.</param>