lbry-sdk/packaging/uri_handler/LBRYURIRegistry.py

55 lines
1.7 KiB
Python
Raw Normal View History

2016-08-28 20:33:46 +02:00
import _winreg as winreg
import os
2016-09-02 22:04:27 +02:00
import sys
import win32con
import win32gui
2016-08-28 20:33:46 +02:00
def main():
2016-09-02 22:04:27 +02:00
try:
install = 'remove' not in sys.argv[1]
except:
install = True
2016-08-28 20:33:46 +02:00
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)
2016-09-02 22:04:27 +02:00
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)
2016-08-28 20:33:46 +02:00
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)
2016-09-02 22:04:27 +02:00
if install:
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"LBRY.exe,1\"")
else:
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_icon)
2016-08-28 20:33:46 +02:00
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)
2016-09-02 22:04:27 +02:00
if install:
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "\"{0}\" \"%1\"".format(lbry_path))
else:
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, key_command)
2016-08-28 20:33:46 +02:00
winreg.CloseKey(key)
2016-09-02 22:04:27 +02:00
win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')
2016-08-28 20:33:46 +02:00
if __name__ == "__main__":
main()