Add option to append file extension in ExtractToDirectory
Some checks are pending
build / build (push) Waiting to run
build / publish (push) Blocked by required conditions

Introduced an 'appendExtension' parameter to ExtractToDirectory, allowing guessed file extensions to be appended to extracted resource filenames. This enhances usability by making extracted files easier to identify by type.
This commit is contained in:
ema
2026-01-20 00:43:00 +08:00
parent 78f2733694
commit 1209d51439
2 changed files with 8 additions and 2 deletions

View File

@@ -33,7 +33,8 @@ public static class PakExtractor
/// </summary>
/// <param name="fileName">The path to the .pak file to extract.</param>
/// <param name="outputDirectory">The directory where extracted resource files will be saved.</param>
public static void ExtractToDirectory(string fileName, string outputDirectory)
/// <param name="appendExtension">If true, append guessed file extension to the filename (e.g., "000000001.png").</param>
public static void ExtractToDirectory(string fileName, string outputDirectory, bool appendExtension = true)
{
using var stream = File.OpenRead(fileName);
using var br = new BinaryReader(stream);
@@ -78,6 +79,11 @@ public static class PakExtractor
read += n;
}
string resourceName = entries[i].ResourceId.ToString("D9");
if (appendExtension)
{
string ext = GuessFileExtension(buffer, length);
resourceName += ext;
}
using var file = File.Create(Path.Combine(outputDirectory, resourceName));
file.Write(buffer, 0, length);
}

View File

@@ -122,7 +122,7 @@ public sealed partial class Plugin
// Chromium resource package file v5 extraction
await Task.Run(() =>
{
PakExtractor.ExtractToDirectory(_path, dialog.FileName);
PakExtractor.ExtractToDirectory(_path, dialog.FileName, appendExtension: true);
});
}
}