From 2eb3a6daf1370becba7f11bfcc402f811cfe59cb Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:09:48 -0700 Subject: [PATCH] Check network before getting title name - Checks the network state before making request for the game title and sets timeouts for requests. Otherwise, Protonfixes will hang indefinitely which can happen for users with certain network configurations (e.g., configuring a VPN) --- fix.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fix.py b/fix.py index 2b2639e5..e290f964 100755 --- a/fix.py +++ b/fix.py @@ -9,7 +9,7 @@ import urllib import json from importlib import import_module -from .util import protonprefix +from .util import protonprefix, check_internet from .checks import run_checks from .logger import log from . import config @@ -33,34 +33,37 @@ def game_id(): def game_name(): """ Trys to return the game name from environment variables """ + is_online = check_internet() if 'ULWGL_ID' in os.environ: if os.path.isfile(os.environ['WINEPREFIX'] + "/game_title"): with open(os.environ['WINEPREFIX'] + "/game_title", 'r') as file: return file.readline() else: try: - if 'STORE' in os.environ: + if 'STORE' in os.environ and is_online: url = "https://ulwgl.openwinecomponents.org/ulwgl_api.php?ulwgl_id=" + os.environ['ULWGL_ID'] + "&store=" + os.environ['STORE'] headers = {'User-Agent': 'Mozilla/5.0'} req = urllib.request.Request(url, headers=headers) - response = urllib.request.urlopen(req) + response = urllib.request.urlopen(req, timeout=5) data = response.read() json_data = json.loads(data) title = json_data[0]['title'] file = open(os.environ['WINEPREFIX'] + "/game_title", 'w') file.write(title) file.close() - else: + elif 'STORE' not in os.environ and is_online: url = "https://ulwgl.openwinecomponents.org/ulwgl_api.php?ulwgl_id=" + os.environ['ULWGL_ID'] + "&store=none" headers = {'User-Agent': 'Mozilla/5.0'} req = urllib.request.Request(url, headers=headers) - response = urllib.request.urlopen(req) + response = urllib.request.urlopen(req, timeout=5) data = response.read() json_data = json.loads(data) title = json_data[0]['title'] file = open(os.environ['WINEPREFIX'] + "/game_title", 'w') file.write(title) file.close() + elif not is_online: + raise OSError except OSError as e: #log.info('OSError occurred: {}'.format(e)) # used for debugging return 'UNKNOWN' @@ -70,6 +73,9 @@ def game_name(): except UnicodeDecodeError as e: #log.info('UnicodeDecodeError occurred: {}'.format(e)) # used for debugging return 'UNKNOWN' + except TimeoutError: + log.info('ulwgl.openwinecomponents.org timed out') + return 'UNKNOWN' with open(os.environ['WINEPREFIX'] + "/game_title", 'r') as file: return file.readline() else: