fix utf16 paths (se why???) and probably make ttmp importing more better

This commit is contained in:
Adam 2020-12-26 13:59:21 +11:00
parent 748c45a461
commit 055399a7e7
2 changed files with 20 additions and 17 deletions

View file

@ -162,27 +162,27 @@ namespace Penumbra
var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath );
var swappedFilePath = Plugin.ModManager.GetSwappedFilePath( gameFsPath );
var path = candidate?.FullName ?? swappedFilePath;
var fsPath = candidate?.FullName ?? swappedFilePath;
// path must be < 260 because statically defined array length :(
if( path == null || path.Length >= 260 )
if( fsPath == null || fsPath.Length >= 260 )
{
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
}
var cleanPath = path.Replace( '\\', '/' );
var utfPath = Encoding.UTF8.GetBytes( cleanPath );
var cleanPath = fsPath.Replace( '\\', '/' );
var path = Encoding.ASCII.GetBytes( cleanPath );
var bPath = stackalloc byte[utfPath.Length + 1];
Marshal.Copy( utfPath, 0, new IntPtr( bPath ), utfPath.Length );
var bPath = stackalloc byte[path.Length + 1];
Marshal.Copy( path, 0, new IntPtr( bPath ), path.Length );
pPath = ( char* )bPath;
Crc32.Init();
Crc32.Update( utfPath );
Crc32.Update( path );
*pResourceHash = Crc32.Checksum;
#if DEBUG
PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, path );
PluginLog.Log( "[GetResourceHandler] resolved {GamePath} to {NewPath}", gameFsPath, fsPath );
#endif
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
@ -206,7 +206,8 @@ namespace Penumbra
pFileDesc->FileMode = FileMode.LoadUnpackedResource;
var utfPath = Encoding.UTF8.GetBytes( gameFsPath );
// note: must be utf16
var utfPath = Encoding.Unicode.GetBytes( gameFsPath );
Marshal.Copy( utfPath, 0, new IntPtr( &pFileDesc->UtfFileName ), utfPath.Length );
@ -215,7 +216,6 @@ namespace Penumbra
pFileDesc->FileDescriptor = fd;
return ReadFile( pFileHandler, pFileDesc, priority, isSync );
}

View file

@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
@ -18,7 +17,7 @@ namespace Penumbra.UI
{
private readonly Plugin _plugin;
public bool Visible { get; set; } = true;
public bool Visible = false;
private static readonly Vector2 AutoFillSize = new Vector2( -1, -1 );
private static readonly Vector2 ModListSize = new Vector2( 200, -1 );
@ -43,9 +42,9 @@ namespace Penumbra.UI
{
ImGui.SetNextWindowSizeConstraints( MinSettingsSize, MaxSettingsSize );
#if DEBUG
var ret = ImGui.Begin( _plugin.PluginDebugTitleStr );
var ret = ImGui.Begin( _plugin.PluginDebugTitleStr, ref Visible );
#else
var ret = ImGui.Begin( _plugin.Name );
var ret = ImGui.Begin( _plugin.Name, ref Visible );
#endif
if( !ret )
{
@ -55,10 +54,14 @@ namespace Penumbra.UI
ImGui.BeginTabBar( "PenumbraSettings" );
DrawSettingsTab();
DrawResourceMods();
DrawEffectiveFileList();
DrawDeleteModal();
if( !_isImportRunning )
{
DrawResourceMods();
DrawEffectiveFileList();
DrawDeleteModal();
}
ImGui.EndTabBar();