From 1c678ba7ae8abe166e0956eecd14db0ddd6eef61 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 17 May 2025 03:56:45 +0900 Subject: [PATCH] Update ZipExtractor.cs --- .../WelsonJS.Launcher/ZipExtractor.cs | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs index 2a838bb..01bab9a 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs @@ -42,12 +42,6 @@ namespace WelsonJS.Launcher ExtractCommand = (src, dest) => $"-ext2simple \"{src}\" \"{dest}\"" }, new Extractor - { - Name = "tar (Windows)", - FileName = "tar.exe", - ExtractCommand = (src, dest) => $"-xf \"{src}\" -C \"{dest}\"" - }, - new Extractor { Name = "WinZip", FileName = "wzunzip.exe", @@ -64,6 +58,18 @@ namespace WelsonJS.Launcher Name = "Bandizip", FileName = "Bandizip.exe", ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y" + }, + new Extractor + { + Name = "tar (Windows)", // Windows 10 build 17063 or later + FileName = "tar.exe", + ExtractCommand = (src, dest) => $"-xf \"{src}\" -C \"{dest}\"" + }, + new Extractor + { + Name = "unzip", // Info-ZIP, Cygwin + FileName = "unzip.exe", + ExtractCommand = (src, dest) => $"\"{src}\" -d \"{dest}\" -o" } }; @@ -86,12 +92,16 @@ namespace WelsonJS.Launcher foreach (var extractor in AvailableExtractors.Where(e => e.Path != null)) { if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory))) - { return true; - } } - return ExtractUsingShell(filePath, workingDirectory); + if (ExtractUsingPowerShell(filePath, workingDirectory)) + return true; + + if (ExtractUsingShell(filePath, workingDirectory)) + return true; + + return false; } private bool IsValidFile(string filePath) @@ -157,7 +167,9 @@ namespace WelsonJS.Launcher } } } - catch { } + catch { + // ignore an exception + } } } @@ -181,6 +193,15 @@ namespace WelsonJS.Launcher } } + private bool ExtractUsingPowerShell(string filePath, string workingDirectory) + { + var escapedSrc = filePath.Replace("'", "''"); + var escapedDest = workingDirectory.Replace("'", "''"); + var script = $"Expand-Archive -LiteralPath '{escapedSrc}' -DestinationPath '{escapedDest}' -Force"; + + return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\""); + } + private bool ExtractUsingShell(string filePath, string workingDirectory) { var shellAppType = Type.GetTypeFromProgID("Shell.Application");