mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-29 19:03:42 +00:00
One more fix #254
This commit is contained in:
parent
ca9caef94e
commit
f60754d9d4
|
|
@ -144,6 +144,10 @@ namespace WelsonJS.Launcher
|
||||||
// Run the application
|
// Run the application
|
||||||
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked);
|
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Failed to extract the ZIP file.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace WelsonJS.Launcher
|
namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +24,7 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
public ZipExtractor()
|
public ZipExtractor()
|
||||||
{
|
{
|
||||||
|
// Searches the computer for any known third-party ZIP utilities.
|
||||||
AvailableExtractors = new List<Extractor>{
|
AvailableExtractors = new List<Extractor>{
|
||||||
new Extractor
|
new Extractor
|
||||||
{
|
{
|
||||||
|
|
@ -61,6 +63,12 @@ namespace WelsonJS.Launcher
|
||||||
ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y"
|
ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y"
|
||||||
},
|
},
|
||||||
new Extractor
|
new Extractor
|
||||||
|
{
|
||||||
|
Name = "IZArc",
|
||||||
|
FileName = "izarce.exe",
|
||||||
|
ExtractCommand = (src, dest) => $"-d -p\"{dest}\" \"{src}\""
|
||||||
|
},
|
||||||
|
new Extractor
|
||||||
{
|
{
|
||||||
Name = "jar (Java SDK)",
|
Name = "jar (Java SDK)",
|
||||||
FileName = "jar.exe",
|
FileName = "jar.exe",
|
||||||
|
|
@ -99,14 +107,14 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
foreach (var extractor in AvailableExtractors.Where(e => e.Path != null))
|
foreach (var extractor in AvailableExtractors.Where(e => e.Path != null))
|
||||||
{
|
{
|
||||||
if (RunProcess(extractor.Path, extractor, workingDirectory))
|
if (RunProcess(extractor, filePath, workingDirectory, true))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExtractUsingPowerShell(filePath, workingDirectory))
|
if (ExtractUsingPowerShell(filePath, workingDirectory, true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (ExtractUsingShell(filePath, workingDirectory))
|
if (ExtractUsingShell(filePath, workingDirectory, true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -182,45 +190,60 @@ namespace WelsonJS.Launcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RunProcess(string executableFilePath, string arguments, string workingDirectory, bool useCmd = false)
|
private bool RunProcess(string execFilePath, string arguments, string workingDirectory, bool useCmd = false, bool showConsole = false)
|
||||||
{
|
{
|
||||||
var fileName = executableFilePath;
|
int exitCode = -1;
|
||||||
var adjustedArguments = arguments;
|
|
||||||
|
string fileName = execFilePath;
|
||||||
|
string adjustedArguments = arguments;
|
||||||
|
|
||||||
if (useCmd && !String.IsNullOrEmpty(workingDirectory))
|
if (useCmd && !String.IsNullOrEmpty(workingDirectory))
|
||||||
{
|
{
|
||||||
fileName = "cmd.exe";
|
fileName = "cmd.exe";
|
||||||
adjustedArguments = $"/c cd /d \"{workingDirectory}\" && \"{executableFilePath}\" {arguments}";
|
adjustedArguments = $"/c cd /d \"{workingDirectory}\" && \"{execFilePath}\" {arguments}";
|
||||||
}
|
}
|
||||||
|
|
||||||
var psi = new ProcessStartInfo
|
var psi = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = fileName,
|
||||||
Arguments = adjustedArguments,
|
Arguments = adjustedArguments,
|
||||||
RedirectStandardOutput = true,
|
WorkingDirectory = workingDirectory,
|
||||||
RedirectStandardError = true,
|
RedirectStandardOutput = !showConsole,
|
||||||
UseShellExecute = false,
|
RedirectStandardError = !showConsole,
|
||||||
CreateNoWindow = true
|
UseShellExecute = showConsole,
|
||||||
|
CreateNoWindow = !showConsole
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var process = new Process { StartInfo = psi, EnableRaisingEvents = true })
|
using (var process = new Process { StartInfo = psi, EnableRaisingEvents = true })
|
||||||
{
|
{
|
||||||
process.Start();
|
process.Start();
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
return process.ExitCode == 0;
|
exitCode = process.ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exitCode != 0)
|
||||||
|
{
|
||||||
|
Trace.TraceWarning($"{fileName} exit with code {exitCode}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Trace.TraceInformation($"{fileName} finished successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
return exitCode == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RunProcess(string executableFilePath, Extractor extractor, string workingDirectory)
|
private bool RunProcess(Extractor extractor, string filePath, string workingDirectory, bool showConsole = false)
|
||||||
{
|
{
|
||||||
return RunProcess(executableFilePath,
|
return RunProcess(extractor.Path,
|
||||||
extractor.ExtractCommand(extractor.FileName, workingDirectory),
|
extractor.ExtractCommand(filePath, workingDirectory),
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
extractor.UseCmd
|
extractor.UseCmd,
|
||||||
|
showConsole
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ExtractUsingPowerShell(string filePath, string workingDirectory)
|
private bool ExtractUsingPowerShell(string filePath, string workingDirectory, bool showConsole = false)
|
||||||
{
|
{
|
||||||
var escapedSrc = filePath.Replace("'", "''");
|
var escapedSrc = filePath.Replace("'", "''");
|
||||||
var escapedDest = workingDirectory.Replace("'", "''");
|
var escapedDest = workingDirectory.Replace("'", "''");
|
||||||
|
|
@ -229,7 +252,7 @@ namespace WelsonJS.Launcher
|
||||||
return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\"", workingDirectory);
|
return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\"", workingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ExtractUsingShell(string filePath, string workingDirectory)
|
private bool ExtractUsingShell(string filePath, string workingDirectory, bool showConsole = false)
|
||||||
{
|
{
|
||||||
var shellAppType = Type.GetTypeFromProgID("Shell.Application");
|
var shellAppType = Type.GetTypeFromProgID("Shell.Application");
|
||||||
if (shellAppType == null)
|
if (shellAppType == null)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user