mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
remove an unnecessary allocation, minor cleanup
This commit is contained in:
parent
51b7856dae
commit
7d558b6bb5
2 changed files with 15 additions and 12 deletions
|
|
@ -111,9 +111,9 @@ namespace Penumbra.Mods
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FileInfo GetCandidateForGameFile( string resourcePath )
|
public FileInfo GetCandidateForGameFile( string gameResourcePath )
|
||||||
{
|
{
|
||||||
var val = ResolvedFiles.TryGetValue( resourcePath.ToLowerInvariant(), out var candidate );
|
var val = ResolvedFiles.TryGetValue( gameResourcePath, out var candidate );
|
||||||
if( !val )
|
if( !val )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -127,9 +127,16 @@ namespace Penumbra.Mods
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSwappedFilePath( string originalPath )
|
public string GetSwappedFilePath( string gameResourcePath )
|
||||||
{
|
{
|
||||||
return SwappedFiles.TryGetValue( originalPath, out var swappedPath ) ? swappedPath : null;
|
return SwappedFiles.TryGetValue( gameResourcePath, out var swappedPath ) ? swappedPath : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ResolveSwappedOrReplacementFilePath( string gameResourcePath )
|
||||||
|
{
|
||||||
|
gameResourcePath = gameResourcePath.ToLowerInvariant();
|
||||||
|
|
||||||
|
return GetCandidateForGameFile( gameResourcePath )?.FullName ?? GetSwappedFilePath( gameResourcePath );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,19 +158,15 @@ namespace Penumbra
|
||||||
PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath );
|
PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var replacementPath = Plugin.ModManager.ResolveSwappedOrReplacementFilePath( gameFsPath );
|
||||||
var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath );
|
|
||||||
var swappedFilePath = Plugin.ModManager.GetSwappedFilePath( gameFsPath );
|
|
||||||
|
|
||||||
var fsPath = candidate?.FullName ?? swappedFilePath;
|
|
||||||
|
|
||||||
// path must be < 260 because statically defined array length :(
|
// path must be < 260 because statically defined array length :(
|
||||||
if( fsPath == null || fsPath.Length >= 260 )
|
if( replacementPath == null || replacementPath.Length >= 260 )
|
||||||
{
|
{
|
||||||
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
}
|
}
|
||||||
|
|
||||||
var cleanPath = fsPath.Replace( '\\', '/' );
|
var cleanPath = replacementPath.Replace( '\\', '/' );
|
||||||
var path = Encoding.ASCII.GetBytes( cleanPath );
|
var path = Encoding.ASCII.GetBytes( cleanPath );
|
||||||
|
|
||||||
var bPath = stackalloc byte[path.Length + 1];
|
var bPath = stackalloc byte[path.Length + 1];
|
||||||
|
|
@ -182,7 +178,7 @@ namespace Penumbra
|
||||||
*pResourceHash = Crc32.Checksum;
|
*pResourceHash = Crc32.Checksum;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, fsPath );
|
PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, replacementPath );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue