Installer: Add registry-based context menus also to directory backgrounds
authorSebastian Schuberth <sschuberth@gmail.com>
Mon, 17 Dec 2012 21:22:33 +0000 (17 21:22 +0000)
committerSebastian Schuberth <sschuberth@gmail.com>
Thu, 17 Jan 2013 21:23:39 +0000 (17 22:23 +0100)
Do this for both "Git Bash Here" and "Git GUI Here" entries. Simplify the
code along the lines. Fixes issue #84.

Helped-by: Matt Hickford <matt.hickford@gmail.com>
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
share/WinGit/install.iss

index ffa06e4..838db90 100644 (file)
@@ -263,7 +263,8 @@ end;
 procedure DeleteContextMenuEntries;\r
 var\r
     AppDir,Command,Msg:String;\r
-    RootKey:Integer;\r
+    RootKey,i:Integer;\r
+    Keys:TArrayOfString;\r
 begin\r
     AppDir:=ExpandConstant('{app}');\r
 \r
@@ -273,27 +274,23 @@ begin
         RootKey:=HKEY_CURRENT_USER;\r
     end;\r
 \r
-    Command:='';\r
-    RegQueryStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell\command','',Command);\r
-    if Pos(AppDir,Command)>0 then begin\r
-        if not RegDeleteKeyIncludingSubkeys(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell') then begin\r
-            Msg:='Line {#__LINE__}: Unable to remove "Git Bash Here" shell extension.';\r
-            MsgBox(Msg,mbError,MB_OK);\r
-            Log(Msg);\r
-            // This is not a critical error, the user can probably fix it manually,\r
-            // so we continue.\r
-        end;\r
-    end;\r
-\r
-    Command:='';\r
-    RegQueryStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui\command','',Command);\r
-    if Pos(AppDir,Command)>0 then begin\r
-        if not RegDeleteKeyIncludingSubkeys(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui') then begin\r
-            Msg:='Line {#__LINE__}: Unable to remove "Git GUI Here" shell extension.';\r
-            MsgBox(Msg,mbError,MB_OK);\r
-            Log(Msg);\r
-            // This is not a critical error, the user can probably fix it manually,\r
-            // so we continue.\r
+    SetArrayLength(Keys,4);\r
+    Keys[0]:='SOFTWARE\Classes\Directory\shell\git_shell';\r
+    Keys[1]:='SOFTWARE\Classes\Directory\Background\shell\git_shell';\r
+    Keys[2]:='SOFTWARE\Classes\Directory\shell\git_gui';\r
+    Keys[3]:='SOFTWARE\Classes\Directory\Background\shell\git_gui';\r
+\r
+    for i:=0 to Length(Keys)-1 do begin\r
+        Command:='';\r
+        RegQueryStringValue(RootKey,Keys[i]+'\command','',Command);\r
+        if Pos(AppDir,Command)>0 then begin\r
+            if not RegDeleteKeyIncludingSubkeys(RootKey,Keys[i]) then begin\r
+                Msg:='Line {#__LINE__}: Unable to remove "Git Bash / GUI Here" shell extension.';\r
+                MsgBox(Msg,mbError,MB_OK);\r
+                Log(Msg);\r
+                // This is not a critical error, the user can probably fix it manually,\r
+                // so we continue.\r
+            end;\r
         end;\r
     end;\r
 end;\r
@@ -1164,8 +1161,12 @@ begin
     end;\r
 \r
     if IsComponentSelected('ext\reg\shellhere') then begin\r
-        if (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell','','Git Ba&sh Here')) or\r
-           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell\command','','"'+ExpandConstant('{syswow64}')+'\wscript" "'+AppDir+'\Git Bash.vbs" "%1"')) then begin\r
+        Msg:='Git Ba&sh Here';\r
+        Cmd:='"'+ExpandConstant('{syswow64}')+'\wscript" "'+AppDir+'\Git Bash.vbs" "%v"';\r
+        if (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell','',Msg)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell\command','',Cmd)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\Background\shell\git_shell','',Msg)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\Background\shell\git_shell\command','',Cmd)) then begin\r
             Msg:='Line {#__LINE__}: Unable to create "Git Bash Here" shell extension.';\r
             MsgBox(Msg,mbError,MB_OK);\r
             Log(Msg);\r
@@ -1175,8 +1176,12 @@ begin
     end;\r
 \r
     if IsComponentSelected('ext\reg\guihere') then begin\r
-        if (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui','','Git &GUI Here')) or\r
-           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui\command','','"'+AppDir+'\bin\wish.exe" "'+AppDir+'\libexec\git-core\git-gui" "--working-dir" "%1"')) then begin\r
+        Msg:='Git &GUI Here';\r
+        Cmd:='"'+AppDir+'\bin\wish.exe" "'+AppDir+'\libexec\git-core\git-gui" "--working-dir" "%v"';\r
+        if (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui','',Msg)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui\command','',Cmd)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\Background\shell\git_gui','',Msg)) or\r
+           (not RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\Background\shell\git_gui\command','',Cmd)) then begin\r
             Msg:='Line {#__LINE__}: Unable to create "Git GUI Here" shell extension.';\r
             MsgBox(Msg,mbError,MB_OK);\r
             Log(Msg);\r