Skip to content

Commit

Permalink
GetFromFile without FileInfo (#1913)
Browse files Browse the repository at this point in the history
* GetFromFile without FileInfo

* Implement missing interface member
  • Loading branch information
RyouBakura committed Jul 24, 2024
1 parent 426eaec commit def28b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ ISharedImmediateTexture ITextureProvider.GetFromFile(string path) =>
ISharedImmediateTexture ITextureProvider.GetFromFile(FileInfo file) =>
this.Shared.GetFromFile(file);

/// <inheritdoc/>
public ISharedImmediateTexture GetFromFileAbsolute(string fullPath) =>
this.Shared.GetFromFileAbsolute(fullPath);

/// <inheritdoc/>
ISharedImmediateTexture ITextureProvider.GetFromManifestResource(Assembly assembly, string name) =>
this.Shared.GetFromManifestResource(assembly, name);
Expand Down Expand Up @@ -141,7 +145,12 @@ public SharedImmediateTexture.PureImpl GetFromFile(string path) =>
/// <inheritdoc cref="ITextureProvider.GetFromFile(FileInfo)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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;

/// <inheritdoc cref="ITextureProvider.GetFromManifestResource"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ public ISharedImmediateTexture GetFromFile(FileInfo file)
return shared;
}

/// <inheritdoc/>
public ISharedImmediateTexture GetFromFileAbsolute(string fullPath)
{
var shared = this.ManagerOrThrow.Shared.GetFromFileAbsolute(fullPath);
shared.AddOwnerPlugin(this.plugin);
return shared;
}

/// <inheritdoc/>
public ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name)
{
Expand Down
11 changes: 10 additions & 1 deletion Dalamud/Plugin/Services/ITextureProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -232,6 +232,15 @@ Task<IDalamudTextureWrap> CreateFromTexFileAsync(
/// </remarks>
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>
/// <param name="assembly">The assembly containing manifest resources.</param>
/// <param name="name">The case-sensitive name of the manifest resource being requested.</param>
Expand Down

0 comments on commit def28b3

Please sign in to comment.