diff --git a/packaging/uri_handler/LBRYURIRegistry.py b/packaging/uri_handler/LBRYURIRegistry.py new file mode 100644 index 000000000..4848e0c46 --- /dev/null +++ b/packaging/uri_handler/LBRYURIRegistry.py @@ -0,0 +1,54 @@ +import _winreg as winreg +import os +import sys + +import win32con +import win32gui + + +def main(): + try: + install = 'remove' not in sys.argv[1] + except: + install = True + lbry_path = os.path.join(os.environ["ProgramFiles"], "LBRY", "LBRY.exe") + + key_url = 'lbry' + try: + key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_url, 0, winreg.KEY_ALL_ACCESS) + except: + key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_url) + if install: + winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "URL:LBRY Protocol") + winreg.SetValueEx(key, "URL Protocol", 0, winreg.REG_SZ, "") + else: + winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_url) + + winreg.CloseKey(key) + + key_icon = os.path.join('lbry', 'DefaultIcon') + try: + key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_icon, 0, winreg.KEY_ALL_ACCESS) + except: + key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_icon) + if install: + winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"LBRY.exe,1\"") + else: + winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_icon) + winreg.CloseKey(key) + + key_command = os.path.join('lbry', 'shell', 'open', 'command') + try: + key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, key_command, 0, winreg.KEY_ALL_ACCESS) + except: + key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, key_command) + if install: + winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"{0}\" \"%1\"".format(lbry_path)) + else: + winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_command) + winreg.CloseKey(key) + + win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment') + +if __name__ == "__main__": + main() diff --git a/packaging/windows/lbry-win32-app/LBRY-URI.reg b/packaging/windows/lbry-win32-app/LBRY-URI.reg index 29d849885..b759f641b 100644 --- a/packaging/windows/lbry-win32-app/LBRY-URI.reg +++ b/packaging/windows/lbry-win32-app/LBRY-URI.reg @@ -5,7 +5,7 @@ Windows Registry Editor Version 5.00 "URL Protocol"="" [HKEY_CLASSES_ROOT\lbry\DefaultIcon] -@="LBRY.exe,1" +@="\"LBRY.exe,1\"" [HKEY_CLASSES_ROOT\lbry\shell] diff --git a/packaging/windows/lbry-win32-app/LBRYWin32App.py b/packaging/windows/lbry-win32-app/LBRYWin32App.py index 6120e1804..bb47a707a 100644 --- a/packaging/windows/lbry-win32-app/LBRYWin32App.py +++ b/packaging/windows/lbry-win32-app/LBRYWin32App.py @@ -11,6 +11,7 @@ import win32gui_struct from jsonrpc.proxy import JSONRPCProxy from twisted.internet import reactor, error from twisted.web import server +import twisted try: import winxpgui as win32gui @@ -19,15 +20,21 @@ except ImportError: from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME -from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING +from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING, LOG_FILE_NAME from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler +# TODO: omg, this code is essentially duplicated in LBRYDaemon +data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet") +if not os.path.isdir(data_dir): + os.mkdir(data_dir) + +lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME) +log = logging.getLogger(__name__) + if getattr(sys, 'frozen', False) and os.name == "nt": os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem") -log = logging.getLogger(__name__) - REMOTE_SERVER = "www.google.com" @@ -282,7 +289,11 @@ def main(lbry_name=None): d.addCallback(lambda _: LBRYURIHandler.open_address(lbry_name)) lbrynet_server = server.Site(lbry.root) lbrynet_server.requestFactory = LBRYDaemonRequest - reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) + try: + reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) + except error.CannotListenError: + log.info('Daemon already running, exiting app') + sys.exit(1) reactor.run() if __name__ == '__main__': @@ -298,7 +309,7 @@ if __name__ == '__main__': lbry_name = LBRYURIHandler.parse_name(sys.argv[1]) except IndexError: lbry_name = None - + start_daemon = True if start_daemon: main(lbry_name) else: diff --git a/setup.py b/setup.py index 35a97bbab..9224af09c 100644 --- a/setup.py +++ b/setup.py @@ -124,7 +124,9 @@ elif platform == WINDOWS: from cx_Freeze import setup, Executable import requests.certs - win_icon = os.path.join('packaging', 'windows', 'lbry-win32-app', 'icons', 'lbry256.ico') + app_dir = os.path.join('packaging', 'windows', 'lbry-win32-app') + daemon_dir = os.path.join('lbrynet', 'lbrynet_daemon') + win_icon = os.path.join(app_dir, 'icons', 'lbry256.ico') wordlist_path = pkg_resources.resource_filename('lbryum', 'wordlist') # Allow virtualenv to find distutils of base python installation @@ -140,26 +142,8 @@ elif platform == WINDOWS: data_dir = os.path.dirname(__file__) return os.path.join(data_dir, filename) - if os.path.isdir("C:\Program Files (x86)"): - shortcut_icon = 'C:\Program Files (x86)\lbrynet\icons\lbry256.ico' - else: - shortcut_icon = 'C:\Program Files\lbrynet\icons\lbry256.ico' - shortcut_table = [ - ('DesktopShortcut', # Shortcut - 'DesktopFolder', # Directory - 'lbrynet-daemon', # Name - 'TARGETDIR', # Component - '[TARGETDIR]\lbrynet-daemon.exe', # Target - '--log-to-console', # Arguments - description, # Description - None, # Hotkey - shortcut_icon, # Icon - None, # IconIndex - None, # ShowCmd - 'TARGETDIR', # WkDir - ), - ('DaemonShortcut', # Shortcut + ('LBRYShortcut', # Shortcut 'DesktopFolder', # Directory 'LBRY', # Name 'TARGETDIR', # Component @@ -167,7 +151,20 @@ elif platform == WINDOWS: None, # Arguments description, # Description None, # Hotkey - shortcut_icon, # Icon + None, # Icon + None, # IconIndex + None, # ShowCmd + 'TARGETDIR', # WkDir + ), + ('DaemonShortcut', # Shortcut + 'DesktopFolder', # Directory + 'lbrynet-daemon', # Name + 'TARGETDIR', # Component + '[TARGETDIR]\lbrynet-daemon.exe', # Target + '--log-to-console', # Arguments + description, # Description + None, # Hotkey + None, # Icon None, # IconIndex None, # ShowCmd 'TARGETDIR', # WkDir @@ -180,7 +177,49 @@ elif platform == WINDOWS: None, # Arguments description, # Description None, # Hotkey - shortcut_icon, # Icon + None, # Icon + None, # IconIndex + None, # ShowCmd + 'TARGETDIR', # WkDir + ), + ('ProgramMenuLBRYShortcut', # Shortcut + 'ProgramMenuFolder', # Directory + # r'[ProgramMenuFolder]\lbrynet', # Directory + 'LBRY', # Name + 'TARGETDIR', # Component + '[TARGETDIR]\{0}.exe'.format(dist_name), # Target + None, # Arguments + description, # Description + None, # Hotkey + None, # Icon + None, # IconIndex + None, # ShowCmd + 'TARGETDIR', # WkDir + ), + ('ProgramMenuDaemonShortcut', # Shortcut + 'ProgramMenuFolder', # Directory + # r'[ProgramMenuFolder]\lbrynet', # Directory + 'lbrynet-daemon', # Name + 'TARGETDIR', # Component + '[TARGETDIR]\lbrynet-daemon.exe', # Target + '--log-to-console', # Arguments + description, # Description + None, # Hotkey + None, # Icon + None, # IconIndex + None, # ShowCmd + 'TARGETDIR', # WkDir + ), + ('ProgramMenuDaemonCLIShortcut', # Shortcut + 'ProgramMenuFolder', # Directory + # r'[ProgramMenuFolder]\lbrynet', # Directory + 'lbrynet-cli', # Name + 'TARGETDIR', # Component + '[TARGETDIR]\lbrynet-cli.exe', # Target + None, # Arguments + description, # Description + None, # Hotkey + None, # Icon None, # IconIndex None, # ShowCmd 'TARGETDIR', # WkDir @@ -240,10 +279,8 @@ elif platform == WINDOWS: 'Tkinter', 'tk', 'tcl', 'PyQt4', 'nose', 'mock' 'zope.interface._zope_interface_coptimizations', 'leveldb'], 'include_files': [(distutils_path, 'distutils'), (requests.certs.where(), 'cacert.pem'), - (os.path.join('packaging', 'windows', 'lbry-win32-app', 'icons', 'lbry16.ico'), - os.path.join('icons', 'lbry16.ico')), - (os.path.join('packaging', 'windows', 'lbry-win32-app', 'icons', 'lbry256.ico'), - os.path.join('icons', 'lbry256.ico')), + (os.path.join(app_dir, 'icons', 'lbry16.ico'), os.path.join('icons', 'lbry16.ico')), + (os.path.join(app_dir, 'icons', 'lbry256.ico'), os.path.join('icons', 'lbry256.ico')), (os.path.join(wordlist_path, 'chinese_simplified.txt'), os.path.join('wordlist', 'chinese_simplified.txt')), (os.path.join(wordlist_path, 'english.txt'), os.path.join('wordlist', 'english.txt')), @@ -254,30 +291,28 @@ elif platform == WINDOWS: 'namespace_packages': ['zope', 'google']} tray_app = Executable( - script=os.path.join('packaging', 'windows', 'lbry-win32-app', 'LBRYWin32App.py'), + script=os.path.join(app_dir, 'LBRYWin32App.py'), base='Win32GUI', icon=win_icon, compress=True, - shortcutName=dist_name, - shortcutDir='DesktopFolder', + # shortcutName=dist_name, + # shortcutDir='DesktopFolder', targetName='{0}.exe'.format(dist_name) - # targetDir="LocalAppDataFolder" ) - daemon_dir = os.path.join('lbrynet', 'lbrynet_daemon') daemon_exe = Executable( script=os.path.join(daemon_dir, 'LBRYDaemonControl.py'), icon=win_icon, - shortcutName="lbrynet-daemon", - shortcutDir='DesktopFolder', + # shortcutName="lbrynet-daemon", + # shortcutDir='DesktopFolder', targetName='lbrynet-daemon.exe' ) cli_exe = Executable( script=os.path.join(daemon_dir, 'LBRYDaemonCLI.py'), icon=win_icon, - shortcutName="lbrynet-cli", - shortcutDir='DesktopFolder', + # shortcutName="lbrynet-cli", + # shortcutDir='DesktopFolder', targetName='lbrynet-cli.exe' )