Support path substitution to filesystem file (#1920)

This commit is contained in:
srkizer 2024-07-11 18:44:22 +09:00 committed by GitHub
parent 2cbb8b9e22
commit 823ec47d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,11 +3,12 @@ using System.Threading;
using System.Threading.Tasks;
using Dalamud.Data;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Textures.TextureWraps;
using Lumina.Data.Files;
using Serilog;
namespace Dalamud.Interface.Textures.Internal.SharedImmediateTextures;
/// <summary>Represents a sharable texture, based on a file in game resources.</summary>
@ -35,9 +36,39 @@ internal sealed class GamePathSharedImmediateTexture : SharedImmediateTexture
{
var dm = await Service<DataManager>.GetAsync();
var tm = await Service<TextureManager>.GetAsync();
TexFile? file;
var substPath = tm.GetSubstitutedPath(this.path);
if (dm.GetFile<TexFile>(substPath) is not { } file)
throw new FileNotFoundException();
if (!string.IsNullOrWhiteSpace(substPath) && substPath != this.path)
{
try
{
file =
Path.IsPathRooted(this.path)
? dm.GameData.GetFileFromDisk<TexFile>(substPath, this.path)
: dm.GetFile<TexFile>(substPath) ??
throw new FileNotFoundException("Game file not found.", substPath);
}
catch (Exception e)
{
file = dm.GetFile<TexFile>(this.path);
if (file is null)
throw;
Log.Warning(
e,
"{who}: substitute path {subst} for {orig} failed to load. Using original path instead.",
nameof(GamePathSharedImmediateTexture),
substPath,
this.path);
}
}
else
{
file = dm.GetFile<TexFile>(this.path) ?? throw new FileNotFoundException("Game file not found.", this.path);
}
cancellationToken.ThrowIfCancellationRequested();
var wrap = tm.NoThrottleCreateFromTexFile(file);
tm.BlameSetName(wrap, this.ToString());