From da254a80cf17555e650774530f3cb9ac464a6551 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 24 Aug 2014 10:51:47 +0100 Subject: [PATCH 1/2] [GTKUI] Add associate magnet reg in Windows --- deluge/ui/gtkui/common.py | 26 +++++++++++++++++++++++++- win32/deluge-win32-installer.nsi | 8 ++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index f51747a77..6022d857e 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -156,7 +156,31 @@ def associate_magnet_links(overwrite=False): Returns: bool: True if association was set """ - if not deluge.common.windows_check(): + + if deluge.common.windows_check(): + import _winreg + + try: + hkey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "Magnet") + except WindowsError: + overwrite = True + finally: + _winreg.CloseKey(hkey) + + if overwrite: + _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Magnet") + magnet_key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "Magnet", 0, _winreg.KEY_WRITE) + _winreg.SetValue(magnet_key, "", _winreg.REG_SZ, "URL:Magnet Protocol") + _winreg.SetValue(magnet_key, "URL Protocol", _winreg.REG_SZ, "") + _winreg.SetValue(magnet_key, "DefaultIcon", _winreg.REG_SZ, "") + _winreg.SetValue(magnet_key + "/DefaultIcon", "", _winreg.REG_SZ, "deluge.exe,1") + _winreg.SetValue(magnet_key, "shell\open\command", _winreg.REG_SZ, "") + ## need to find current running dir: os.path.dirname(os.path.realpath(__file__)) + _winreg.SetValue(magnet_key + "\shell\open\command", "", _winreg.REG_SZ, "C:\Program Files\Deluge\deluge.exe" "%1") + _winreg.CloseKey(magnet_key) + + # Don't try associate magnet on OSX see: #2420 + elif not deluge.common.osx_check(): # gconf method is only available in a GNOME environment try: import gconf diff --git a/win32/deluge-win32-installer.nsi b/win32/deluge-win32-installer.nsi index 247152773..c01b58ccb 100644 --- a/win32/deluge-win32-installer.nsi +++ b/win32/deluge-win32-installer.nsi @@ -182,11 +182,11 @@ SectionEnd # Create magnet uri association Section "Create magnet uri link association for Deluge" Section3 - DeleteRegKey HKCR "magnet" - WriteRegStr HKCR "magnet" "" "URL:magnet protocol" - WriteRegStr HKCR "magnet" "URL Protocol" "" + DeleteRegKey HKCR "Magnet" + WriteRegStr HKCR "Magnet" "" "URL:Magnet Protocol" + WriteRegStr HKCR "Magnet" "URL Protocol" "" - WriteRegStr HKCR "magnet\shell\open\command" "" '"$INSTDIR\deluge.exe" "%1"' + WriteRegStr HKCR "Magnet\shell\open\command" "" '"$INSTDIR\deluge.exe" "%1"' SectionEnd From 14ee13bdd4e9b1e3a10186ef4cc65dc707848331 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Tue, 23 Sep 2014 20:02:16 -0400 Subject: [PATCH 2/2] [GTKUI] Fix magnet association button on Windows --- ChangeLog | 1 + deluge/ui/gtkui/common.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9124bc99..36f060ec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,7 @@ * #378: Allow showing a pieces bar instead of a regular progress bar in a torrent's status tab. * #2093: Make torrent opening compatible with all unicode paths. + * #1084: Fix magnet association button on Windows ==== WebUI ==== * Server (deluge-web) now daemonizes by default, use -d or --do-not-daemonize to disable. diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index 6022d857e..240f0163e 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -12,6 +12,7 @@ import os import logging import cPickle import shutil +import sys import pygtk pygtk.require('2.0') @@ -164,19 +165,17 @@ def associate_magnet_links(overwrite=False): hkey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "Magnet") except WindowsError: overwrite = True - finally: + else: _winreg.CloseKey(hkey) if overwrite: - _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Magnet") - magnet_key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "Magnet", 0, _winreg.KEY_WRITE) + deluge_exe = os.path.join(os.path.dirname(sys.executable), "deluge.exe") + magnet_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Magnet") _winreg.SetValue(magnet_key, "", _winreg.REG_SZ, "URL:Magnet Protocol") - _winreg.SetValue(magnet_key, "URL Protocol", _winreg.REG_SZ, "") - _winreg.SetValue(magnet_key, "DefaultIcon", _winreg.REG_SZ, "") - _winreg.SetValue(magnet_key + "/DefaultIcon", "", _winreg.REG_SZ, "deluge.exe,1") - _winreg.SetValue(magnet_key, "shell\open\command", _winreg.REG_SZ, "") - ## need to find current running dir: os.path.dirname(os.path.realpath(__file__)) - _winreg.SetValue(magnet_key + "\shell\open\command", "", _winreg.REG_SZ, "C:\Program Files\Deluge\deluge.exe" "%1") + _winreg.SetValueEx(magnet_key, "URL Protocol", 0, _winreg.REG_SZ, "") + _winreg.SetValueEx(magnet_key, "BrowserFlags", 0, _winreg.REG_DWORD, 0x8) + _winreg.SetValue(magnet_key, "DefaultIcon", _winreg.REG_SZ, "{},0".format(deluge_exe)) + _winreg.SetValue(magnet_key, r"shell\open\command", _winreg.REG_SZ, '"{}" "%1"'.format(deluge_exe)) _winreg.CloseKey(magnet_key) # Don't try associate magnet on OSX see: #2420