@@ -45,14 +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-
48+ public static string ConfigPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
49+
50+ public static List < string > DragDropPaths ;
4951 public static int Seed = - 1 ;
5052 public static string Hash ;
5153
52- private static string _configPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
53-
5454 private static MainForm _form ;
55- private static List < string > _dragDropPaths ;
5655 private static bool _outToConsole ;
5756
5857 [ STAThread ]
@@ -63,7 +62,7 @@ public static void Main(string[] args)
6362 // Hide cmd
6463 ShowWindow ( GetConsoleWindow ( ) , SW_HIDE ) ;
6564
66- _dragDropPaths = new List < string > ( ) ;
65+ DragDropPaths = new List < string > ( ) ;
6766
6867 var cmdMode = false ;
6968
@@ -75,44 +74,20 @@ public static void Main(string[] args)
7574 // Directory
7675 if ( File . GetAttributes ( args [ i ] ) . HasFlag ( FileAttributes . Directory ) )
7776 {
78- _dragDropPaths . AddRange ( GetFilesFromDirectory ( args [ i ] ) ) ;
77+ DragDropPaths . AddRange ( GetFilesFromDirectory ( args [ i ] ) ) ;
7978 }
8079 // File
8180 else
8281 {
8382 // Zip
8483 if ( Path . GetExtension ( args [ i ] ) == ".zip" )
8584 {
86- var zipBytes = File . ReadAllBytes ( args [ i ] ) ;
87- var zipHash = MD5 . Create ( ) . ComputeHash ( zipBytes ) ;
88-
89- var tempDir = Path . GetTempPath ( ) + ByteArrayToString ( zipHash ) ;
90-
91- if ( Directory . Exists ( tempDir ) )
92- {
93- Directory . Delete ( tempDir , true ) ;
94- }
95-
96- ZipFile . ExtractToDirectory ( args [ i ] , tempDir ) ;
97-
98- var unzipFiles = ScanDir ( tempDir ) ;
99-
100- foreach ( var unzipFile in unzipFiles )
101- {
102- if ( unzipFile . EndsWith ( ConfigFileName ) )
103- {
104- _configPath = unzipFile ;
105- }
106- else
107- {
108- _dragDropPaths . Add ( unzipFile ) ;
109- }
110- }
85+ ProcessZip ( args [ i ] ) ;
11186 }
11287 // Normal
11388 else
11489 {
115- _dragDropPaths . Add ( args [ i ] ) ;
90+ DragDropPaths . Add ( args [ i ] ) ;
11691 }
11792 }
11893 }
@@ -143,44 +118,46 @@ public static void Main(string[] args)
143118 }
144119 }
145120
146- // Data file not found
147- if ( ! File . Exists ( _configPath ) )
148- {
149- WinApi . WritePrivateProfileString ( "SharpLoader" , "References" , "" , _configPath ) ;
150- WinApi . WritePrivateProfileString ( "SharpLoader" , "Directory" , "" , _configPath ) ;
151- WinApi . WritePrivateProfileString ( "SharpLoader" , "Sources" , "" , _configPath ) ;
152- WinApi . WritePrivateProfileString ( "SharpLoader" , "Output" , "SharpLoader" , _configPath ) ;
153- WinApi . WritePrivateProfileString ( "SharpLoader" , "Arguments" , "/platform:anycpu32bitpreferred" , _configPath ) ;
154- WinApi . WritePrivateProfileString ( "SharpLoader" , "AutoRun" , "false" , _configPath ) ;
155-
156- Environment . Exit ( 1 ) ;
157- }
158-
159121 // Generate random seed
160122 if ( Seed == - 1 )
161123 {
162124 Seed = new Random ( Environment . TickCount ) . Next ( 0 , int . MaxValue ) ;
163125 }
164126
127+ // Show UI
165128 if ( ! cmdMode )
166129 {
167130 Application . EnableVisualStyles ( ) ;
168131 Application . SetCompatibleTextRenderingDefault ( false ) ;
169132 Application . Run ( _form = new MainForm ( ) ) ;
170-
171- return ;
172133 }
173-
174134 // Show cmd
175- ShowWindow ( GetConsoleWindow ( ) , SW_SHOW ) ;
176- _outToConsole = true ;
177-
178- var compileResult = Compile ( ) ;
179- if ( compileResult != 0 )
135+ else
180136 {
181- 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+ Environment . Exit ( compileResult ) ;
182160 }
183- Environment . Exit ( compileResult ) ;
184161 }
185162
186163 public static int Compile ( )
@@ -201,7 +178,7 @@ public static int Compile()
201178 Out ( "" ) ;
202179
203180 // Data file not found
204- if ( ! File . Exists ( _configPath ) )
181+ if ( ! File . Exists ( ConfigPath ) )
205182 {
206183 Console . ForegroundColor = ConsoleColor . Red ;
207184 Out ( $ "-=: Config file not found ({ ConfigFileName } )") ;
@@ -219,12 +196,12 @@ public static int Compile()
219196 var compilerArgumentsReadSb = new StringBuilder ( ReadBufferSize ) ;
220197 var autoRunReadSb = new StringBuilder ( ReadBufferSize ) ;
221198
222- WinApi . GetPrivateProfileString ( "SharpLoader" , "References" , string . Empty , userReferencesReadSb , ReadBufferSize , _configPath ) ;
223- WinApi . GetPrivateProfileString ( "SharpLoader" , "Directory" , string . Empty , baseDirectoryReadSb , ReadBufferSize , _configPath ) ;
224- WinApi . GetPrivateProfileString ( "SharpLoader" , "Sources" , string . Empty , sourceFilesReadSb , ReadBufferSize , _configPath ) ;
225- WinApi . GetPrivateProfileString ( "SharpLoader" , "Output" , string . Empty , outputNameReadSb , ReadBufferSize , _configPath ) ;
226- WinApi . GetPrivateProfileString ( "SharpLoader" , "Arguments" , string . Empty , compilerArgumentsReadSb , ReadBufferSize , _configPath ) ;
227- WinApi . GetPrivateProfileString ( "SharpLoader" , "AutoRun" , string . Empty , autoRunReadSb , ReadBufferSize , _configPath ) ;
199+ WinApi . GetPrivateProfileString ( "SharpLoader" , "References" , string . Empty , userReferencesReadSb , ReadBufferSize , ConfigPath ) ;
200+ WinApi . GetPrivateProfileString ( "SharpLoader" , "Directory" , string . Empty , baseDirectoryReadSb , ReadBufferSize , ConfigPath ) ;
201+ WinApi . GetPrivateProfileString ( "SharpLoader" , "Sources" , string . Empty , sourceFilesReadSb , ReadBufferSize , ConfigPath ) ;
202+ WinApi . GetPrivateProfileString ( "SharpLoader" , "Output" , string . Empty , outputNameReadSb , ReadBufferSize , ConfigPath ) ;
203+ WinApi . GetPrivateProfileString ( "SharpLoader" , "Arguments" , string . Empty , compilerArgumentsReadSb , ReadBufferSize , ConfigPath ) ;
204+ WinApi . GetPrivateProfileString ( "SharpLoader" , "AutoRun" , string . Empty , autoRunReadSb , ReadBufferSize , ConfigPath ) ;
228205
229206 var userReferences = userReferencesReadSb . ToString ( ) . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
230207 var baseDirectory = baseDirectoryReadSb . ToString ( ) ;
@@ -234,9 +211,9 @@ public static int Compile()
234211 var autoRun = autoRunReadSb . ToString ( ) . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ;
235212
236213 // Drag n Drop
237- if ( _dragDropPaths . Count != 0 )
214+ if ( DragDropPaths . Count != 0 )
238215 {
239- userSourcePaths = _dragDropPaths . ToArray ( ) ;
216+ userSourcePaths = DragDropPaths . ToArray ( ) ;
240217 }
241218 // Read from config
242219 else
@@ -466,6 +443,35 @@ public static void Out(string text)
466443 }
467444 }
468445
446+ public static void ProcessZip ( string path )
447+ {
448+ var zipBytes = File . ReadAllBytes ( path ) ;
449+ var zipHash = MD5 . Create ( ) . ComputeHash ( zipBytes ) ;
450+
451+ var tempDir = Path . GetTempPath ( ) + ByteArrayToString ( zipHash ) ;
452+
453+ if ( Directory . Exists ( tempDir ) )
454+ {
455+ Directory . Delete ( tempDir , true ) ;
456+ }
457+
458+ ZipFile . ExtractToDirectory ( path , tempDir ) ;
459+
460+ var unzipFiles = ScanDir ( tempDir ) ;
461+
462+ foreach ( var unzipFile in unzipFiles )
463+ {
464+ if ( unzipFile . EndsWith ( ConfigFileName ) )
465+ {
466+ ConfigPath = unzipFile ;
467+ }
468+ else
469+ {
470+ DragDropPaths . Add ( unzipFile ) ;
471+ }
472+ }
473+ }
474+
469475 private static IEnumerable < string > GetFilesFromDirectory ( string directory )
470476 {
471477 var dir = new DirectoryInfo ( directory ) ;
0 commit comments