mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 18:11:20 +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
|
// 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,7 +5,6 @@ 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
|
||||||
{
|
{
|
||||||
|
|
@ -17,14 +16,12 @@ namespace WelsonJS.Launcher
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
public Func<string, string, string> ExtractCommand { get; set; }
|
public Func<string, string, string> ExtractCommand { get; set; }
|
||||||
public bool UseCmd { get; set; } = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<Extractor> AvailableExtractors;
|
private readonly List<Extractor> AvailableExtractors;
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
@ -63,19 +60,6 @@ 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)",
|
|
||||||
FileName = "jar.exe",
|
|
||||||
ExtractCommand = (src, dest) => $"xf \"{src}\"",
|
|
||||||
UseCmd = true
|
|
||||||
},
|
|
||||||
new Extractor
|
|
||||||
{
|
{
|
||||||
Name = "tar (Windows)", // Windows 10 build 17063 or later
|
Name = "tar (Windows)", // Windows 10 build 17063 or later
|
||||||
FileName = "tar.exe",
|
FileName = "tar.exe",
|
||||||
|
|
@ -107,14 +91,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, filePath, workingDirectory, true))
|
if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory)))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExtractUsingPowerShell(filePath, workingDirectory, true))
|
if (ExtractUsingPowerShell(filePath, workingDirectory))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (ExtractUsingShell(filePath, workingDirectory, true))
|
if (ExtractUsingShell(filePath, workingDirectory))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -183,66 +167,42 @@ namespace WelsonJS.Launcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch {
|
||||||
|
// ignore an exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool RunProcess(string executableFilePath, string arguments)
|
||||||
{
|
{
|
||||||
Trace.TraceInformation($"Ignored file or directory: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool RunProcess(string execFilePath, string arguments, string workingDirectory, bool useCmd = false, bool showConsole = false)
|
|
||||||
{
|
|
||||||
int exitCode = -1;
|
|
||||||
|
|
||||||
string fileName = useCmd ? "cmd.exe" : execFilePath;
|
|
||||||
string adjustedArguments = useCmd ? $"/c \"{execFilePath}\" {arguments}" : arguments;
|
|
||||||
|
|
||||||
var psi = new ProcessStartInfo
|
var psi = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = executableFilePath,
|
||||||
Arguments = adjustedArguments,
|
Arguments = arguments,
|
||||||
WorkingDirectory = workingDirectory,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardOutput = !showConsole,
|
RedirectStandardError = true,
|
||||||
RedirectStandardError = !showConsole,
|
UseShellExecute = false,
|
||||||
UseShellExecute = showConsole,
|
CreateNoWindow = true
|
||||||
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();
|
||||||
exitCode = process.ExitCode;
|
return process.ExitCode == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exitCode != 0)
|
private bool ExtractUsingPowerShell(string filePath, string workingDirectory)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
var escapedSrc = filePath.Replace("'", "''");
|
var escapedSrc = filePath.Replace("'", "''");
|
||||||
var escapedDest = workingDirectory.Replace("'", "''");
|
var escapedDest = workingDirectory.Replace("'", "''");
|
||||||
var script = $"Expand-Archive -LiteralPath '{escapedSrc}' -DestinationPath '{escapedDest}' -Force";
|
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");
|
var shellAppType = Type.GetTypeFromProgID("Shell.Application");
|
||||||
if (shellAppType == null)
|
if (shellAppType == null)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user