From 481a08b29d6110a876b1515dbb6bc8df8dfce2cd Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 6 Feb 2024 09:41:44 -0300 Subject: Button to download the game clients, in case they weren't included. --- __main__.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/__main__.py b/__main__.py index a6d5055..463db7f 100755 --- a/__main__.py +++ b/__main__.py @@ -9,6 +9,7 @@ ##################################### import requests, json, traceback, subprocess, sys, time, os, uuid, base64 +import zipfile, shutil #import threading #hmac, struct # < - TODO: Necessary for TOTP-remember support import tkinter as tk from tkinter.messagebox import showinfo, showerror, askyesno @@ -16,6 +17,8 @@ from functools import partial OBFS = uuid.getnode() % 256 # Get a number which *usually* doesn't change OBFS = 185 # <- For debugging (FIXME ^ above didn't held up in practice) +# TODO: Maybe we can do len() for the absolute path to this script +# Then % 256 it so we always have a valid unchanging obfuscation? >_> print("Obfuscation key = %d" % OBFS) # <- Just to not leave it in plain text ## Internal wrapper for preferences @@ -134,6 +137,7 @@ class HoverButton(tk.Button): self.bind("", self.exit) ## TODO: Get from `sys` args parameters like world auto-selection +## or not using ./manaplus/ as path (but something else) (replace os.getcwd) ##################################### #VAULT_HOST = "https://localhost:13370" @@ -416,9 +420,10 @@ def greeter(text, _dest=None): ## It likely calls world_select() on return so only accessible from there ## Settings Screen should allow for world linking/unlinking ## Settings Screen should allow to modify anything in prefs[] -prefNotLocal=None; prefDiscord=None +prefNotLocal=None; prefDiscord=None; prefMana=None; prefPlus=None; prefLogs=None def settings(): - global canva, serverlist, prefNotLocal, prefDiscord + global canva, serverlist + global prefNotLocal, prefDiscord, prefMana, prefPlus, prefLogs canva.destroy() canva = tk.Canvas(root, width=400, height=600, bg="#0c3251") canva.pack() @@ -431,14 +436,36 @@ def settings(): prefNotLocal.set(pref["local"] != True) prefDiscord = tk.BooleanVar() prefDiscord.set(pref["discord"] == True) + prefMana = tk.BooleanVar() + prefMana.set(pref["mana"] == True) + prefPlus = tk.BooleanVar() + prefPlus.set(pref["plus"] == True) + prefLogs = tk.BooleanVar() + prefLogs.set(pref["shell"] == True) c1 = tk.Checkbutton(root, text="Use system-wide client", variable=prefNotLocal, bg="#0c3251", fg="#f70") canva.create_window(200, 60, window=c1) c2 = tk.Checkbutton(root, text="Use Discord integration", variable=prefDiscord, bg="#0c3251", fg="#f70") canva.create_window(200, 80, window=c2) - # TODO: M+, Mana, Console output + ## Less important/system specific options (TODO) + if not sys.platform.startswith('win'): + c3 = tk.Checkbutton(root, text="Use original Mana client", variable=prefMana, bg="#0c3251", fg="#f70") + canva.create_window(200, 110, window=c3) + c4 = tk.Checkbutton(root, text="Use ManaPlus client", variable=prefPlus, bg="#0c3251", fg="#f70") + canva.create_window(200, 135, window=c4) + c5 = tk.Checkbutton(root, text="Verbose logging", variable=prefLogs, bg="#0c3251", fg="#f70") + canva.create_window(200, 160, window=c5) + # TODO: "Download/Update GPL clients" button + button = HoverButton(text="Download GPL clients", command=_downloadClient, bg="#cc6600", fg="#fff", activebackground="#ee9933", font="helvetica 12", height=-10) + canva.create_window(200, 190, window=button) # TODO: Account Linking and Unlinking + # For that, use a dropdown menu (select world), login, password, ... + # Then a button "LINK" and "UNLINK". Encapsulate the form in a box + # TODO: Set a homeworld + # Can be done like above: Dropdown menu if not yet set, and button to save + # (Otherwise, homeworld is displayed with a label, and no button to change) + # TODO Then we can put some permanent multi-world bosses on CR? (Giving EXP) button = HoverButton(text="Save Settings", command=_settingSave, width=40, bg="#cc6600", fg="#fff", activebackground="#ee9933") canva.create_window(200, 575, window=button) @@ -446,10 +473,39 @@ def settings(): def _settingSave(): pref["local"] = not prefNotLocal.get() pref["discord"] = prefDiscord.get() + pref["shell"] = prefLogs.get() + pref["mana"] = prefMana.get() + pref["plus"] = prefPlus.get() _savePref() world_select() return +def _downloadClient(): + ## TODO: Show progress bars + if askyesno("Mana Launcher", "Do you want to download or update the game clients?\n\nThey are licensed under GPLv2 or later. Up to 150 MB of disk space will be required."): + ## Manaverse for Linux + if False and not sys.platform.startswith('win'): + with open("manaplus/ManaVerse.AppImage", 'wb') as f: + f.write(requests.get("https://updates.tmw2.org/mana/linux/ManaPlus-x86_64.AppImage", allow_redirects=True).content) + execute("chmod +x \"%s\"" % "manaplus/ManaVerse.AppImage", shell=True) + ## Manaverse for Windows + else: + with open("manaplus/manaverse.zip", 'wb') as f: + f.write(requests.get("https://updates.tmw2.org/mana/windows/manaverse.zip", allow_redirects=True).content) + try: + shutil.rmtree("manaplus/Mana") + except: + pass + with zipfile.ZipFile("manaplus/manaverse.zip", 'r') as zip_ref: + zip_ref.extractall("manaplus/") + os.remove("manaplus/manaverse.zip") + ## Mana for Linux + if not sys.platform.startswith('win') and pref["mana"]: + with open("manaplus/Mana.AppImage", 'wb') as f: + f.write(requests.get("https://updates.tmw2.org/mana/linux/Mana-x86_64.AppImage", allow_redirects=True).content) + execute("chmod +x \"%s\"" % "manaplus/Mana.AppImage", shell=True) + return + ################################################################################# ###### World Selection Screen def world_select(): @@ -462,6 +518,7 @@ def world_select(): canva.create_window(200, 30, window=label1) ## Fetch soul data + ## TODO: Doing this here is too inefficient!! auth = {"vaultId": vaultId, "token": vaultToken} @@ -473,19 +530,14 @@ def world_select(): mySoul["level"]=dat["soulv"] mySoul["exp"]=dat["soulx"] mySoul["next"]=dat["varlv"] - mySoul["up"]=False - ## Newer versions of API may level you up - catch it - try: - mySoul["up"]=dat["lvlup"] - mySoul["home"]=dat["homew"] - for s in serverlist: - if mySoul["home"] == s["UUID"]: - mySoul["home"] = s["Name"] - break - if mySoul["home"] == "VAULT": - mySoul["home"]="Not Set" - except: - pass + mySoul["up"]=dat["lvlup"] + mySoul["home"]=dat["homew"] + for s in serverlist: + if mySoul["home"] == s["UUID"]: + mySoul["home"] = s["Name"] + break + if mySoul["home"] == "VAULT": + mySoul["home"]="Not Set" ## Not really necessary? Or just TODO? ## Without these, max is 10 worlds -- cgit v1.2.3-70-g09d2