Update MainForm.cs

This commit is contained in:
Namhyeon Go 2024-11-04 01:22:33 +09:00
parent 3989eeba45
commit 020f99c5b2

View File

@ -11,13 +11,15 @@ namespace WelsonJS.Launcher
public partial class MainForm : Form public partial class MainForm : Form
{ {
private string workingDirectory; private string workingDirectory;
private string appName; private string instanceName;
private readonly string entrypointFileName = "bootstrap.bat"; private string entryFileName;
private string scriptName; private string scriptName;
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
entryFileName = "bootstrap.bat";
} }
private void EnableUI() private void EnableUI()
@ -43,7 +45,7 @@ namespace WelsonJS.Launcher
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
ShowMessageBox("Comming soon...!"); MessageBox.Show("Comming soon...!");
} }
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
@ -54,7 +56,7 @@ namespace WelsonJS.Launcher
string fileExtension = Path.GetExtension(filePath); string fileExtension = Path.GetExtension(filePath);
if (fileExtension != ".zip") if (fileExtension != ".zip")
{ {
ShowMessageBox("It doesn't seems to a ZIP file."); MessageBox.Show("It doesn't seems to a ZIP file.");
} }
else else
{ {
@ -65,8 +67,8 @@ namespace WelsonJS.Launcher
private void ExtractAndRun(string filePath) private void ExtractAndRun(string filePath)
{ {
appName = Path.GetFileNameWithoutExtension(filePath); instanceName = Guid.NewGuid().ToString();
workingDirectory = Path.Combine(Path.GetTempPath(), appName); workingDirectory = Path.Combine(Path.GetTempPath(), instanceName);
scriptName = textBox1.Text; scriptName = textBox1.Text;
Task.Run(() => Task.Run(() =>
@ -90,7 +92,7 @@ namespace WelsonJS.Launcher
} }
catch (Exception ex) catch (Exception ex)
{ {
ShowMessageBox(ex.Message); MessageBox.Show(ex.Message);
} }
// Enable UI // Enable UI
@ -109,9 +111,9 @@ namespace WelsonJS.Launcher
if (!isConsoleApplication) if (!isConsoleApplication)
{ {
if (!File.Exists(Path.Combine(workingDirectory, entrypointFileName))) if (!File.Exists(Path.Combine(workingDirectory, entryFileName)))
{ {
throw new Exception("Not Found: " + entrypointFileName); throw new Exception("Not Found: " + entryFileName);
} }
} }
else else
@ -149,7 +151,7 @@ namespace WelsonJS.Launcher
} }
else if (!isConsoleApplication) else if (!isConsoleApplication)
{ {
process.StandardInput.WriteLine(entrypointFileName); process.StandardInput.WriteLine(entryFileName);
process.StandardInput.WriteLine(); process.StandardInput.WriteLine();
process.StandardInput.Flush(); process.StandardInput.Flush();
process.StandardOutput.ReadLine(); process.StandardOutput.ReadLine();
@ -169,23 +171,18 @@ namespace WelsonJS.Launcher
{ {
string filePath = null; string filePath = null;
using (OpenFileDialog openFileDialog = new OpenFileDialog()) using (OpenFileDialog fileDialog = new OpenFileDialog())
{ {
if (openFileDialog.ShowDialog() == DialogResult.OK) if (fileDialog.ShowDialog() == DialogResult.OK)
{ {
//Get the path of specified file // Get the path of specified file
filePath = openFileDialog.FileName; filePath = fileDialog.FileName;
} }
} }
return filePath; return filePath;
} }
private void ShowMessageBox(string message)
{
MessageBox.Show(message);
}
private string GetFinalDirectory(string path) private string GetFinalDirectory(string path)
{ {
string[] directories = Directory.GetDirectories(path); string[] directories = Directory.GetDirectories(path);
@ -206,7 +203,7 @@ namespace WelsonJS.Launcher
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
System.Diagnostics.Process.Start("https://github.com/gnh1201/welsonjs"); Process.Start("https://github.com/gnh1201/welsonjs");
} }
private void userdefinedVariablesToolStripMenuItem_Click(object sender, EventArgs e) private void userdefinedVariablesToolStripMenuItem_Click(object sender, EventArgs e)