forked from SilverStudioGames/WTS
55 lines
1.4 KiB
Plaintext
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()
|