Skip to content

Commit

Permalink
Check network before getting title name
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
R1kaB3rN committed Mar 15, 2024
1 parent 2e55ced commit 2eb3a6d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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:
Expand Down

0 comments on commit 2eb3a6d

Please sign in to comment.