11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
34using System . IO ;
45using System . Threading . Tasks ;
56using 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