Skip to content

Commit 7758894

Browse files
committed
Add option to append file extension in ExtractToDirectory
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.
1 parent 78f2733 commit 7758894

File tree

1 file changed

+7
-1
lines changed
  • QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ChromiumResourcePackage

1 file changed

+7
-1
lines changed

QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/ChromiumResourcePackage/PakExtractor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static class PakExtractor
3333
/// </summary>
3434
/// <param name="fileName">The path to the .pak file to extract.</param>
3535
/// <param name="outputDirectory">The directory where extracted resource files will be saved.</param>
36-
public static void ExtractToDirectory(string fileName, string outputDirectory)
36+
/// <param name="appendExtension">If true, append guessed file extension to the filename (e.g., "000000001.png").</param>
37+
public static void ExtractToDirectory(string fileName, string outputDirectory, bool appendExtension = true)
3738
{
3839
using var stream = File.OpenRead(fileName);
3940
using var br = new BinaryReader(stream);
@@ -78,6 +79,11 @@ public static void ExtractToDirectory(string fileName, string outputDirectory)
7879
read += n;
7980
}
8081
string resourceName = entries[i].ResourceId.ToString("D9");
82+
if (appendExtension)
83+
{
84+
string ext = GuessFileExtension(buffer, length);
85+
resourceName += ext;
86+
}
8187
using var file = File.Create(Path.Combine(outputDirectory, resourceName));
8288
file.Write(buffer, 0, length);
8389
}

0 commit comments

Comments
 (0)