Fix zstd not loaded

This commit is contained in:
2025-10-14 13:56:57 +08:00
parent a21672e7e9
commit 419941b96e
8 changed files with 57 additions and 5 deletions

View File

@@ -111,6 +111,7 @@
<Compile Include="FC01\ArcBDT.cs" />
<Compile Include="FC01\BdtTables.cs" />
<Compile Include="GScripter\ArcDATA.cs" />
<Compile Include="ImageJXL.cs" />
<Compile Include="Ism\ImagePNG.cs" />
<Compile Include="Kogado\ArcARC.cs" />
<Compile Include="Ice\ImageIBM.cs" />
@@ -1268,10 +1269,16 @@
<EmbeddedResource Include="Strings\arcStrings.ru-RU.resx" />
</ItemGroup>
<ItemGroup>
<Content Include="x64\zstd.dll">
<Content Include="x64\jxl_dec.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\zstd.dll">
<Content Include="x64\zstd-1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\jxl_dec.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\zstd-1.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

23
ArcFormats/ImageJXL.cs Normal file
View File

@@ -0,0 +1,23 @@
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace GameRes.Formats
{
// [Export(typeof(ImageFormat))]
// public class JxlImageFormat : ImageFormat, IDisposable
// {
// public override string Tag { get { return "JXL"; } }
// public override string Description { get { return "JPEG XL image format"; } }
// public override uint Signature { get { return 0; } } // JXL signature starts with 0xFF 0x0A
// public override bool CanWrite { get { return false; } }
// public JxlImageFormat()
// {
// Extensions = new[] { "jxl" };
// }
// }
}

View File

@@ -9,13 +9,13 @@ namespace GameRes.Compression
{
private const int BUFFER_SIZE = 4096;
[DllImport("zstd.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("zstd-1.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr ZSTD_createDStream();
[DllImport("zstd.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("zstd-1.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ZSTD_decompressStream(IntPtr zds, ref ZSTD_outBuffer output, ref ZSTD_inBuffer input);
[DllImport("zstd.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("zstd-1.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ZSTD_freeDStream(IntPtr zds);
[StructLayout(LayoutKind.Sequential)]

BIN
ArcFormats/x64/jxl_dec.dll Normal file
View File

Binary file not shown.

BIN
ArcFormats/x86/jxl_dec.dll Normal file
View File

Binary file not shown.

View File

@@ -30,6 +30,8 @@ using GARbro.GUI.Properties;
using GameRes;
using GameRes.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
namespace GARbro.GUI
{
@@ -46,8 +48,13 @@ namespace GARbro.GUI
/// </summary>
public string InitPath { get; private set; }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
void ApplicationStartup (object sender, StartupEventArgs e)
{
SetupDllDirectory();
string exe_dir = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location);
#if DEBUG
Trace.Listeners.Add (new TextWriterTraceListener (Path.Combine (exe_dir, "trace.log")));
@@ -159,5 +166,20 @@ namespace GARbro.GUI
}
return false;
}
private static void SetupDllDirectory() {
string arch = Environment.Is64BitProcess ? "x64" : "x86";
string appPath = AppDomain.CurrentDomain.BaseDirectory;
string dllPath = Path.Combine(appPath, arch);
if (Directory.Exists(dllPath)) {
Console.WriteLine($"Setting DLL search directory to: {dllPath}");
if (!SetDllDirectory(dllPath)) {
Console.WriteLine("Warning: Failed to set DLL directory.");
}
} else {
Console.WriteLine($"Warning: Directory not found: {dllPath}");
}
}
}
}