Skip to content

Commit c5e135f

Browse files
authored
checksum and warning if fails
1 parent e4bf406 commit c5e135f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

gamefixes-steam/1873170.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,26 @@
1111
import urllib.request
1212
import zipfile
1313
import subprocess
14+
import hashlib
1415
from protonfixes import util
16+
from protonfixes.logger import log
1517

1618
def main():
1719
util.replace_command('CTB.exe', 'nw.exe')
1820
install_dir = glob.escape(util.get_game_install_path())
1921
if not os.path.isfile(os.path.join(install_dir, 'nw.exe')):
2022
url = 'https://dl.nwjs.io/v0.86.0/nwjs-v0.86.0-win-x64.zip'
2123
nwjs = os.path.basename(url)
22-
urllib.request.urlretrieve (url, nwjs)
23-
with zipfile.ZipFile(nwjs, 'r') as zip_ref:
24-
zip_ref.extractall(install_dir)
25-
nwjs = os.path.join(install_dir, nwjs.rsplit('.', 1)[0])
26-
shutil.copytree(nwjs, install_dir, dirs_exist_ok=True)
27-
shutil.rmtree(nwjs)
24+
urllib.request.urlretrieve(url, nwjs)
25+
with open(nwjs, "rb") as f:
26+
nwjs_sum = hashlib.sha256(f.read()).hexdigest()
27+
urllib.request.urlretrieve(f"https://dl.nwjs.io/{nwjs.split('-', 2)[1]}/SHASUMS256.txt", 'SHASUMS256.txt')
28+
if subprocess.check_output(f"grep -F '{nwjs}' ./SHASUMS256.txt", shell=True,universal_newlines=True)[:64] == nwjs_sum:
29+
with zipfile.ZipFile(nwjs, 'r') as zip_ref:
30+
zip_ref.extractall(install_dir)
31+
nwjs = os.path.join(install_dir, nwjs.rsplit('.', 1)[0])
32+
shutil.copytree(nwjs, install_dir, dirs_exist_ok=True)
33+
shutil.rmtree(nwjs)
34+
else:
35+
log(f"{nwjs} checksum doesn't match, fix not applied.")
2836
subprocess.call([f"sed -i 's/\"frame\": true/\"frame\": false/' \"{install_dir}/package.json\""], shell=True)

0 commit comments

Comments
 (0)