-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskless_games_updater.py
99 lines (82 loc) · 2.94 KB
/
diskless_games_updater.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
import logging
from subprocess import Popen
from win32 import win32gui
from win32 import win32process
from win32con import SW_MINIMIZE
from time import sleep
from psutil import process_iter
from sys import stdout
from os import system
logging.basicConfig(level=logging.INFO,format='%(asctime)s %(levelname)-8s %(message)s')
logger = logging.getLogger(__name__)
launchers = [
{'exe': "DRIVE:/PATH/TO/Battle.net/Battle.net Launcher.exe", 'kill': "Battle.net.exe", 'hide': "Blizzard Battle.net", 'hide_wait': 20, 'timeout': 7200, 'rounds': 2, 'copy': ["ROBOCOPY %programdata%\Battle.net \"DRIVE:\PATH\TO\Blizzard Data\Battle.net\" /MIR /FFT"]},
{'exe': "DRIVE:/PATH/TO/Epic Games/Launcher/Engine/Binaries/Win64/EpicGamesLauncher.exe", 'kill': "EpicGamesLauncher.exe", 'hide': "Epic Games", 'hide_wait': 20, 'timeout': 7200, 'rounds': 2, 'copy': ["ROBOCOPY %userprofile%\AppData\Local\EpicGamesLauncher \"DRIVE:\PATH\TO\Epic Data\EpicGamesLauncher\" /MIR /FFT", "ROBOCOPY %programdata%\Epic \"DRIVE:\PATH\TO\Epic Data\Epic\" /MIR /FFT"]},
]
def spinning_cursor():
while True:
for cursor in '|/-\\':
yield cursor
def minimize_window(pid, pid_text=None):
def callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
if pid_text is not None:
text = win32gui.GetWindowText(hwnd)
if text.find(pid_text) >= 0:
hwnds.append(hwnd)
else:
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(callback, hwnds)
if len(hwnds) > 0:
win32gui.ShowWindow(hwnds[0], SW_MINIMIZE)
return True
else:
return False
def kill_by_name(name):
killed = False
for proc in process_iter():
if proc.name() == name:
proc.kill()
killed = True
return killed
for launcher in launchers:
for round in range(launcher['rounds']):
logger.info("Launching " + launcher['exe'])
launcher_proc = Popen([launcher['exe']])
if 'hide' in launcher:
logger.info("Waiting {} seconds then minimizing...".format(launcher['hide_wait']))
tries = 0
while 1:
sleep(launcher['hide_wait'])
if minimize_window(0, launcher['hide']):
break
tries += 1
if tries == 3:
kill_by_name(launcher['kill'])
logger.error("Failed to minimize launcher, skipping")
break
if tries == 3:
break
logger.info("Waiting {} seconds before killing launcher".format(launcher['timeout']))
tmp = launcher['timeout']
spinner = spinning_cursor()
while tmp != 0:
if 'hide' in launcher and (tmp % 60) == 0:
minimize_window(0, launcher['hide'])
stdout.write(next(spinner))
stdout.flush()
sleep(1)
stdout.write('\b')
tmp -= 1
if kill_by_name(launcher['kill']):
logger.info("Killed launcher...")
else:
logger.error("Failed to kill launcher") #todo: what now?
if round == 1 and 'copy' in launcher:
for cmd in launcher['copy']:
system(cmd)
logger.info("All launched... Quitting")