mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-28 10:31:04 +00:00
Refactor zip file run logic in MainForm
Removed the _filePath field and refactored zip file handling to pass file paths directly as parameters. Simplified the RunAppPackageFile workflow and eliminated redundant methods for improved clarity and maintainability.
This commit is contained in:
parent
afe7d6213a
commit
b3b00771c5
|
|
@ -20,7 +20,6 @@ namespace WelsonJS.Launcher
|
||||||
private readonly string _dateTimeFormat;
|
private readonly string _dateTimeFormat;
|
||||||
private readonly ICompatibleLogger _logger;
|
private readonly ICompatibleLogger _logger;
|
||||||
|
|
||||||
private string _filePath;
|
|
||||||
private string _workingDirectory;
|
private string _workingDirectory;
|
||||||
private string _instanceId;
|
private string _instanceId;
|
||||||
private string _scriptName;
|
private string _scriptName;
|
||||||
|
|
@ -123,17 +122,6 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
private void btnRunFromZipFile_Click(object sender, EventArgs e)
|
private void btnRunFromZipFile_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(_filePath))
|
|
||||||
{
|
|
||||||
string fileExtension = Path.GetExtension(_filePath);
|
|
||||||
if (fileExtension != null && fileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
DisableUI();
|
|
||||||
Task.Run(() => RunAppPackageFile());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var openFileDialog = new OpenFileDialog())
|
using (var openFileDialog = new OpenFileDialog())
|
||||||
{
|
{
|
||||||
openFileDialog.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
|
openFileDialog.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
|
||||||
|
|
@ -142,15 +130,15 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
_filePath = openFileDialog.FileName;
|
string filePath = openFileDialog.FileName;
|
||||||
|
|
||||||
DisableUI();
|
DisableUI();
|
||||||
Task.Run(() => RunAppPackageFile());
|
Task.Run(() => RunAppPackageFile(filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RunAppPackageFile()
|
private void RunAppPackageFile(string filePath)
|
||||||
{
|
{
|
||||||
_instanceId = Guid.NewGuid().ToString();
|
_instanceId = Guid.NewGuid().ToString();
|
||||||
_workingDirectory = Program.GetWorkingDirectory(_instanceId);
|
_workingDirectory = Program.GetWorkingDirectory(_instanceId);
|
||||||
|
|
@ -165,7 +153,7 @@ namespace WelsonJS.Launcher
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to extract ZIP file
|
// try to extract ZIP file
|
||||||
ZipFile.ExtractToDirectory(_filePath, _workingDirectory);
|
ZipFile.ExtractToDirectory(filePath, _workingDirectory);
|
||||||
|
|
||||||
// record the first deploy time
|
// record the first deploy time
|
||||||
Program.RecordFirstDeployTime(_workingDirectory, _instanceId);
|
Program.RecordFirstDeployTime(_workingDirectory, _instanceId);
|
||||||
|
|
@ -206,7 +194,6 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
return Program._resourceServer.IsRunning();
|
return Program._resourceServer.IsRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsInAdministrator()
|
private bool IsInAdministrator()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -317,11 +304,5 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
Program.OpenWebBrowser(Program.GetAppConfig("RepositoryUrl"));
|
Program.OpenWebBrowser(Program.GetAppConfig("RepositoryUrl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RunFromZipFile(string filePath)
|
|
||||||
{
|
|
||||||
_filePath = filePath;
|
|
||||||
btnRunFromZipFile.PerformClick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user