Last active
April 2, 2021 18:17
-
-
Save C-ffeeStain/9b7db32da263741da657ce9a0c9af90e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, urllib.request, shutil, os | |
from pprint import pprint | |
import winreg | |
from pathlib import Path | |
from subprocess import Popen | |
def check_registry_for_spel2(): | |
if winreg is None: | |
return None | |
programs = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall') | |
index = 0 | |
while True: | |
try: | |
keyname = winreg.EnumKey(programs, index) | |
index += 1 | |
except OSError: | |
return None | |
try: | |
subkey = winreg.OpenKey(programs, keyname) | |
name, _ = winreg.QueryValueEx(subkey, "DisplayName") | |
if name == "Spelunky 2": | |
return Path(winreg.QueryValueEx(subkey, "InstallLocation")[0]) | |
except OSError: | |
continue | |
return None | |
r = requests.get('https://api.github.com/repos/spelunky-fyi/overlunky/releases') | |
for data in r.json(): | |
if data['tag_name'].lower() == 'whip': | |
url = data['assets'][0]['browser_download_url'] | |
print('Getting WHIP build and information about it...') | |
urllib.request.urlretrieve(url, 'Overlunky_WHIP.zip') | |
print('Extracting zip...') | |
s2_path = check_registry_for_spel2() | |
if s2_path is not None: | |
shutil.unpack_archive('Overlunky_WHIP.zip', s2_path) | |
elif Path('C:/Program Files (x86)/Steam/steamapps/common/Spelunky 2/Spel2.exe').exists(): | |
s2_path = 'C:/Program Files (x86)/Steam/steamapps/common/Spelunky 2' | |
shutil.unpack_archive('Overlunky_WHIP.zip', s2_path) | |
else: | |
shutil.unpack_archive('Overlunky_WHIP.zip', '.') | |
os.remove('Overlunky_WHIP.zip') | |
if s2_path is not None: | |
print('Successfully downloaded WHIP build to \'{}\'.'.format(s2_path)) | |
elif Path('C:/Program Files (x86)/Steam/steamapps/common/Spelunky 2/Spel2.exe').exists(): | |
s2_path = Path('C:/Program Files (x86)/Steam/steamapps/common/Spelunky 2/') | |
print('Downloaded WHIP build to \'{}\' since this program could not find your Spelunky folder installation.'.format(s2_path)) | |
else: | |
print('Downloaded WHIP build to current folder.') | |
Popen([s2_path / 'Overlunky/Overlunky.exe']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment