@@ -30,25 +30,26 @@ internal static void HandleContextMenu(IntegrationOption option)
3030 case IntegrationOption . Add :
3131 string fullPath = RuntimeInfo . ExeLocation ;
3232
33- if ( ! RuntimeInfo . IsExeInAppFolder ) {
34- bool v = CliOutput . ReadConfirm ( "Could not find exe in system path. Add now?" ) ;
33+ // Add command and icon to command
34+ string [ ] commandCode =
35+ {
36+ "@echo off" ,
37+ $ "reg.exe add { REG_SHELL_CMD } /ve /d \" { fullPath } \" \" %%1\" \" \" /f >nul",
38+ $ "reg.exe add { REG_SHELL } /v Icon /d \" { fullPath } \" /f >nul"
39+ } ;
3540
36- if ( v ) {
37- Setup ( ) ;
38- return ;
39- }
40- }
41-
42-
43- RegistrySubKey . SetValue ( "Icon" , fullPath ) ;
44-
45- var cmd = RegistrySubKey . CreateSubKey ( "command" ) ;
46- cmd . SetValue ( null , String . Format ( "\" {0}\" \" %1\" " , fullPath ) ) ;
41+ Cli . CreateRunBatchFile ( "add_to_menu.bat" , commandCode ) ;
4742
4843 break ;
4944 case IntegrationOption . Remove :
5045
51- Registry . CurrentUser . DeleteSubKeyTree ( REG_HKCU_SHELL_SMARTIMAGE ) ;
46+ string [ ] code =
47+ {
48+ "@echo off" ,
49+ $@ "reg.exe delete { REG_SHELL } /f >nul"
50+ } ;
51+
52+ Cli . CreateRunBatchFile ( "rem_from_menu.bat" , code ) ;
5253
5354 break ;
5455 default :
@@ -88,53 +89,6 @@ internal static void HandlePath(IntegrationOption option)
8889 }
8990 }
9091
91- /// <summary>
92- /// Remove old legacy registry integrations
93- /// </summary>
94- internal static void RemoveOldRegistry ( )
95- {
96- const string REG_SHELL_LEGACY = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\" ;
97-
98- const string REG_SHELL_CMD_LEGACY = @"HKEY_CLASSES_ROOT\*\shell\SmartImage\command" ;
99-
100- bool added = IsAdded ( ) ;
101-
102- if ( added ) {
103- Remove ( ) ;
104- }
105- else {
106- return ;
107- }
108-
109- bool success = ! IsAdded ( ) ;
110-
111-
112- static void Remove ( )
113- {
114- string [ ] code =
115- {
116- "@echo off" ,
117- $@ "reg.exe delete { REG_SHELL_LEGACY } /f >nul"
118- } ;
119-
120- Cli . CreateRunBatchFile ( "rem_from_menu.bat" , code ) ;
121- }
122-
123- static bool IsAdded ( )
124- {
125- string cmdStr = String . Format ( @"reg query {0}" , REG_SHELL_CMD_LEGACY ) ;
126- var cmd = Cli . Shell ( cmdStr , true ) ;
127-
128- string [ ] stdOut = Cli . ReadAllLines ( cmd . StandardOutput ) ;
129-
130- bool b = stdOut . Any ( s => s . Contains ( RuntimeInfo . NAME ) ) ;
131- return b ;
132- }
133-
134- if ( ! success ) {
135- throw new SmartImageException ( ) ;
136- }
137- }
13892
13993 internal static void ResetIntegrations ( )
14094 {
@@ -182,23 +136,27 @@ internal static void Uninstall()
182136
183137 File . WriteAllText ( dir , commands . QuickJoin ( "\n " ) ) ;
184138
185-
139+
186140 // Runs in background
187141 Process . Start ( dir ) ;
188142 }
189143
190- private const string REG_HKCU_SHELL_ROOT = @"Software\Classes\ *\shell\" ;
144+ private const string REG_SHELL = @"HKEY_CLASSES_ROOT\ *\shell\SmartImage \" ;
191145
192- private const string REG_HKCU_SHELL_SMARTIMAGE = REG_HKCU_SHELL_ROOT + @" SmartImage\";
146+ private const string REG_SHELL_CMD = @"HKEY_CLASSES_ROOT\*\shell\ SmartImage\command ";
193147
194- internal static RegistryKey RegistrySubKey => Registry . CurrentUser . CreateSubKey ( REG_HKCU_SHELL_SMARTIMAGE ) ;
195148
196149 internal static bool IsContextMenuAdded
197150 {
198151 get
199152 {
200- var shell = Registry . CurrentUser . OpenSubKey ( REG_HKCU_SHELL_ROOT ) ! ;
201- return shell . GetSubKeyNames ( ) . Contains ( RuntimeInfo . NAME ) ;
153+ string cmdStr = String . Format ( @"reg query {0}" , REG_SHELL_CMD ) ;
154+ var cmd = Cli . Shell ( cmdStr , true ) ;
155+
156+ string [ ] stdOut = Cli . ReadAllLines ( cmd . StandardOutput ) ;
157+
158+ bool b = stdOut . Any ( s => s . Contains ( RuntimeInfo . NAME ) ) ;
159+ return b ;
202160 }
203161 }
204162
0 commit comments