1717
1818namespace SmartImage
1919{
20- internal static class Commands
20+ internal enum IntegrationOption
2121 {
22- internal const string OPT_ADD = "add" ;
23- internal const string OPT_REM = "remove" ;
24- internal const string OPT_ALL = "all" ;
22+ Add ,
23+ Remove
24+ }
2525
26+ /// <summary>
27+ /// Program functionality and integration
28+ /// </summary>
29+ internal static class Commands
30+ {
2631 private const char CLI_CHAR = '*' ;
2732
28- internal static void RunContextMenuIntegration ( string option )
33+ internal static void RunContextMenuIntegration ( IntegrationOption option )
2934 {
3035 switch ( option ) {
31- case OPT_ADD :
36+ case IntegrationOption . Add :
3237 string fullPath = RuntimeInfo . ExeLocation ;
3338
3439 if ( ! RuntimeInfo . IsExeInAppFolder ) {
@@ -44,34 +49,33 @@ internal static void RunContextMenuIntegration(string option)
4449 string [ ] commandCode =
4550 {
4651 "@echo off" ,
47- String . Format ( "reg.exe add {0} /ve /d \" {1} \" \" %%1\" \" \" /f >nul" , RuntimeInfo . REG_SHELL_CMD ,
48- fullPath ) ,
49- String . Format ( "reg.exe add {0} /v Icon /d \" {1}\" /f >nul" , RuntimeInfo . REG_SHELL , fullPath )
52+ $ "reg.exe add { RuntimeInfo . REG_SHELL_CMD } /ve /d \" { fullPath } \" \" %%1\" \" \" /f >nul",
53+ $ "reg.exe add { RuntimeInfo . REG_SHELL } /v Icon /d \" { fullPath } \" /f >nul"
5054 } ;
5155
5256 Cli . CreateRunBatchFile ( "add_to_menu.bat" , commandCode ) ;
5357
5458 break ;
55- case OPT_REM :
59+ case IntegrationOption . Remove :
5660 // reg delete HKEY_CLASSES_ROOT\*\shell\SmartImage
5761
5862 // const string DEL = @"reg delete HKEY_CLASSES_ROOT\*\shell\SmartImage";
5963
6064 string [ ] code =
6165 {
6266 "@echo off" ,
63- String . Format ( @"reg.exe delete {0 } /f >nul" , RuntimeInfo . REG_SHELL )
67+ $ @ "reg.exe delete { RuntimeInfo . REG_SHELL } /f >nul"
6468 } ;
6569
6670 Cli . CreateRunBatchFile ( "rem_from_menu.bat" , code ) ;
6771 break ;
6872 }
6973 }
7074
71- internal static void RunPathIntegration ( string option )
75+ internal static void RunPathIntegration ( IntegrationOption option )
7276 {
7377 switch ( option ) {
74- case OPT_ADD :
78+ case IntegrationOption . Add :
7579 {
7680 string oldValue = ExplorerSystem . EnvironmentPath ;
7781
@@ -92,43 +96,44 @@ internal static void RunPathIntegration(string option)
9296
9397 break ;
9498 }
95- case OPT_REM :
99+ case IntegrationOption . Remove :
96100 ExplorerSystem . RemoveFromPath ( RuntimeInfo . AppFolder ) ;
97101 break ;
98102 }
99103 }
100104
101- internal static void RunReset ( string option )
105+ internal static void RunReset ( )
102106 {
103- bool all = option == OPT_ALL ;
104107
105108 SearchConfig . Config . Reset ( ) ;
109+ SearchConfig . Config . WriteToFile ( ) ;
106110
107111 // Computer\HKEY_CLASSES_ROOT\*\shell\SmartImage
108112
109- RunContextMenuIntegration ( OPT_REM ) ;
113+ RunContextMenuIntegration ( IntegrationOption . Remove ) ;
110114
111115 // will be added automatically if run again
112116 //Path.Remove();
113117
114- if ( all ) {
115- SearchConfig . Config . Reset ( ) ;
116- SearchConfig . Config . WriteToFile ( ) ;
117-
118- CliOutput . WriteSuccess ( "Reset cfg" ) ;
119- }
118+ CliOutput . WriteSuccess ( "Reset cfg" ) ;
120119 }
121120
122121 internal static void ShowInfo ( )
123122 {
124123 Console . Clear ( ) ;
125124
126125
127- // Config
126+ /*
127+ * Search settings
128+ */
128129
129130 CliOutput . WriteInfo ( "Search engines: {0}" , SearchConfig . Config . SearchEngines ) ;
130131 CliOutput . WriteInfo ( "Priority engines: {0}" , SearchConfig . Config . PriorityEngines ) ;
131132
133+ /*
134+ * API settings
135+ */
136+
132137 string sn = SearchConfig . Config . SauceNaoAuth ;
133138 bool snNull = String . IsNullOrWhiteSpace ( sn ) ;
134139
@@ -144,25 +149,34 @@ internal static void ShowInfo()
144149 CliOutput . WriteInfo ( "Image upload service: {0}" ,
145150 imgurNull ? "ImgOps" : "Imgur" ) ;
146151
152+
153+ /*
154+ * Runtime info
155+ */
156+
157+
147158 CliOutput . WriteInfo ( "Application folder: {0}" , RuntimeInfo . AppFolder ) ;
148159 CliOutput . WriteInfo ( "Executable location: {0}" , RuntimeInfo . ExeLocation ) ;
149-
150- CliOutput . WriteInfo ( "Config location: {0}" , RuntimeInfo . ConfigLocation ) ;
160+ CliOutput . WriteInfo ( "Config location: {0}" , SearchConfig . ConfigLocation ) ;
151161 CliOutput . WriteInfo ( "Context menu integrated: {0}" , RuntimeInfo . IsContextMenuAdded ) ;
152162 CliOutput . WriteInfo ( "In path: {0}\n " , RuntimeInfo . IsAppFolderInPath ) ;
153163
154164
155- // Version
165+ /*
166+ * Version info
167+ */
156168
157- var versionsInfo = VersionsInfo . Create ( ) ;
169+ var versionsInfo = UpdateInfo . CheckForUpdates ( ) ;
158170
159171 CliOutput . WriteInfo ( "Current version: {0}" , versionsInfo . Current ) ;
160172 CliOutput . WriteInfo ( "Latest version: {0}" , versionsInfo . Latest . Version ) ;
161- CliOutput . WriteInfo ( "{0}" , versionsInfo . Status ) ;
173+ CliOutput . WriteInfo ( "> {0}" , versionsInfo . Status ) ;
162174
163175 Console . WriteLine ( ) ;
164176
165- // Author
177+ /*
178+ * Author info
179+ */
166180
167181 CliOutput . WriteInfo ( "Readme: {0}" , RuntimeInfo . Readme ) ;
168182 CliOutput . WriteInfo ( "Author: {0}" , RuntimeInfo . Author ) ;
@@ -253,7 +267,7 @@ static int FromDisplay(char c)
253267
254268 // Show options
255269 if ( multiple ) {
256- string optionsStr = Common . Join ( selectedOptions ) ;
270+ string optionsStr = CommonUtilities . Join ( selectedOptions ) ;
257271
258272
259273 CliOutput . WithColor ( ConsoleColor . Blue , ( ) =>
@@ -301,19 +315,28 @@ static int FromDisplay(char c)
301315 return selectedOptions ;
302316 }
303317
304- internal static void SelfDestruct ( )
318+ private static void SelfDestruct ( )
305319 {
320+
321+ // todo: optimize this
322+
306323 string batchCommands = string . Empty ;
307324 string exeFileName = RuntimeInfo . ExeLocation ;
308325 string batname = "SmartImage_Delete.bat" ;
309326
310- batchCommands += "@ECHO OFF\n " ; // Do not show any output
311327
312- batchCommands +=
313- "ping 127.0.0.1 > nul\n " ; // Wait approximately 4 seconds (so that the process is already terminated)
314- batchCommands += "echo y | del /F " ; // Delete the executable
328+ batchCommands += "@echo off\n " ;
329+
330+ /* Wait approximately 4 seconds (so that the process is already terminated) */
331+ batchCommands += "ping 127.0.0.1 > nul\n " ;
332+
333+ /* Delete executable */
334+ batchCommands += "echo y | del /F " ;
335+
315336 batchCommands += exeFileName + "\n " ;
316- batchCommands += "echo y | del " + batname ; // Delete this bat file
337+
338+ /* Delete this bat file */
339+ batchCommands += "echo y | del " + batname ;
317340
318341 var dir = Path . Combine ( Path . GetTempPath ( ) , batname ) ;
319342
@@ -351,7 +374,7 @@ internal static void RunCommandMenu()
351374 Console . Write ( "Image: " ) ;
352375
353376 string img = Console . ReadLine ( ) ;
354- img = Common . CleanString ( img ) ;
377+ img = CommonUtilities . CleanString ( img ) ;
355378
356379 SearchConfig . Config . Image = img ;
357380
@@ -367,7 +390,7 @@ internal static void RunCommandMenu()
367390 } ) ,
368391 new ConsoleOption ( "Reset all configuration" , ( ) =>
369392 {
370- RunReset ( OPT_ALL ) ;
393+ RunReset ( ) ;
371394
372395 Wait ( ) ;
373396 return null ;
@@ -377,11 +400,11 @@ internal static void RunCommandMenu()
377400 bool ctx = RuntimeInfo . IsContextMenuAdded ;
378401
379402 if ( ! ctx ) {
380- RunContextMenuIntegration ( OPT_ADD ) ;
403+ RunContextMenuIntegration ( IntegrationOption . Add ) ;
381404 CliOutput . WriteSuccess ( "Added to context menu" ) ;
382405 }
383406 else {
384- RunContextMenuIntegration ( OPT_REM ) ;
407+ RunContextMenuIntegration ( IntegrationOption . Remove ) ;
385408 CliOutput . WriteSuccess ( "Removed from context menu" ) ;
386409 }
387410
@@ -393,7 +416,7 @@ internal static void RunCommandMenu()
393416 var rgEnum = ConsoleOption . CreateOptionsFromEnum < SearchEngines > ( ) ;
394417 var values = HandleConsoleOptions ( rgEnum , true ) ;
395418
396- var newValues = Common . ReadEnumFromSet < SearchEngines > ( values ) ;
419+ var newValues = CommonUtilities . ReadEnumFromSet < SearchEngines > ( values ) ;
397420
398421 CliOutput . WriteInfo ( newValues ) ;
399422
@@ -408,7 +431,7 @@ internal static void RunCommandMenu()
408431 var rgEnum = ConsoleOption . CreateOptionsFromEnum < SearchEngines > ( ) ;
409432 var values = HandleConsoleOptions ( rgEnum , true ) ;
410433
411- var newValues = Common . ReadEnumFromSet < SearchEngines > ( values ) ;
434+ var newValues = CommonUtilities . ReadEnumFromSet < SearchEngines > ( values ) ;
412435
413436 CliOutput . WriteInfo ( newValues ) ;
414437
@@ -452,22 +475,22 @@ internal static void RunCommandMenu()
452475 {
453476 // TODO: WIP
454477
455- var v = VersionsInfo . Create ( ) ;
478+ var v = UpdateInfo . CheckForUpdates ( ) ;
456479
457480 if ( ( v . Status == VersionStatus . Available ) ) {
458- WebAgent . OpenUrl ( v . Latest . AssetUrl ) ;
481+ NetworkUtilities . OpenUrl ( v . Latest . AssetUrl ) ;
459482 }
460483
461484 Wait ( ) ;
462485 return null ;
463486 } ) ,
464487 new ConsoleOption ( "Uninstall" , ( ) =>
465488 {
466- RunReset ( OPT_ALL ) ;
467- RunContextMenuIntegration ( OPT_REM ) ;
468- RunPathIntegration ( OPT_REM ) ;
489+ RunReset ( ) ;
490+ RunContextMenuIntegration ( IntegrationOption . Remove ) ;
491+ RunPathIntegration ( IntegrationOption . Remove ) ;
469492
470- File . Delete ( RuntimeInfo . ConfigLocation ) ;
493+ File . Delete ( SearchConfig . ConfigLocation ) ;
471494 SelfDestruct ( ) ;
472495
473496 // No return
@@ -476,6 +499,7 @@ internal static void RunCommandMenu()
476499
477500 return null ;
478501 } ) ,
502+
479503 } ;
480504
481505 HandleConsoleOptions ( options ) ;
0 commit comments