Skip to content

Commit c02ec6d

Browse files
committed
[FlashpointManager] Run executable from temp folder to allow deletion, add comments
1 parent 6f02d06 commit c02ec6d

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

FlashpointManager/src/Forms/Main.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private async void RemoveButton_Click(object sender, EventArgs e)
181181
await Task.Run(() => {
182182
foreach (string file in Directory.GetFiles(FPM.SourcePath, "*", SearchOption.AllDirectories))
183183
{
184-
try { File.Delete(file); } catch { }
184+
try { FPM.DeleteFileAndDirectories(file); } catch { }
185185
}
186186

187187
var shortcutPaths = new string[]
@@ -201,13 +201,6 @@ await Task.Run(() => {
201201
"Uninstallation Complete", MessageBoxButtons.OK, MessageBoxIcon.Information
202202
);
203203

204-
Process.Start(new ProcessStartInfo()
205-
{
206-
FileName = "cmd.exe",
207-
Arguments = $"/k timeout /nobreak /t 3 >nul & rmdir /Q /S \"{FPM.SourcePath}\"",
208-
WindowStyle = ProcessWindowStyle.Hidden
209-
});
210-
211204
Close();
212205
}
213206
}

FlashpointManager/src/Program.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Threading.Tasks;
56
using System.Windows.Forms;
@@ -18,20 +19,51 @@ internal static class Program
1819
[STAThread]
1920
static void Main(string[] args)
2021
{
22+
// Run app from temp folder if it isn't already
23+
// This allows the executable to be deleted when updating the component or uninstalling Flashpoint
24+
if (!Debugger.IsAttached)
25+
{
26+
string realPath = AppDomain.CurrentDomain.BaseDirectory;
27+
string realFile = AppDomain.CurrentDomain.FriendlyName;
28+
string tempPath = Path.GetTempPath();
29+
string tempFile = $"69McIKvK_{realFile}";
30+
31+
if (realPath != tempPath && realFile != tempFile)
32+
{
33+
File.Copy(realPath + realFile, tempPath + tempFile, true);
34+
Process.Start(new ProcessStartInfo
35+
{
36+
FileName = tempPath + tempFile,
37+
Arguments = string.Join(" ", args),
38+
WorkingDirectory = realPath
39+
});
40+
Environment.Exit(0);
41+
}
42+
else if (tempPath.TrimEnd('\\') == Directory.GetCurrentDirectory())
43+
{
44+
Environment.Exit(0);
45+
}
46+
}
47+
2148
Application.EnableVisualStyles();
2249
Application.SetCompatibleTextRenderingDefault(false);
2350

24-
var config = new List<string>() { Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..")), FPM.ListURL };
51+
// Load config, or create if it doesn't exist
52+
53+
var config = new List<string>() {
54+
Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..")),
55+
FPM.ListURL
56+
};
2557

2658
try
2759
{
28-
var configReader = File.ReadAllLines("fpm.cfg");
60+
var configReader = File.ReadAllLines(FPM.ConfigFile);
2961
config[0] = configReader[0];
3062
config[1] = configReader[1];
3163
}
3264
catch
3365
{
34-
using (var configWriter = File.CreateText("fpm.cfg"))
66+
using (var configWriter = File.CreateText(FPM.ConfigFile))
3567
{
3668
configWriter.WriteLine(config[0]);
3769
configWriter.WriteLine(config[1]);
@@ -41,6 +73,8 @@ static void Main(string[] args)
4173
FPM.SourcePath = config[0];
4274
FPM.ListURL = config[1];
4375

76+
// Download and parse component list
77+
4478
Stream listStream = null;
4579
Task.Run(async () => { listStream = await new DownloadService().DownloadFileTaskAsync(FPM.ListURL); }).Wait();
4680

@@ -59,10 +93,13 @@ static void Main(string[] args)
5993
FPM.XmlTree = new XmlDocument();
6094
FPM.XmlTree.Load(listStream);
6195

96+
// Verify that the configured Flashpoint path is valid
6297
FPM.VerifySourcePath();
6398

99+
// Open update tab on startup if /update argument is passed
64100
if (args.Length > 0 && args[0].ToLower() == "/update") FPM.OpenUpdateTab = true;
65101

102+
// Display the application window
66103
Application.Run(new Main());
67104
}
68105
}

0 commit comments

Comments
 (0)