66using System . Linq ;
77using System . Reflection ;
88using System . Runtime . CompilerServices ;
9+ using System . Threading ;
910
1011namespace CSharpFinder
1112{
@@ -15,6 +16,8 @@ internal class Program
1516 private static readonly Logger logger = new Logger ( _logPath ) ;
1617 private static bool consoleResized = false ;
1718 private static bool errorOccured = false ;
19+ private static bool gotValidAnswer = false ;
20+ private static ConsoleKeyInfo info ;
1821
1922 static void Main ( string [ ] args )
2023 {
@@ -35,9 +38,14 @@ static void Main(string[] args)
3538
3639
3740 // Anzeigeeinstellungen
38- Console . Title = "CSharp Finder" ;
41+ Console . Title = "CSharp Finder v" + Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ;
3942 Console . ForegroundColor = ConsoleColor . DarkRed ;
4043
44+ if ( Environment . Is64BitProcess )
45+ {
46+ Console . Title += " (64-bit Windows)" ;
47+ }
48+
4149 try
4250 {
4351 if ( ! consoleResized )
@@ -62,21 +70,30 @@ static void Main(string[] args)
6270 // ============================================
6371
6472
65- Console . ForegroundColor = ConsoleColor . Gray ;
66- Console . Write ( "> Bitte geben sie den Pfad des Verzeichnisses ein, dass auf C#-Dateien untersucht werden soll: " ) ;
67- Console . ForegroundColor = ConsoleColor . White ;
68- string dirPath = Console . ReadLine ( ) ;
69-
7073 // Prüfen ob Pfad gefüllt
71- if ( string . IsNullOrEmpty ( dirPath ) )
74+ string dirPath = "" ;
75+ do
7276 {
73- WriteErrorLine ( "Bitte geben sie einen Pfad an!!" ) ;
74- }
77+ Console . ForegroundColor = ConsoleColor . Gray ;
78+ Console . Write ( "> Bitte geben sie den Pfad des Verzeichnisses ein, dass auf C#-Dateien untersucht werden soll: " ) ;
79+ Console . ForegroundColor = ConsoleColor . White ;
80+
81+ dirPath = Console . ReadLine ( ) ;
82+ if ( ! string . IsNullOrEmpty ( dirPath ) )
83+ {
84+ gotValidAnswer = true ;
85+ }
86+ else
87+ {
88+ WriteErrorLine ( "Bitte geben sie einen Pfad an!!" , false ) ;
89+ gotValidAnswer = false ;
90+ }
91+ } while ( ! gotValidAnswer ) ;
7592
7693 // Prüfen ob Zielverzeichnis existiert
7794 if ( ! Directory . Exists ( dirPath ) )
7895 {
79- WriteErrorLine ( "Dieses Verzeichnis existiert nicht. Bitte wählen sie en anderes Verzeichnis aus!!! " ) ;
96+ WriteErrorLine ( "Dieses Verzeichnis existiert nicht. Bitte wählen sie en anderes Verzeichnis aus!" ) ;
8097 }
8198
8299 // Dateien auflisten
@@ -93,7 +110,7 @@ static void Main(string[] args)
93110
94111 // Startmeldung
95112 Console . ForegroundColor = ConsoleColor . Blue ;
96- Console . WriteLine ( "Dateien werden gesucht..." ) ;
113+ Console . WriteLine ( "\n [INFO]: Dateien werden gesucht..." ) ;
97114
98115 // Zielverzeichnis für kopierte Dateien
99116 string resultDirPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "result" ) ;
@@ -125,16 +142,57 @@ static void Main(string[] args)
125142
126143
127144 // ============================================
128- // ============= Dateien prüfen = =============
145+ // ============ Dateien kopieren =============
129146 // ============================================
130147
148+ gotValidAnswer = false ;
149+ info = new ConsoleKeyInfo ( ) ;
150+ bool copyFiles = false ;
151+
152+ Console . ForegroundColor = ConsoleColor . Gray ;
153+ Console . WriteLine ( "\n > Möchten Sie diese Dateien kopieren? [Y/N]" ) ;
154+
155+ do
156+ {
157+ info = Console . ReadKey ( ) ;
158+ Console . WriteLine ( "\b " ) ;
159+
160+ switch ( info . Key )
161+ {
162+ case ( ConsoleKey . Y ) :
163+ copyFiles = true ;
164+ gotValidAnswer = true ;
165+ break ;
166+ case ( ConsoleKey . N ) :
167+ copyFiles = false ;
168+ gotValidAnswer = true ;
169+ break ;
170+ default :
171+ Console . WriteLine ( ) ;
172+ Console . ForegroundColor = ConsoleColor . Red ;
173+ Console . WriteLine ( "Keine gültige Eingabe!" ) ;
174+ gotValidAnswer = false ;
175+ break ;
176+ }
177+ } while ( ! gotValidAnswer ) ;
178+
179+ if ( ! copyFiles )
180+ {
181+ Console . ForegroundColor = ConsoleColor . Red ;
182+ Console . WriteLine ( "\n Es wurde keine Aktion ausgeführt. Das Programm wird automatisch geschlossen..." ) ;
183+ Thread . Sleep ( 2500 ) ;
184+ Environment . Exit ( 0 ) ;
185+ }
186+
131187 Console . ForegroundColor = ConsoleColor . White ;
132- Console . WriteLine ( "[INFO]: Dateien werden kopiert..." ) ;
188+ Console . WriteLine ( "\n [INFO]: Dateien werden kopiert..." ) ;
133189
190+ // Dateien durchlaufen
134191 foreach ( string file in files )
135192 {
136193 try
137194 {
195+ // Prüfen auf C# / .NET Datei
138196 if ( IsCSharpAssembly ( file ) )
139197 {
140198 // Kompletten Pfad bekommen, Datei in Liste hinzufügen
@@ -191,16 +249,17 @@ static void Main(string[] args)
191249 // ============================================
192250
193251
194- bool gotValidAnswer = false ;
195- ConsoleKeyInfo info = new ConsoleKeyInfo ( ) ;
252+ gotValidAnswer = false ;
253+ info = new ConsoleKeyInfo ( ) ;
196254
197255 Console . WriteLine ( ) ;
198256 Console . ForegroundColor = ConsoleColor . Gray ;
199- Console . WriteLine ( "Möchten Sie das Kopierverzeichnis öffnen? [Y/N]" ) ;
257+ Console . WriteLine ( "\n > Möchten Sie das Kopierverzeichnis öffnen? [Y/N]" ) ;
200258
201259 do
202260 {
203261 info = Console . ReadKey ( ) ;
262+ Console . WriteLine ( "\b " ) ;
204263
205264 switch ( info . Key )
206265 {
@@ -231,13 +290,15 @@ static void Main(string[] args)
231290 {
232291 gotValidAnswer = false ;
233292 info = new ConsoleKeyInfo ( ) ;
293+
234294 Console . WriteLine ( ) ;
235295 Console . ForegroundColor = ConsoleColor . Gray ;
236- Console . WriteLine ( "Möchten Sie die Log-Datei öffnen? [Y/N]" ) ;
296+ Console . WriteLine ( "\n > Möchten Sie die Log-Datei öffnen? [Y/N]" ) ;
237297
238298 do
239299 {
240300 info = Console . ReadKey ( ) ;
301+ Console . WriteLine ( "\b " ) ;
241302
242303 switch ( info . Key )
243304 {
@@ -264,11 +325,12 @@ static void Main(string[] args)
264325 info = new ConsoleKeyInfo ( ) ;
265326 Console . WriteLine ( ) ;
266327 Console . ForegroundColor = ConsoleColor . Gray ;
267- Console . WriteLine ( "Möchten Sie versuchen, die kopierten Dateien so klein wie möglich zu komprimieren? (Beta) [Y/N]" ) ;
328+ Console . WriteLine ( "\n > Möchten Sie versuchen, die kopierten Dateien so klein wie möglich zu komprimieren? (Beta) [Y/N]" ) ;
268329
269330 do
270331 {
271332 info = Console . ReadKey ( ) ;
333+ Console . WriteLine ( "\b " ) ;
272334
273335 switch ( info . Key )
274336 {
@@ -290,34 +352,39 @@ static void Main(string[] args)
290352 }
291353 } while ( ! gotValidAnswer ) ;
292354
293- // Komprimierte Dateien anzeigen?
294- gotValidAnswer = false ;
295- info = new ConsoleKeyInfo ( ) ;
296- Console . WriteLine ( ) ;
297- Console . ForegroundColor = ConsoleColor . Gray ;
298- Console . WriteLine ( "Möchten Sie das Verzeichnis der komprimierten Dateien öffnen? [Y/N]" ) ;
299-
300- do
355+ // Prüfen ob Dateien komprimiert wurden?
356+ if ( compressFiles )
301357 {
302- info = Console . ReadKey ( ) ;
358+ // Komprimierte Dateien anzeigen?
359+ gotValidAnswer = false ;
360+ info = new ConsoleKeyInfo ( ) ;
361+ Console . WriteLine ( ) ;
362+ Console . ForegroundColor = ConsoleColor . Gray ;
363+ Console . WriteLine ( "\n > Möchten Sie das Verzeichnis der komprimierten Dateien öffnen? [Y/N]" ) ;
303364
304- switch ( info . Key )
365+ do
305366 {
306- case ( ConsoleKey . Y ) :
307- Process . Start ( Path . Combine ( resultDirPath , "compressed" ) ) ;
308- gotValidAnswer = true ;
309- break ;
310- case ( ConsoleKey . N ) :
311- gotValidAnswer = true ;
312- break ;
313- default :
314- Console . WriteLine ( ) ;
315- Console . ForegroundColor = ConsoleColor . Red ;
316- Console . WriteLine ( "Keine gültige Eingabe!" ) ;
317- gotValidAnswer = false ;
318- break ;
319- }
320- } while ( ! gotValidAnswer ) ;
367+ info = Console . ReadKey ( ) ;
368+ Console . WriteLine ( "\b " ) ;
369+
370+ switch ( info . Key )
371+ {
372+ case ( ConsoleKey . Y ) :
373+ Process . Start ( Path . Combine ( resultDirPath , "compressed" ) ) ;
374+ gotValidAnswer = true ;
375+ break ;
376+ case ( ConsoleKey . N ) :
377+ gotValidAnswer = true ;
378+ break ;
379+ default :
380+ Console . WriteLine ( ) ;
381+ Console . ForegroundColor = ConsoleColor . Red ;
382+ Console . WriteLine ( "Keine gültige Eingabe!" ) ;
383+ gotValidAnswer = false ;
384+ break ;
385+ }
386+ } while ( ! gotValidAnswer ) ;
387+ }
321388
322389 Environment . Exit ( 0 ) ;
323390 }
@@ -352,7 +419,7 @@ private static void CompressFiles(string filePath)
352419 using ( GZipStream compressionStream = new GZipStream ( compressedFileStream , CompressionMode . Compress ) )
353420 {
354421 originalFileStream . CopyTo ( compressionStream ) ;
355- Console . WriteLine ( "Datei komprimiert/kopiert zu: " + compressedFile ) ;
422+ Console . WriteLine ( "Datei komprimiert/kopiert zu: " + compressedFile . Replace ( filePath , "..." ) ) ;
356423 }
357424 }
358425 }
@@ -361,12 +428,18 @@ private static void CompressFiles(string filePath)
361428 Console . WriteLine ( "[INFO]: Dateien kopiert. Nutzen sie 7Zip oder andere Tools, um die Dateien wieder zu dekomprimieren." ) ;
362429 }
363430
364- private static void WriteErrorLine ( string message )
431+ private static void WriteErrorLine ( string message , bool restart = true )
365432 {
366433 Console . ForegroundColor = ConsoleColor . Red ;
367- Console . WriteLine ( message ) ;
434+ Console . WriteLine ( "[ERROR]: " + message ) ;
368435 Console . ReadKey ( ) ;
369- Main ( new string [ 0 ] ) ;
436+
437+ // Prüfen auf geforderten Restart
438+ if ( restart )
439+ {
440+ Console . Clear ( ) ;
441+ Main ( new string [ 0 ] ) ;
442+ }
370443 }
371444
372445 private static bool IsCSharpAssembly ( string assemblyLocation )
0 commit comments