-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlauncher.py
More file actions
59 lines (46 loc) · 1.63 KB
/
launcher.py
File metadata and controls
59 lines (46 loc) · 1.63 KB
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
"""Entry point for the installed executable.
Portable executables bypass this file.
"""
import ctypes
import sys
import subprocess
from mousetracks2.context import CTX
from mousetracks2.utils.update import get_local_executables
from mousetracks2.sign import verify_signature
MB_ICONERROR = 0x10
def show_error(title: str, message: str) -> None:
"""Displays an error message box.
Currently only supports Windows.
"""
ctypes.windll.user32.MessageBoxW(0, message, title, MB_ICONERROR)
def main() -> None:
# Build an ordered list of available executables
lower, current, higher = get_local_executables(CTX.executable_dir)
executables = list(lower)
if current is not None:
executables.append(current)
executables.extend(higher)
# Get the latest version that passes the signature verification
try:
executable = next(filter(verify_signature, reversed(executables)))
except StopIteration:
show_error('Launch Error',
'No valid version of MouseTracks found in the installation folder.\n\n'
'Please reinstall the application.')
sys.exit(1)
print(f'Launching {executable}...')
# Start the child process
cmd = [str(executable)]
if '--installed' not in sys.argv:
cmd.append('--installed')
cmd.extend(sys.argv[1:])
try:
exit_code = subprocess.call(cmd, cwd=str(CTX.executable_dir))
sys.exit(exit_code)
except KeyboardInterrupt:
sys.exit(1)
except OSError as e:
show_error('Launch Error', f'Failed to start application:\n{e}')
sys.exit(1)
if __name__ == "__main__":
main()