-
Notifications
You must be signed in to change notification settings - Fork 9
/
updater.py
143 lines (116 loc) · 3.84 KB
/
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
import os
import subprocess
def exc_hook(type, value, traceback, oldhook=sys.excepthook):
oldhook(type, value, traceback)
input(' Press Enter to exit...')
sys.excepthook = exc_hook
import zipfile as zf
import locale
import shutil
LOCALE = locale.getdefaultlocale()[0]
FILES_TO_PRESERVE = ('config.yml', 'config.json', 'accounts.yml', 'accounts.json', 'salt')
def pprint(content):
print(' ', content)
def clear():
os.system('cls')
pprint(f'Launch arguments: {" ".join(sys.argv)}')
if '--force-update' in sys.argv:
force = True
elif "__compiled__" not in globals():
print()
pprint("Running on Python interpreter not supported")
print()
input(' Press Enter to exit...')
sys.exit(0)
else:
force = False
def invalidzip():
print()
if LOCALE == 'ko_KR':
pprint('업데이트 압축 파일이 유효하지 않습니다.')
pprint('프로그램을 재시작 하여 업데이트를 다시 시도하십시오.')
print()
pprint('----------------------------------------------------------')
print()
input(' Enter 키를 눌러서 나가기...')
else:
pprint('Update archive is invalid.')
pprint('Restart the application and try again.')
print()
pprint('----------------------------------------------------------')
print()
input(' Press Enter to exit...')
sys.exit(1)
cwd = os.getcwd()
if LOCALE == 'ko_KR':
pprint('현재 작업 디렉토리: ' + cwd)
pprint('업데이트 압축 파일 확인 중...')
else:
pprint('Current working directory: ' + cwd)
pprint('Verifying update archive...')
print()
archive = os.path.join(cwd, 'update.zip')
if not os.path.isfile(archive):
pprint("Error: Archive file doesn't exist")
invalidzip()
elif not zf.is_zipfile(archive):
pprint("Error: Archive file is not a zip file")
invalidzip()
else:
try:
f = zf.ZipFile(archive, mode='r')
except zf.BadZipFile:
pprint('Error: Bad zip file')
invalidzip()
if 'Steam Account Switcher.exe' not in f.namelist():
pprint(f.namelist())
invalidzip()
print()
if LOCALE == 'ko_KR':
pprint('업데이트 설치 중...')
else:
pprint('Installing update...')
for name in os.listdir(os.getcwd()):
if os.path.isdir(os.path.join(os.getcwd(), name)):
if name != 'avatar':
try:
shutil.rmtree(name)
pprint('Deleted a directory: ' + name)
except OSError:
pass
elif os.path.isfile(os.path.join(os.getcwd(), name)):
if name not in FILES_TO_PRESERVE:
try:
os.remove(name)
pprint('Deleted a file: ' + name)
except OSError:
pass
while True:
try:
pprint('Extracting...')
f.extractall(members=(member for member in f.namelist() if 'updater' not in member))
break
except OSError:
print()
if LOCALE == 'ko_KR':
pprint('업데이트 도중 오류가 발생하였습니다.')
pprint('다른 앱이 파일을 사용 중이지 않은지 확인하세요.')
print()
pprint('----------------------------------------------------------')
print()
input(' 다시 시도하려면 Enter키를 누르세요...')
else:
pprint('Error occured during update process.')
pprint('Make sure that other applications are not using any of the files')
print()
pprint('----------------------------------------------------------')
print()
input(' Press Enter to try again...')
clear()
f.close()
if not force:
subprocess.Popen('Steam Account Switcher.exe', cwd=os.getcwd())
else:
input('Forced update complete. Press Enter to exit...')
sys.exit(0)