installer will now detect if it is a dev version, and can change url to download track

This commit is contained in:
raphael60650 2021-07-17 21:05:09 +02:00
parent 57efdf2da3
commit 2f171311bc
5 changed files with 20 additions and 11 deletions

View file

@ -19,6 +19,7 @@ def __init__(self):
self.ctconfig = CT_Config() self.ctconfig = CT_Config()
self.ctconfig.load_ctconfig_file("./ct_config.json") self.ctconfig.load_ctconfig_file("./ct_config.json")
self.is_dev_version = False # Is this installer version a dev ?
self.stringvar_language = StringVar(value=self.option["language"]) self.stringvar_language = StringVar(value=self.option["language"])
self.stringvar_game_format = StringVar(value=self.option["format"]) self.stringvar_game_format = StringVar(value=self.option["format"])
self.boolvar_disable_download = BooleanVar(value=self.option["disable_download"]) self.boolvar_disable_download = BooleanVar(value=self.option["disable_download"])
@ -36,8 +37,6 @@ def __init__(self):
self.root.iconbitmap(bitmap="./icon.ico") self.root.iconbitmap(bitmap="./icon.ico")
if not(self.boolvar_dont_check_for_update.get()): self.check_update() if not(self.boolvar_dont_check_for_update.get()): self.check_update()
self.path_mkwf = None
self.menu_bar = Menu(self.root) self.menu_bar = Menu(self.root)
self.root.config(menu=self.menu_bar) self.root.config(menu=self.menu_bar)

View file

@ -13,15 +13,15 @@ def check_update(self):
with open("./version", "rb") as f: with open("./version", "rb") as f:
locversion = json.load(f) locversion = json.load(f)
if ((float(gitversion["version"]) > float(locversion["version"])) or if ((float(gitversion["version"]) > float(locversion["version"])) or # if github version is newer than
(float(gitversion["version"]) == float(locversion["version"])) and (float(gitversion["version"]) == float(locversion["version"])) and # local version
float(gitversion["subversion"]) > float(locversion["subversion"])): float(gitversion["subversion"]) > float(locversion["subversion"])):
if messagebox.askyesno( if messagebox.askyesno(
self.translate("Update available !"), self.translate("Update available !"),
self.translate("An update is available, do you want to install it ?", self.translate("An update is available, do you want to install it ?",
f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> " f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> "
f"{gitversion['version']}.{gitversion['subversion']}\n" f"{gitversion['version']}.{gitversion['subversion']}\n"
f"Changelog :\n{gitversion['changelog']}")): f"Changelog :\n{gitversion['changelog']}")):
if not(os.path.exists("./Updater/Updater.exe")): if not(os.path.exists("./Updater/Updater.exe")):
dl = requests.get(gitversion["updater_bin"], allow_redirects=True) dl = requests.get(gitversion["updater_bin"], allow_redirects=True)
@ -38,6 +38,11 @@ def check_update(self):
print(self.translate("starting application...")) print(self.translate("starting application..."))
os.startfile(os.path.realpath("./Updater/Updater.exe")) os.startfile(os.path.realpath("./Updater/Updater.exe"))
if ((float(gitversion["version"]) < float(locversion["version"])) or # if local version is newer than
(float(gitversion["version"]) == float(locversion["version"])) and # github version
float(gitversion["subversion"]) < float(locversion["subversion"])):
self.is_dev_version = True
except requests.ConnectionError: except requests.ConnectionError:
messagebox.showwarning(self.translate("Warning"), messagebox.showwarning(self.translate("Warning"),
self.translate("Can't connect to internet. Download will be disabled.")) self.translate("Can't connect to internet. Download will be disabled."))

View file

@ -1,7 +1,10 @@
CREATE_NO_WINDOW = 0x08000000 CREATE_NO_WINDOW = 0x08000000
GITHUB_REPOSITORY = "Faraphel/MKWF-Install" GITHUB_REPOSITORY = "Faraphel/MKWF-Install"
GITHUB_CONTENT_ROOT = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/" GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/"
VERSION_FILE_URL = GITHUB_CONTENT_ROOT + "version" GITHUB_DEV_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/dev/"
VERSION_FILE_URL = GITHUB_MASTER_BRANCH + "version"
get_github_content_root = lambda self: GITHUB_DEV_BRANCH if self.is_dev_version else GITHUB_MASTER_BRANCH
get_filename = lambda file: ".".join(file.split(".")[:-1]) get_filename = lambda file: ".".join(file.split(".")[:-1])
get_nodir = lambda file: file.replace("\\", "/").split("/")[-1] get_nodir = lambda file: file.replace("\\", "/").split("/")[-1]

View file

@ -9,7 +9,7 @@ def get_github_file(self, file):
returncode = 0 returncode = 0
if self.boolvar_disable_download.get(): return 2 if self.boolvar_disable_download.get(): return 2
dl = requests.get(GITHUB_CONTENT_ROOT+file, allow_redirects=True, stream=True) dl = requests.get(get_github_content_root(self)+file, allow_redirects=True, stream=True)
if os.path.exists(file): if os.path.exists(file):
if int(dl.headers['Content-Length']) == os.path.getsize(file): return 1 if int(dl.headers['Content-Length']) == os.path.getsize(file): return 1
else: returncode = 3 else: returncode = 3

View file

@ -132,4 +132,6 @@ def install_mod(self):
t = Thread(target=func) t = Thread(target=func)
t.setDaemon(True) t.setDaemon(True)
t.start() t.start()
return t return t
# TODO: use wszst module instead of subprocess