mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 10:00:57 +00:00
Revert "Merge pull request #257 from gnh1201/dev"
This reverts commit308fccf165, reversing changes made to26bc061819.
This commit is contained in:
parent
8eb450c9d9
commit
f2dc0a3904
|
|
@ -144,10 +144,6 @@ namespace WelsonJS.Launcher
|
|||
// Run the application
|
||||
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Failed to extract the ZIP file.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WelsonJS.Launcher
|
||||
{
|
||||
|
|
@ -17,14 +16,12 @@ namespace WelsonJS.Launcher
|
|||
public string FileName { get; set; }
|
||||
public string Path { get; set; }
|
||||
public Func<string, string, string> ExtractCommand { get; set; }
|
||||
public bool UseCmd { get; set; } = false;
|
||||
}
|
||||
|
||||
private readonly List<Extractor> AvailableExtractors;
|
||||
|
||||
public ZipExtractor()
|
||||
{
|
||||
// Searches the computer for any known third-party ZIP utilities.
|
||||
AvailableExtractors = new List<Extractor>{
|
||||
new Extractor
|
||||
{
|
||||
|
|
@ -63,19 +60,6 @@ namespace WelsonJS.Launcher
|
|||
ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y"
|
||||
},
|
||||
new Extractor
|
||||
{
|
||||
Name = "IZArc",
|
||||
FileName = "izarce.exe",
|
||||
ExtractCommand = (src, dest) => $"-d -p\"{dest}\" \"{src}\""
|
||||
},
|
||||
new Extractor
|
||||
{
|
||||
Name = "jar (Java SDK)",
|
||||
FileName = "jar.exe",
|
||||
ExtractCommand = (src, dest) => $"xf \"{src}\"",
|
||||
UseCmd = true
|
||||
},
|
||||
new Extractor
|
||||
{
|
||||
Name = "tar (Windows)", // Windows 10 build 17063 or later
|
||||
FileName = "tar.exe",
|
||||
|
|
@ -107,14 +91,14 @@ namespace WelsonJS.Launcher
|
|||
|
||||
foreach (var extractor in AvailableExtractors.Where(e => e.Path != null))
|
||||
{
|
||||
if (RunProcess(extractor, filePath, workingDirectory, true))
|
||||
if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory)))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ExtractUsingPowerShell(filePath, workingDirectory, true))
|
||||
if (ExtractUsingPowerShell(filePath, workingDirectory))
|
||||
return true;
|
||||
|
||||
if (ExtractUsingShell(filePath, workingDirectory, true))
|
||||
if (ExtractUsingShell(filePath, workingDirectory))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
@ -183,66 +167,42 @@ namespace WelsonJS.Launcher
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceInformation($"Ignored file or directory: {ex.Message}");
|
||||
catch {
|
||||
// ignore an exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool RunProcess(string execFilePath, string arguments, string workingDirectory, bool useCmd = false, bool showConsole = false)
|
||||
private bool RunProcess(string executableFilePath, string arguments)
|
||||
{
|
||||
int exitCode = -1;
|
||||
|
||||
string fileName = useCmd ? "cmd.exe" : execFilePath;
|
||||
string adjustedArguments = useCmd ? $"/c \"{execFilePath}\" {arguments}" : arguments;
|
||||
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = adjustedArguments,
|
||||
WorkingDirectory = workingDirectory,
|
||||
RedirectStandardOutput = !showConsole,
|
||||
RedirectStandardError = !showConsole,
|
||||
UseShellExecute = showConsole,
|
||||
CreateNoWindow = !showConsole
|
||||
FileName = executableFilePath,
|
||||
Arguments = arguments,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (var process = new Process { StartInfo = psi, EnableRaisingEvents = true })
|
||||
{
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
exitCode = process.ExitCode;
|
||||
return process.ExitCode == 0;
|
||||
}
|
||||
|
||||
if (exitCode != 0)
|
||||
Trace.TraceWarning($"{fileName} exit with code {exitCode}");
|
||||
else
|
||||
Trace.TraceInformation($"{fileName} finished successfully");
|
||||
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
private bool RunProcess(Extractor extractor, string filePath, string workingDirectory, bool showConsole = false)
|
||||
{
|
||||
return RunProcess(extractor.Path,
|
||||
extractor.ExtractCommand(filePath, workingDirectory),
|
||||
workingDirectory,
|
||||
extractor.UseCmd,
|
||||
showConsole
|
||||
);
|
||||
}
|
||||
|
||||
private bool ExtractUsingPowerShell(string filePath, string workingDirectory, bool showConsole = false)
|
||||
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}\"", workingDirectory);
|
||||
return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\"");
|
||||
}
|
||||
|
||||
private bool ExtractUsingShell(string filePath, string workingDirectory, bool showConsole = false)
|
||||
private bool ExtractUsingShell(string filePath, string workingDirectory)
|
||||
{
|
||||
var shellAppType = Type.GetTypeFromProgID("Shell.Application");
|
||||
if (shellAppType == null)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user