-
Notifications
You must be signed in to change notification settings - Fork 3
/
installAddon.py
34 lines (30 loc) · 1.13 KB
/
installAddon.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
import ctypes
import pathlib
import sys
from buildVars import addon_info
def createSymlink(srcDir, instDir):
if not isAdmin():
if sys.version_info.major == 3 and sys.version_info.minor < 8:
print("This script cannot be run on versions of python less than 3.8 without administrator privileges")
sys.exit()
try:
instDir.symlink_to(srcDir, target_is_directory=True)
except WindowsError as e:
if e.winerror == 1314:
print("You will need to enable developer mode on your system to run this script")
def isAdmin():
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
return is_admin
def main():
addonName = addon_info["addon_name"]
srcDir = pathlib.Path().absolute() / "addon"
instDir = pathlib.Path.home() / f"appdata/roaming/nvda/addons/{addonName}"
if instDir.exists() and instDir.is_symlink():
ans = input(f"{addonName} is already installed. Do you want to remove it from NVDA?")
if ans.lower() == "y":
instDir.unlink()
sys.exit()
else:
createSymlink(srcDir, instDir)
if __name__ == "__main__":
main()