forked from woodruffw/ff2mpv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-config-win.py
64 lines (50 loc) · 1.74 KB
/
check-config-win.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env/python3
"""
A Python script that attempts to check that the configuration of your
nativeMessaging app is set up correctly
Currently requires Python 3.
If you find more issues with setting this up, let's see if we can add to this
script.
"""
import json
import os
import winreg
key_path = "Software\\Mozilla\\NativeMessagingHosts\\ff2mpv"
# Assuming current user overrides local machine.
key_roots = ["HKEY_CURRENT_USER", "HKEY_LOCAL_MACHINE"]
found_key = False
for root in key_roots:
key = winreg.OpenKey(getattr(winreg, root), key_path)
try:
print("Checking:", root, key_path)
res = winreg.QueryValueEx(key, "")
except FileNotFoundError:
print("...error finding key")
continue
found_key = True
break
if not found_key:
raise ValueError("Could not find a registry entry, aborting.")
json_path = res[0]
print("Path from registry key is:", json_path)
if not os.path.exists(json_path):
raise ValueError("JSON file does not exist:", json_path)
try:
bat_data = json.load(open(json_path, "r"))
except json.decoder.JSONDecodeError:
raise ValueError("Parsing error. Is {} a JSON file?".format(json_path))
bat_path = bat_data["path"]
print("Path from JSON is:", bat_path)
if not os.path.exists(bat_path):
raise ValueError(".bat does not exist:", bat_path)
py_lines = open(bat_path, "r").readlines()
py_path = None
for line in py_lines:
if line.startswith("call python "):
py_path = line[12:].replace("\\\\", "\\").strip()
if not py_path:
raise ValueError("No python script in the batch file.")
print("Path from batch file is:", py_path)
if not os.path.exists(py_path):
raise ValueError("Python file does not exist:", py_path)
print("Looks good! Give it a try from Firefox.")