-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.py
104 lines (84 loc) · 3.74 KB
/
installer.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import subprocess
from glob import glob
def env_error():
with open('errors.txt', 'w') as log:
log.write('''Local App Data Enviornment Variable Not Found. \n
Please place your chrome intsall directory in the config.txt file.''')
def plexamp_dir_error():
with open('errors.txt', 'w') as log:
log.write('Plexamp directory not found.\n Please update your plex directory in the config.txt file.')
def default_plexamp_dir():
try:
local_app_data = os.environ.get('LOCALAPPDATA')
except KeyError:
env_error()
return False
plexamp_dir = os.path.join(local_app_data,'Programs','plexamp')
if not os.path.exists(plexamp_dir):
return False
return plexamp_dir
def check_dir(path):
if not os.path.exists(path):
plexamp_dir_error()
return False
return True
def plexamp_config():
if not os.path.exists('config'):
with open('config.txt' ,'w') as config:
config.write('Chrome=\n')
config.write('Plexamp=\n')
with open('config.txt', 'r') as config:
paths = config.readlines()
plexamp_dir = ''
chrome_dir = ''
for path in paths:
if 'Plexamp' in path:
plexamp_dir = path[path.find('=')+1:].strip()
if 'Chrome' in path:
chrome_dir = path[path.find('=')+1:].strip()
with open('config.txt', 'w') as config:
config.write('Chrome=%s\n'%chrome_dir)
config.write('Plexamp=%s\n'%plexamp_dir)
return plexamp_dir
def main():
plexamp_dir = plexamp_config()
if not bool(plexamp_dir):
plexamp_dir = default_plexamp_dir()
plexamp_dir = os.path.join(plexamp_dir,'Plexamp.exe')
if not check_dir(plexamp_dir):
return
current_path = os.path.abspath(os.getcwd())
if len(glob(os.path.join(current_path,'*.py'))) > 0:
fix_keys = os.path.join(current_path,'update_chrome_files.py')
with open('launch.bat', 'w') as launcher:
launcher.write('python %s start\n'%fix_keys)
launcher.write('start /b /wait "" %s\n'%plexamp_dir)
launcher.write('python %s close'%fix_keys)
else:
fix_keys = os.path.join(current_path,'update_chrome_files.exe')
with open('launch.bat', 'w') as launcher:
launcher.write('start /b /wait %s start\n'%fix_keys)
launcher.write('start /b /wait "" %s\n'%plexamp_dir)
launcher.write('start /b /wait %s close'%fix_keys)
with open('Plexamp (Media Key Fix).vbs', 'w') as vbs:
vbs.write('Set oShell = CreateObject ("Wscript.Shell")\n')
vbs.write('Dim StrArgs\n')
bat = os.path.join(current_path,'launch.bat')
vbs.write('StrArgs = "cmd /c %s"\n'%bat)
vbs.write('oShell.Run strArgs, 0, false')
shortcut_link = os.path.join(current_path,'Plexamp (Media Key Fix).vbs')
with open('make_shortcut.vbs', 'w') as short:
short.write('Set WshShell = CreateObject("Wscript.shell")\n')
short.write('strDesktop = WshShell.SpecialFolders("Desktop")\n')
short.write('set oMyShortcut = WshShell.CreateShortcut(strDesktop & "\\Plexamp (Media Key Fix).lnk")\n')
short.write('oMyShortcut.WindowStyle = 1\n')
short.write('oMyShortcut.IconLocation = "%s,0"\n'%plexamp_dir)
short.write('oMyShortcut.TargetPath = "%s"\n'%shortcut_link)
short.write('oMyShortcut.Description = "Shortcut to the Streamkeys Plexamp Fix"\n')
short.write('oMyShortcut.WorkingDirectory = "%s"\n'%current_path)
short.write('oMyShortcut.Save')
subprocess.call('cmd /c make_shortcut.vbs')
os.remove('make_shortcut.vbs')
if __name__ == '__main__':
main()