mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 17:05:14 +00:00
allow search an instances in the temporary folder
This commit is contained in:
parent
7d2f76e2dd
commit
51110e54b7
|
@ -7,43 +7,55 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
public partial class InstancesForm : Form
|
public partial class InstancesForm : Form
|
||||||
{
|
{
|
||||||
private string instancesRoot;
|
|
||||||
private string entryFileName;
|
private string entryFileName;
|
||||||
private string scriptName;
|
private string scriptName;
|
||||||
|
private const string timestampFormat = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
public InstancesForm()
|
public InstancesForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
instancesRoot = Program.GetAppDataPath();
|
|
||||||
entryFileName = "bootstrap.bat";
|
entryFileName = "bootstrap.bat";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InstancesForm_Load(object sender, EventArgs e)
|
private void InstancesForm_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadInstances();
|
listView1.Items.Clear();
|
||||||
|
LoadInstances(Program.GetAppDataPath());
|
||||||
|
LoadInstances(Path.GetTempPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadInstances()
|
private void LoadInstances(string instancesRoot)
|
||||||
{
|
{
|
||||||
listView1.Items.Clear();
|
|
||||||
|
|
||||||
if (!Directory.Exists(instancesRoot))
|
if (!Directory.Exists(instancesRoot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string dir in Directory.GetDirectories(instancesRoot))
|
foreach (string dir in Directory.GetDirectories(instancesRoot))
|
||||||
{
|
{
|
||||||
string timestampFile = Path.Combine(dir, ".welsonjs_first_deploy_time");
|
string timestampFile = Path.Combine(dir, ".welsonjs_first_deploy_time");
|
||||||
|
string entryScriptFile = Path.Combine(dir, "app.js");
|
||||||
|
string firstDeployTime = null;
|
||||||
|
|
||||||
if (File.Exists(timestampFile))
|
if (File.Exists(timestampFile)
|
||||||
|
&& DateTime.TryParse(File.ReadAllText(timestampFile).Trim(), out DateTime parsedTimestamp))
|
||||||
|
{
|
||||||
|
firstDeployTime = parsedTimestamp.ToString(timestampFormat);
|
||||||
|
}
|
||||||
|
else if (File.Exists(entryScriptFile))
|
||||||
|
{
|
||||||
|
firstDeployTime = File.GetCreationTime(entryScriptFile).ToString(timestampFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstDeployTime != null)
|
||||||
|
{
|
||||||
|
listView1.Items.Add(new ListViewItem(new[]
|
||||||
{
|
{
|
||||||
string firstDeployTime = File.ReadAllText(timestampFile).Trim();
|
|
||||||
ListViewItem item = new ListViewItem(new[] {
|
|
||||||
Path.GetFileName(dir),
|
Path.GetFileName(dir),
|
||||||
firstDeployTime
|
firstDeployTime
|
||||||
|
})
|
||||||
|
{
|
||||||
|
Tag = dir
|
||||||
});
|
});
|
||||||
item.Tag = dir;
|
|
||||||
listView1.Items.Add(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,11 +66,8 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
scriptName = textBox1.Text;
|
scriptName = textBox1.Text;
|
||||||
|
|
||||||
string selectedInstance = listView1.SelectedItems[0].Text;
|
string instanceId = listView1.SelectedItems[0].Text;
|
||||||
string workingDirectory = Path.Combine(instancesRoot, selectedInstance);
|
string workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||||
|
|
||||||
// If it is created the sub-directory
|
|
||||||
workingDirectory = Program.GetFinalDirectory(workingDirectory);
|
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
@ -83,13 +92,21 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
if (listView1.SelectedItems.Count > 0)
|
if (listView1.SelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
string selectedInstance = listView1.SelectedItems[0].Text;
|
string instanceId = listView1.SelectedItems[0].Text;
|
||||||
string workingDirectory = Path.Combine(instancesRoot, selectedInstance);
|
string workingDirectory = Program.GetWorkingDirectory(instanceId, false);
|
||||||
|
|
||||||
|
if (!Directory.Exists(workingDirectory))
|
||||||
|
{
|
||||||
|
workingDirectory = Path.Combine(Path.GetTempPath(), instanceId);
|
||||||
|
}
|
||||||
|
|
||||||
if (Directory.Exists(workingDirectory))
|
if (Directory.Exists(workingDirectory))
|
||||||
{
|
{
|
||||||
Directory.Delete(workingDirectory, true);
|
Directory.Delete(workingDirectory, true);
|
||||||
LoadInstances();
|
|
||||||
|
listView1.Items.Clear();
|
||||||
|
LoadInstances(Program.GetAppDataPath());
|
||||||
|
LoadInstances(Path.GetTempPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -102,8 +119,8 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
if (listView1.SelectedItems.Count > 0)
|
if (listView1.SelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
string selectedInstance = listView1.SelectedItems[0].Text;
|
string instanceId = listView1.SelectedItems[0].Text;
|
||||||
string workingDirectory = Path.Combine(instancesRoot, selectedInstance);
|
string workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||||
|
|
||||||
if (Directory.Exists(workingDirectory))
|
if (Directory.Exists(workingDirectory))
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace WelsonJS.Launcher
|
||||||
private void ExtractAndRun(string filePath)
|
private void ExtractAndRun(string filePath)
|
||||||
{
|
{
|
||||||
instanceId = Guid.NewGuid().ToString();
|
instanceId = Guid.NewGuid().ToString();
|
||||||
workingDirectory = Path.Combine(Program.GetAppDataPath(), instanceId);
|
workingDirectory = Program.GetWorkingDirectory(instanceId);
|
||||||
scriptName = textBox1.Text;
|
scriptName = textBox1.Text;
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
|
@ -88,8 +88,8 @@ namespace WelsonJS.Launcher
|
||||||
// record the first deploy time
|
// record the first deploy time
|
||||||
RecordFirstDeployTime(workingDirectory);
|
RecordFirstDeployTime(workingDirectory);
|
||||||
|
|
||||||
// If it is created the sub-directory
|
// follow the sub-directory
|
||||||
workingDirectory = Program.GetFinalDirectory(workingDirectory);
|
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||||
|
|
||||||
// Run the appliction
|
// Run the appliction
|
||||||
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, checkBox1.Checked, checkBox2.Checked);
|
Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, checkBox1.Checked, checkBox2.Checked);
|
||||||
|
|
|
@ -105,5 +105,22 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetWorkingDirectory(string instanceId, bool followSubDirectory = false)
|
||||||
|
{
|
||||||
|
string workingDirectory = Path.Combine(GetAppDataPath(), instanceId);
|
||||||
|
|
||||||
|
if (followSubDirectory)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(workingDirectory))
|
||||||
|
{
|
||||||
|
workingDirectory = Path.Combine(Path.GetTempPath(), instanceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
workingDirectory = GetFinalDirectory(workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return workingDirectory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user