mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 18:11:20 +00:00
parent
dcdf79dc3a
commit
d214a8d749
|
|
@ -12,7 +12,7 @@ namespace WelsonJS.Launcher
|
|||
{
|
||||
private string workingDirectory;
|
||||
private string instanceId;
|
||||
private string entryFileName;
|
||||
private readonly string entryFileName;
|
||||
private string scriptName;
|
||||
|
||||
public MainForm()
|
||||
|
|
@ -23,7 +23,7 @@ namespace WelsonJS.Launcher
|
|||
|
||||
if (IsInAdministrator())
|
||||
{
|
||||
Text = Text + " (Administrator)";
|
||||
Text += " (Administrator)";
|
||||
}
|
||||
|
||||
notifyIcon1.DoubleClick += OnShow;
|
||||
|
|
@ -109,8 +109,10 @@ namespace WelsonJS.Launcher
|
|||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string filePath = openFileDialog.FileName;
|
||||
ExtractAndRun(filePath);
|
||||
Task.Run(() => ExtractAndRun(filePath));
|
||||
}
|
||||
|
||||
DisableUI();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,43 +122,33 @@ namespace WelsonJS.Launcher
|
|||
workingDirectory = Program.GetWorkingDirectory(instanceId);
|
||||
scriptName = txtUseSpecificScript.Text;
|
||||
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
// try to validate GUID
|
||||
if (Directory.Exists(workingDirectory))
|
||||
{
|
||||
// If exists, delete all
|
||||
if (Directory.Exists(workingDirectory))
|
||||
{
|
||||
Directory.Delete(workingDirectory, true);
|
||||
}
|
||||
|
||||
// try to extact ZIP file
|
||||
ZipFile.ExtractToDirectory(filePath, workingDirectory);
|
||||
|
||||
// record the first deploy time
|
||||
RecordFirstDeployTime(workingDirectory);
|
||||
|
||||
// follow the sub-directory
|
||||
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||
|
||||
// Run the appliction
|
||||
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SafeInvoke(() =>
|
||||
{
|
||||
MessageBox.Show("Error: " + ex.Message);
|
||||
});
|
||||
throw new InvalidOperationException("GUID validation failed. Directory already exists.");
|
||||
}
|
||||
|
||||
// Enable UI
|
||||
SafeInvoke(() => {
|
||||
EnableUI();
|
||||
});
|
||||
});
|
||||
// try to extract ZIP file
|
||||
ZipFile.ExtractToDirectory(filePath, workingDirectory);
|
||||
|
||||
DisableUI();
|
||||
// record the first deploy time
|
||||
RecordFirstDeployTime(workingDirectory);
|
||||
|
||||
// follow the sub-directory
|
||||
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||
|
||||
// Run the appliction
|
||||
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SafeInvoke(() => MessageBox.Show($"Extraction failed: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error));
|
||||
}
|
||||
|
||||
// Enable UI
|
||||
SafeInvoke(() => EnableUI());
|
||||
}
|
||||
|
||||
private void RecordFirstDeployTime(string directory)
|
||||
|
|
@ -181,8 +173,9 @@ namespace WelsonJS.Launcher
|
|||
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||
return wp.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceInformation($"The current user is not an administrator, or the check failed: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -226,7 +219,7 @@ namespace WelsonJS.Launcher
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Failed to run as administrator: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Failed to run as Administrator: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user