Fix issues and PR #254 #260

This commit is contained in:
Namhyeon Go 2025-05-24 12:16:11 +09:00
parent dcdf79dc3a
commit d214a8d749

View File

@ -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