Commits

Anonymous committed 959fb18

tortoise: revise registry handling for TortoiseOverlays.dll

implementation adapted from TortoiseBzr

Comments (0)

Files changed (3)

tortoise/contextmenu.py

         ]
 
     registry_keys = [
-        (_winreg.HKEY_CLASSES_ROOT, r"*\shellex\ContextMenuHandlers\TortoiseHg"),
-        (_winreg.HKEY_CLASSES_ROOT, r"Directory\Background\shellex\ContextMenuHandlers\TortoiseHg"),
-        (_winreg.HKEY_CLASSES_ROOT, r"Directory\shellex\ContextMenuHandlers\TortoiseHg"),
-        (_winreg.HKEY_CLASSES_ROOT, r"Folder\shellex\ContextMenuHandlers\TortoiseHg"),
-        (_winreg.HKEY_CLASSES_ROOT, r"Directory\shellex\DragDropHandlers\TortoiseHg"),
-        (_winreg.HKEY_CLASSES_ROOT, r"Folder\shellex\DragDropHandlers\TortoiseHg"),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"*\shellex\ContextMenuHandlers\TortoiseHg", 
+         [(None, _reg_clsid_)]),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"Directory\Background\shellex\ContextMenuHandlers\TortoiseHg",
+         [(None, _reg_clsid_)]),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"Directory\shellex\ContextMenuHandlers\TortoiseHg",
+         [(None, _reg_clsid_)]),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"Folder\shellex\ContextMenuHandlers\TortoiseHg",
+         [(None, _reg_clsid_)]),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"Directory\shellex\DragDropHandlers\TortoiseHg",
+         [(None, _reg_clsid_)]),
+        (_winreg.HKEY_CLASSES_ROOT,
+         r"Folder\shellex\DragDropHandlers\TortoiseHg",
+         [(None, _reg_clsid_)]),
         ]
 
     def __init__(self):

tortoise/iconoverlay.py

     prog_id = "Mercurial.ShellExtension.%s" % classname
     desc = "Mercurial icon overlay shell extension for %s files" % name.lower()
     reg = [
-        (_winreg.HKEY_LOCAL_MACHINE, r"Software\TortoiseOverlays\%s" % icon_type) ]
+            (_winreg.HKEY_LOCAL_MACHINE,
+             r"Software\TortoiseOverlays\%s" % icon_type,
+             [("TortoiseHg", clsid)])
+        ]
     cls = type(
             classname,
             (IconOverlayExtension, ),
 bin_path = os.path.dirname(os.path.join(os.getcwd(), sys.argv[0]))
 print "bin path = ", bin_path
 
+def check_tortoise_overlays():
+    # TortoiseOverlays must be installed, and we must be able to write there.
+    try:
+        hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
+                               r"Software\TortoiseOverlays", 0,
+                               _winreg.KEY_ALL_ACCESS)
+    except WindowsError:
+        print "TortoiseOverlays is not installed."
+        sys.exit(1)
+
 # TortoiseHg registry setup
 def register_tortoise_path(unregister=False):
     key = r"Software\TortoiseHg"
 
 # for COM registration via py2exe
 def DllRegisterServer():
+    check_tortoise_overlays()
     RegisterServer(ContextMenuExtension)
     RegisterServer(ChangedOverlay)
     RegisterServer(AddedOverlay)
         pass
         
     # Add the appropriate shell extension registry keys
-    for category, keyname in cls.registry_keys: 
-        _winreg.SetValue(category, keyname, _winreg.REG_SZ, cls._reg_clsid_)
+    for category, keyname, values in cls.registry_keys:
+        hkey = _winreg.CreateKey(category, keyname)
+        for (name, val) in values:
+            # todo: handle ints?
+            _winreg.SetValueEx(hkey, name, 0, _winreg.REG_SZ, val)
         
     # register the extension on Approved list
     try:
     print cls._reg_desc_, "registration complete."
 
 def UnregisterServer(cls):
-    for category, keyname in cls.registry_keys:
-        try:
-            _winreg.DeleteKey(category, keyname)
-        except WindowsError, details:
-            import errno
-            if details.errno != errno.ENOENT:
-                raise
+    for category, keyname, values in cls.registry_keys:
+        hkey = _winreg.OpenKey(category, keyname, 0, _winreg.KEY_ALL_ACCESS)
+        for (name, val) in values:
+            # todo: handle ints?
+            try:
+                _winreg.DeleteValue(hkey, name)
+            except WindowsError, exc:
+                print "Failed to remove registry key %s: %s" % (keyname, exc)
 
     # unregister the extension from Approved list
     try:
     print cls._reg_desc_, "unregistration complete."
 
 if __name__=='__main__':
+    check_tortoise_overlays()
+
     from win32com.server import register
     register.UseCommandLine(ContextMenuExtension,
             finalize_register = lambda: RegisterServer(ContextMenuExtension),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.