1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using System . IO ;
4
5
using System . Threading . Tasks ;
5
6
using System . Windows . Forms ;
@@ -18,20 +19,51 @@ internal static class Program
18
19
[ STAThread ]
19
20
static void Main ( string [ ] args )
20
21
{
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
+
21
48
Application . EnableVisualStyles ( ) ;
22
49
Application . SetCompatibleTextRenderingDefault ( false ) ;
23
50
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
+ } ;
25
57
26
58
try
27
59
{
28
- var configReader = File . ReadAllLines ( "fpm.cfg" ) ;
60
+ var configReader = File . ReadAllLines ( FPM . ConfigFile ) ;
29
61
config [ 0 ] = configReader [ 0 ] ;
30
62
config [ 1 ] = configReader [ 1 ] ;
31
63
}
32
64
catch
33
65
{
34
- using ( var configWriter = File . CreateText ( "fpm.cfg" ) )
66
+ using ( var configWriter = File . CreateText ( FPM . ConfigFile ) )
35
67
{
36
68
configWriter . WriteLine ( config [ 0 ] ) ;
37
69
configWriter . WriteLine ( config [ 1 ] ) ;
@@ -41,6 +73,8 @@ static void Main(string[] args)
41
73
FPM . SourcePath = config [ 0 ] ;
42
74
FPM . ListURL = config [ 1 ] ;
43
75
76
+ // Download and parse component list
77
+
44
78
Stream listStream = null ;
45
79
Task . Run ( async ( ) => { listStream = await new DownloadService ( ) . DownloadFileTaskAsync ( FPM . ListURL ) ; } ) . Wait ( ) ;
46
80
@@ -59,10 +93,13 @@ static void Main(string[] args)
59
93
FPM . XmlTree = new XmlDocument ( ) ;
60
94
FPM . XmlTree . Load ( listStream ) ;
61
95
96
+ // Verify that the configured Flashpoint path is valid
62
97
FPM . VerifySourcePath ( ) ;
63
98
99
+ // Open update tab on startup if /update argument is passed
64
100
if ( args . Length > 0 && args [ 0 ] . ToLower ( ) == "/update" ) FPM . OpenUpdateTab = true ;
65
101
102
+ // Display the application window
66
103
Application . Run ( new Main ( ) ) ;
67
104
}
68
105
}
0 commit comments