From 9bcbdba53b633b1ff08742f0429d6a07e48bfed8 Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Mon, 30 May 2022 22:04:51 +0100 Subject: [PATCH] Web Updater * Separated updater server code * Fixed update logo fetch crash * Added logo fetch var --- game/scripts/gui/main_menu.rpy | 6 ++-- game/scripts/utility/server.rpy | 54 ++++++++++++++++++++++++++++++++ game/scripts/utility/updater.rpy | 39 +---------------------- 3 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 game/scripts/utility/server.rpy diff --git a/game/scripts/gui/main_menu.rpy b/game/scripts/gui/main_menu.rpy index 1a7fb7c9..d14c5d1b 100644 --- a/game/scripts/gui/main_menu.rpy +++ b/game/scripts/gui/main_menu.rpy @@ -243,11 +243,11 @@ screen navigation(title=None): if main_menu: if not title: - if (updater.can_update() or config.developer): + if (updater.can_update() or config.developer) and getattr(store, "UPDATE_URL", None): if new_version: - textbutton "Update available" action updater.Update(UPDATE_URL, simulate="available", patch=True) style_prefix "update_available" + textbutton "Update available" action install_updates() style_prefix "update_available" else: - textbutton "Check for updates" action Function(check_for_updates, 300) + textbutton "Check for updates" action Function(check_updates, 300) if show_quick_start: textbutton _("Quick Start") action Start("start_quick") diff --git a/game/scripts/utility/server.rpy b/game/scripts/utility/server.rpy new file mode 100644 index 00000000..24da3af3 --- /dev/null +++ b/game/scripts/utility/server.rpy @@ -0,0 +1,54 @@ +# 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() diff --git a/game/scripts/utility/updater.rpy b/game/scripts/utility/updater.rpy index a9b8bb04..f95128d0 100644 --- a/game/scripts/utility/updater.rpy +++ b/game/scripts/utility/updater.rpy @@ -67,49 +67,12 @@ define update_message_list = [ "Insert disc 2", ] -init python: - import requests - - UPDATE_URL = "http://update.silverstudiogames.org/updates.json" - new_version = None - - def check_for_updates(interval=3600*6): - global new_version - new_version = updater.UpdateVersion(UPDATE_URL, simulate="available", check_interval=interval) - - def fetch_update_logo(url): - if not (updater.can_update() or config.developer) or new_version is None: - 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 - response = requests.get(url, timeout=5) - data = response.content - - if not data: - return Null() - - with open(path, "wb") as f: - f.write(data) - - return im.Data(data, path) - - # check_for_updates() - screen updater: tag menu default msg = renpy.random.choice(update_message_list) - default logo = fetch_update_logo("https://cdn.discordapp.com/attachments/535709194876354571/957762605735354378/discord.png") # http://update.silverstudiogames.org/logo.webp + default logo = fetch_update_logo(LOGO_URL) # http://update.silverstudiogames.org/logo.webp use game_menu(_("Updater"), scroll="viewport"):