|
11 | 11 | import urllib.request
|
12 | 12 | import zipfile
|
13 | 13 | import subprocess
|
| 14 | +import hashlib |
14 | 15 | from protonfixes import util
|
| 16 | +from protonfixes.logger import log |
15 | 17 |
|
16 | 18 | def main():
|
17 | 19 | util.replace_command('CTB.exe', 'nw.exe')
|
18 | 20 | install_dir = glob.escape(util.get_game_install_path())
|
19 | 21 | if not os.path.isfile(os.path.join(install_dir, 'nw.exe')):
|
20 | 22 | url = 'https://dl.nwjs.io/v0.86.0/nwjs-v0.86.0-win-x64.zip'
|
21 | 23 | 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.") |
28 | 36 | subprocess.call([f"sed -i 's/\"frame\": true/\"frame\": false/' \"{install_dir}/package.json\""], shell=True)
|
0 commit comments