-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkipUpdate.py
209 lines (183 loc) · 6.64 KB
/
SkipUpdate.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import wexpect
import os
import re
import sys
import time
from pathlib import Path
NotValid1 = True
NotValid2 = True
IOdata = ['\n']*10
separator = '\n-------------------------------------\n'
try:
with open(Path(__file__).with_name('path.txt'), 'r'): pass
except FileNotFoundError:
with open(Path(__file__).with_name('path.txt'), 'w'): pass
# Path to file
while NotValid1:
x = input('Use last directory? (y/n) ')
# Load configs as list
with open(Path(__file__).with_name('path.txt'), 'r') as fileI:
var = fileI.readlines()
IOdata[:len(var)] = var
# if yes load from list
if x in ["y", "yes"]:
directory = IOdata[0].rstrip()
NotValid1 = False
# if no save input to file
elif x in ["n", "no"]:
directory = input('Input directory (ex. X:\SteamLibrary\steamapps): ')
# Save data for next time
with open(Path(__file__).with_name('path.txt'), 'w') as fileO:
IOdata[0] = directory + '\n'
fileO.writelines(IOdata)
NotValid1 = False
else:
print('Invalid input')
# Filename
while NotValid2:
x = input('Use last filename? (y/n) ')
# Load configs as list
with open(Path(__file__).with_name('path.txt'), 'r') as fileI:
var = fileI.readlines()
IOdata[:len(var)] = var
# if yes load from list
if x in ["y", "yes"]:
filename = IOdata[1].rstrip()
NotValid2 = False
# if no save input to file
elif x in ["n", "no"]:
# Save data for next time
filename = os.path.splitext(input('Input filename: '))[0]+'.acf'
with open(Path(__file__).with_name('path.txt'), 'w') as fileO:
IOdata[1] = filename + '\n'
fileO.writelines(IOdata)
NotValid2 = False
else:
print('Invalid input')
print(separator)
# Normalize and combine
filepath = os.path.normpath(directory) + "\\" + filename
# Read manifest file as list and search for manifest
try:
with open(filepath, 'r') as file:
content = file.readlines()
index = [x for x in range(len(content)) if 'manifest' in content[x].lower()]
except FileNotFoundError:
print('Error: Path does not exist!\n{}\n'.format(filepath))
input('\n Press Enter to exit...')
exit()
# Check if its already updated
for i in content:
if 'StateFlags' in i:
print(i)
if re.findall(r'\d+',i)[0] == 4:
print('Already up to date')
input('\n Press Enter to exit...')
exit()
# If not show index
print('Found manifests: \n')
for i in index:
print(content[i-2])
print(content[i])
print(separator)
# Spicy wexpect action
child = wexpect.spawn("cmd")
child.expect('>')
appid = filename.split("_")[1].rstrip()
print('Starting SteamCMD... \n')
arg = "steamcmd.exe +login anonymous +app_info_request {} +app_info_print {} +logoff +quit".format(appid, appid)
print('>' + arg + '... \n')
child.sendline(arg)
child.expect('>')
RawDB = child.before
child.sendline("exit")
child.wait()
print(separator)
# Split output to list
DB = RawDB.splitlines(True)
# Throw error if fail
for i in range(len(DB)):
if 'is not recognized as an internal or external command,' in DB[i].lower():
print("Error SteamCMD not found! \n\nPlease place SteamCMD in same directory as file \n")
print(RawDB)
input('\n Press Enter to exit...')
exit()
# Cleanup the list for search
Junk = [x for x in range(len(DB)) if 'logging off current session' in DB[x].lower()]
for i in range(Junk[0]):
DB[i] = ''
DB.pop(-1)
# Search for manifest and add to list
DBindex = [x for x in range(len(DB)) if 'manifest' in DB[x].lower()]
ManifestIndex = []
for i in DBindex:
if '}' not in DB[i-2]:
for x in range(10):
if re.findall(r'\d+', DB[i-x]):
ManifestIndex.append(DB[i-x])
ManifestIndex.append(DB[i+4])
# Search for BuildID
for idi, i in enumerate(DB):
if 'buildid' in i:
if 'public' in DB[idi-2]:
BuildID = re.findall(r'\d+', DB[idi])[0]
# Error if empty
if not ManifestIndex:
debug = False
print('Error SteamCMD gave no data please run login anonymous and app_info_print {} manually to load the data and try again'.format(appid))
Attempt = input('\n Press Enter to exit or press y to attempt auto fix:\n')
if Attempt in ('y','debug'):
if Attempt == 'debug':
debug = True
child = wexpect.spawn("cmd")
child.expect('>')
appid = filename.split("_")[1].rstrip()
print('Starting SteamCMD... \n')
arg = "steamcmd.exe +login anonymous +app_info_request {}".format(appid)
print('>' + arg + '... \n')
child.sendline(arg)
T = 0
print('Please wait: ')
while T < 40:
print(40-T,' Seconds', end="\r", flush=True)
time.sleep(1)
T += 1
child.close()
if debug:
arg = "steamcmd.exe +login anonymous +app_info_request {} +app_info_print {} +logoff +quit".format(appid, appid)
print('>' + arg + '... \n')
child = wexpect.spawn("cmd")
child.expect('>')
child.sendline(arg)
child.expect('>')
print(child.before)
child.sendline("exit")
child.wait()
child.close()
input('\n Press Enter to exit...')
else:
print('\n Please rerun the script')
input('\n Press Enter to exit...')
exit()
# Compare and replace old manifest
for xid, x in enumerate(ManifestIndex):
for i in index:
if int(re.findall(r'\d+', content[i-2])[0]) == int(re.findall(r'\d+', x)[0]):
print('Found match: ' + re.findall(r'\d+', x)[0] + '!\n\nold:\n' + re.findall(r'\d+',content[i])[0] + '\nnew:\n' + re.findall(r'\d+', ManifestIndex[xid + 1])[0])
content[i] = ' "manifest" "{}"\n'.format(re.findall(r'\d+', ManifestIndex[xid + 1])[0])
# Update BuildId, change Flag and disable ScheduledAutoUpdate
for idi, i in enumerate(content):
if 'StateFlags' in i:
content[idi] = ' "StateFlags" "4"\n'
elif 'ScheduledAutoUpdate' in i:
content[idi] = ' "ScheduledAutoUpdate" "0"\n'
elif 'buildid' in i:
content[idi] = ' "buildid" "{}"\n'.format(BuildID)
# Output
print(separator + '\nUpdated manifest:\n\n')
for i in content:
print(i, end='')
with open(filepath, 'w') as file:
file.writelines(content)
input('\n Press Enter to exit...')
# F:\SteamLibrary\steamapps\appmanifest_582660.acf