WTS/game/scripts/utility/server.rpy
LoafyLemon 9bcbdba53b Web Updater
* Separated updater server code
* Fixed update logo fetch crash
* Added logo fetch var
2022-05-30 22:04:51 +01:00

55 lines
1.4 KiB
Plaintext

# This file can be safely deleted to permanently disable update checks.
init python:
import requests
import binascii
UPDATE_URL = ""
LOGO_URL = ""
new_version = None
def check_updates(interval=3600*6):
if not UPDATE_URL:
return
global new_version
new_version = updater.UpdateVersion(binascii.unhexlify(UPDATE_URL), check_interval=interval)
def install_updates():
if not UPDATE_URL:
return None
return updater.Update(binascii.unhexlify(UPDATE_URL), patch=True)
def fetch_update_logo(url):
if not (updater.can_update() or config.developer) or new_version is None or not LOGO_URL:
return Null()
filename = "logo_{}.png".format(new_version)
path = os.path.join(config.basedir, "updates/{}".format(filename))
# Read file if exists
if os.path.isfile(path):
with open(path, "rb") as f:
data = f.read()
return im.Data(data, path)
# Fetch file if doesn't exist
try:
url = binascii.unhexlify(url)
response = requests.get(url, timeout=5)
data = response.content
except:
return Null()
if not data:
return Null()
with open(path, "wb") as f:
f.write(data)
return im.Data(data, path)
check_updates()