44using System . IO ;
55using System . IO . Compression ;
66using System . Linq ;
7- using System . Reflection ;
87using System . Runtime . InteropServices ;
98using System . Security . Cryptography ;
109using System . Text ;
@@ -15,6 +14,10 @@ namespace SharpLoader
1514{
1615 public static class Program
1716 {
17+ /* Limitations:
18+ * supports only c# 5.0
19+ */
20+
1821 /* Exit codes:
1922 * 0 - default
2023 * 1 - data file not found
@@ -35,19 +38,18 @@ public static class Program
3538 private const int SW_SHOW = 5 ;
3639
3740 public const string Author = "Zaczero" ;
38- public const string Version = "2.1" ;
41+ public const string Version = "2.0. 1" ;
3942
4043 private const int ReadBufferSize = ushort . MaxValue ;
4144
4245 private const string ConfigFileName = "SharpLoader.ini" ;
4346 private static readonly string MyPath = Process . GetCurrentProcess ( ) . MainModule . FileName ;
4447 private static readonly string MyDirectory = Path . GetDirectoryName ( MyPath ) ;
45- public static string ConfigPath ;
48+ public static string ConfigPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
4649
4750 public static List < string > DragDropPaths ;
4851 public static int Seed = - 1 ;
4952 public static string Hash ;
50- public static string SaveDir ;
5153
5254 private static MainForm _form ;
5355 private static bool _outToConsole ;
@@ -67,7 +69,7 @@ public static void Main(string[] args)
6769 for ( var i = 0 ; i < args . Length ; i ++ )
6870 {
6971 // Argument is path
70- if ( ( File . Exists ( args [ i ] ) || Directory . Exists ( args [ i ] ) ) && Path . GetExtension ( args [ i ] ) != ".exe" )
72+ if ( args [ i ] != MyPath && ( File . Exists ( args [ i ] ) || Directory . Exists ( args [ i ] ) ) )
7173 {
7274 // Directory
7375 if ( File . GetAttributes ( args [ i ] ) . HasFlag ( FileAttributes . Directory ) )
@@ -92,12 +94,6 @@ public static void Main(string[] args)
9294 // Normal argument
9395 else
9496 {
95- if ( args [ i ] == "-cmd" )
96- {
97- cmdMode = true ;
98- continue ;
99- }
100-
10197 // Multiple arguments
10298 if ( i + 1 < args . Length )
10399 {
@@ -109,12 +105,14 @@ public static void Main(string[] args)
109105 {
110106 throw new Exception ( $ "invalid seed value: { args [ i + 1 ] } ") ;
111107 }
112- i ++ ;
113108 }
114- else if ( args [ i ] == "-path" )
109+ }
110+ // Single argument
111+ else
112+ {
113+ if ( args [ i ] == "-cmd" )
115114 {
116- SaveDir = args [ i + 1 ] ;
117- i ++ ;
115+ cmdMode = true ;
118116 }
119117 }
120118 }
@@ -126,18 +124,6 @@ public static void Main(string[] args)
126124 Seed = new Random ( Environment . TickCount ) . Next ( 0 , int . MaxValue ) ;
127125 }
128126
129- if ( string . IsNullOrEmpty ( SaveDir ) )
130- {
131- ConfigPath = Path . Combine ( MyDirectory , ConfigFileName ) ;
132- SaveDir = MyDirectory ;
133- }
134- else
135- {
136- ConfigPath = Path . Combine ( SaveDir , ConfigFileName ) ;
137- }
138-
139- DumpToAppData ( ) ;
140-
141127 // Show UI
142128 if ( ! cmdMode )
143129 {
@@ -175,55 +161,6 @@ public static void Main(string[] args)
175161 }
176162 }
177163
178- public static void DumpToAppData ( )
179- {
180- var appDataPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "SharpLoader" ) ;
181- var exePath = Path . Combine ( appDataPath , "SharpLoader.exe" ) ;
182- var thisPath = Process . GetCurrentProcess ( ) . MainModule . FileName ;
183-
184- if ( thisPath != exePath )
185- {
186- if ( ! Directory . Exists ( appDataPath ) )
187- {
188- Directory . CreateDirectory ( appDataPath ) ;
189- }
190-
191- // Run the newest file
192- File . Copy ( thisPath , exePath , true ) ;
193-
194- var argsString = string . Empty ;
195- foreach ( var arg in Environment . GetCommandLineArgs ( ) )
196- {
197- if ( File . Exists ( arg ) )
198- {
199- argsString += $ "\" { arg } \" ";
200- }
201- else
202- {
203- argsString += $ "{ arg } ";
204- }
205- }
206- argsString = argsString . TrimEnd ( ' ' ) ;
207-
208- Process . Start ( exePath , $ "{ argsString } -path \" { SaveDir } \" ") ;
209- Environment . Exit ( 0 ) ;
210- }
211-
212- var binPath = Path . Combine ( appDataPath , "bin" ) ;
213- var binZipPath = Path . Combine ( appDataPath , "bin.zip" ) ;
214-
215- if ( ! Directory . Exists ( binPath ) )
216- {
217- if ( ! File . Exists ( binZipPath ) )
218- {
219- WriteResourceToFile ( "SharpLoader.bin.zip" , binZipPath ) ;
220- }
221-
222- ZipFile . ExtractToDirectory ( binZipPath , binPath ) ;
223- File . Delete ( binZipPath ) ;
224- }
225- }
226-
227164 public static int Compile ( )
228165 {
229166 var randomizer = new SourceRandomizer ( Seed ) ;
@@ -302,8 +239,6 @@ public static int Compile()
302239 return 2 ;
303240 }
304241
305- outputName = Path . Combine ( SaveDir , outputName ) ;
306-
307242 // Read sources
308243 var userSourceFiles = new List < string > ( ) ;
309244
@@ -475,10 +410,8 @@ public static int Compile()
475410 return 4 ;
476411 }
477412
478- int . TryParse ( "lol" , out int parseeed ) ;
479-
480413 Console . ForegroundColor = ConsoleColor . Green ;
481- Out ( $ "-=: Done [{ Path . GetFileName ( outputName ) } ] { ( _outToConsole ? "(press any key to exit)" : string . Empty ) } ") ;
414+ Out ( $ "-=: Done [{ outputName } ] { ( _outToConsole ? "(press any key to exit)" : string . Empty ) } ") ;
482415
483416 var sourceBytes = new List < byte > ( ) ;
484417 foreach ( var s in compileSourceFiles )
@@ -549,17 +482,6 @@ public static void CleanTemp()
549482 }
550483 }
551484
552- private static void WriteResourceToFile ( string resourceName , string fileName )
553- {
554- using ( var resource = Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( resourceName ) )
555- {
556- using ( var file = new FileStream ( fileName , FileMode . Create , FileAccess . Write ) )
557- {
558- resource . CopyTo ( file ) ;
559- }
560- }
561- }
562-
563485 private static IEnumerable < string > GetFilesFromDirectory ( string directory )
564486 {
565487 var dir = new DirectoryInfo ( directory ) ;
0 commit comments