mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-28 12:37:02 +00:00
Update ZipExtractor.cs
This commit is contained in:
parent
753ef4c6e5
commit
1c678ba7ae
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user