@@ -45,13 +45,13 @@ public static class Program
4545 private const string ConfigFileName = "SharpLoader.ini" ;
4646 private static readonly string MyPath = Process . GetCurrentProcess ( ) . MainModule . FileName ;
4747 private static readonly string MyDirectory = Path . GetDirectoryName ( MyPath ) ;
48- private static readonly string ConfigPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
48+ public static string ConfigPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
4949
50+ public static List < string > DragDropPaths ;
5051 public static int Seed = - 1 ;
5152 public static string Hash ;
5253
5354 private static MainForm _form ;
54- private static List < string > _dragDropPaths ;
5555 private static bool _outToConsole ;
5656
5757 [ STAThread ]
@@ -62,7 +62,7 @@ public static void Main(string[] args)
6262 // Hide cmd
6363 ShowWindow ( GetConsoleWindow ( ) , SW_HIDE ) ;
6464
65- _dragDropPaths = new List < string > ( ) ;
65+ DragDropPaths = new List < string > ( ) ;
6666
6767 var cmdMode = false ;
6868
@@ -74,32 +74,20 @@ public static void Main(string[] args)
7474 // Directory
7575 if ( File . GetAttributes ( args [ i ] ) . HasFlag ( FileAttributes . Directory ) )
7676 {
77- _dragDropPaths . AddRange ( GetFilesFromDirectory ( args [ i ] ) ) ;
77+ DragDropPaths . AddRange ( GetFilesFromDirectory ( args [ i ] ) ) ;
7878 }
7979 // File
8080 else
8181 {
8282 // Zip
8383 if ( Path . GetExtension ( args [ i ] ) == ".zip" )
8484 {
85- var zipBytes = File . ReadAllBytes ( args [ i ] ) ;
86- var zipHash = MD5 . Create ( ) . ComputeHash ( zipBytes ) ;
87-
88- var tempDir = Path . GetTempPath ( ) + ByteArrayToString ( zipHash ) ;
89-
90- if ( Directory . Exists ( tempDir ) )
91- {
92- Directory . Delete ( tempDir , true ) ;
93- }
94-
95- ZipFile . ExtractToDirectory ( args [ i ] , tempDir ) ;
96-
97- _dragDropPaths . AddRange ( ScanDir ( tempDir ) ) ;
85+ ProcessZip ( args [ i ] ) ;
9886 }
9987 // Normal
10088 else
10189 {
102- _dragDropPaths . Add ( args [ i ] ) ;
90+ DragDropPaths . Add ( args [ i ] ) ;
10391 }
10492 }
10593 }
@@ -136,25 +124,41 @@ public static void Main(string[] args)
136124 Seed = new Random ( Environment . TickCount ) . Next ( 0 , int . MaxValue ) ;
137125 }
138126
127+ // Show UI
139128 if ( ! cmdMode )
140129 {
141130 Application . EnableVisualStyles ( ) ;
142131 Application . SetCompatibleTextRenderingDefault ( false ) ;
143132 Application . Run ( _form = new MainForm ( ) ) ;
144-
145- return ;
146133 }
147-
148134 // Show cmd
149- ShowWindow ( GetConsoleWindow ( ) , SW_SHOW ) ;
150- _outToConsole = true ;
151-
152- var compileResult = Compile ( ) ;
153- if ( compileResult != 0 )
135+ else
154136 {
155- Console . ReadKey ( ) ;
137+ // Data file not found
138+ if ( ! File . Exists ( ConfigPath ) )
139+ {
140+ WinApi . WritePrivateProfileString ( "SharpLoader" , "References" , "" , ConfigPath ) ;
141+ WinApi . WritePrivateProfileString ( "SharpLoader" , "Directory" , "" , ConfigPath ) ;
142+ WinApi . WritePrivateProfileString ( "SharpLoader" , "Sources" , "" , ConfigPath ) ;
143+ WinApi . WritePrivateProfileString ( "SharpLoader" , "Output" , "SharpLoader" , ConfigPath ) ;
144+ WinApi . WritePrivateProfileString ( "SharpLoader" , "Arguments" , "/platform:anycpu32bitpreferred" , ConfigPath ) ;
145+ WinApi . WritePrivateProfileString ( "SharpLoader" , "AutoRun" , "false" , ConfigPath ) ;
146+
147+ Environment . Exit ( 1 ) ;
148+ }
149+
150+ ShowWindow ( GetConsoleWindow ( ) , SW_SHOW ) ;
151+ _outToConsole = true ;
152+
153+ var compileResult = Compile ( ) ;
154+ if ( compileResult != 0 )
155+ {
156+ Console . ReadKey ( ) ;
157+ }
158+
159+ CleanTemp ( ) ;
160+ Environment . Exit ( compileResult ) ;
156161 }
157- Environment . Exit ( compileResult ) ;
158162 }
159163
160164 public static int Compile ( )
@@ -175,21 +179,11 @@ public static int Compile()
175179 Out ( "" ) ;
176180
177181 // Data file not found
178- if ( ! File . Exists ( ConfigFileName ) )
182+ if ( ! File . Exists ( ConfigPath ) )
179183 {
180184 Console . ForegroundColor = ConsoleColor . Red ;
181185 Out ( $ "-=: Config file not found ({ ConfigFileName } )") ;
182186
183- WinApi . WritePrivateProfileString ( "SharpLoader" , "References" , "" , ConfigPath ) ;
184- WinApi . WritePrivateProfileString ( "SharpLoader" , "Directory" , "" , ConfigPath ) ;
185- WinApi . WritePrivateProfileString ( "SharpLoader" , "Sources" , "" , ConfigPath ) ;
186- WinApi . WritePrivateProfileString ( "SharpLoader" , "Output" , "SharpLoader" , ConfigPath ) ;
187- WinApi . WritePrivateProfileString ( "SharpLoader" , "Arguments" , "/platform:anycpu32bitpreferred" , ConfigPath ) ;
188- WinApi . WritePrivateProfileString ( "SharpLoader" , "AutoRun" , "false" , ConfigPath ) ;
189-
190- Console . ForegroundColor = ConsoleColor . Red ;
191- Out ( $ "-=: Default config file generated") ;
192-
193187 return 1 ;
194188 }
195189
@@ -218,9 +212,9 @@ public static int Compile()
218212 var autoRun = autoRunReadSb . ToString ( ) . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ;
219213
220214 // Drag n Drop
221- if ( _dragDropPaths . Count != 0 )
215+ if ( DragDropPaths . Count != 0 )
222216 {
223- userSourcePaths = _dragDropPaths . ToArray ( ) ;
217+ userSourcePaths = DragDropPaths . ToArray ( ) ;
224218 }
225219 // Read from config
226220 else
@@ -450,6 +444,44 @@ public static void Out(string text)
450444 }
451445 }
452446
447+ public static void ProcessZip ( string path )
448+ {
449+ var zipBytes = File . ReadAllBytes ( path ) ;
450+ var zipHash = MD5 . Create ( ) . ComputeHash ( zipBytes ) ;
451+
452+ var tempDir = Path . GetTempPath ( ) + @"SharpLoader\" + ByteArrayToString ( zipHash ) ;
453+
454+ if ( Directory . Exists ( tempDir ) )
455+ {
456+ Directory . Delete ( tempDir , true ) ;
457+ }
458+
459+ ZipFile . ExtractToDirectory ( path , tempDir ) ;
460+
461+ var unzipFiles = ScanDir ( tempDir ) ;
462+
463+ foreach ( var unzipFile in unzipFiles )
464+ {
465+ if ( unzipFile . EndsWith ( ConfigFileName ) )
466+ {
467+ ConfigPath = unzipFile ;
468+ }
469+ else
470+ {
471+ DragDropPaths . Add ( unzipFile ) ;
472+ }
473+ }
474+ }
475+
476+ public static void CleanTemp ( )
477+ {
478+ var path = Path . GetTempPath ( ) + "SharpLoader" ;
479+ if ( Directory . Exists ( path ) )
480+ {
481+ Directory . Delete ( path , true ) ;
482+ }
483+ }
484+
453485 private static IEnumerable < string > GetFilesFromDirectory ( string directory )
454486 {
455487 var dir = new DirectoryInfo ( directory ) ;
0 commit comments