Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit fc2c658

Browse files
v0.7 (autoupdating added)
1 parent 0f1439b commit fc2c658

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

APLauncher.pyw

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ import re
1515
import shutil
1616
import datetime
1717
import webview
18+
import hashlib
19+
import atexit
20+
import webbrowser
21+
import configparser
1822

19-
class SettingsPage(Frame):
23+
VERSION = "0.7"
24+
25+
class AboutPage(Frame):
2026

2127
def __init__(self, parent):
2228
super().__init__(parent)
23-
self.label = Label(self, text="Settings page coming soon!")
29+
self.titlelabel = Label(self, text=f"Links:", anchor="w")
30+
self.titlelabel.grid(column=0, row=0, sticky="nsew")
31+
self.bugreportlabel = Label(self, text=" Found a bug? Report it here!", foreground="blue", cursor="hand2")
32+
self.bugreportlabel.grid(column=0, row=1, sticky="nsew")
33+
self.bugreportlabel.bind("<Button-1>", lambda e: self.open_link("https://github.com/SpacePython12/AP-Launcher/issues/new"))
34+
35+
def open_link(self, url):
36+
webbrowser.open_new(url)
2437

2538
class LabeledEntry(Frame):
2639

@@ -53,7 +66,7 @@ class App:
5366

5467
def __init__(self):
5568
self.win = Tk()
56-
self.win.title("AP Launcher")
69+
self.win.title(f"AP Launcher v{VERSION}")
5770
self.tabs = Notebook(self.win)
5871
self.tabs.grid()
5972
self.minecraftdir = os.path.join(os.getenv('APPDATA'), '.minecraft')
@@ -166,6 +179,8 @@ class App:
166179
self.profadd.grid(column=0, row=7, sticky="nsew")
167180
self.update_profiles(self.versionvar.get())
168181
self.profilelist.bind("<<ComboboxSelected>>", lambda x: self.update_profiles(self.versionvar.get()))
182+
self.aboutpage = AboutPage(self.win)
183+
self.tabs.add(self.aboutpage, text="About")
169184

170185
def kill_process(self):
171186
"""Kills the running Minecraft process. I dont really know what to do about this function..."""
@@ -199,6 +214,8 @@ class App:
199214
json.dump(self.accounts, open(os.path.join(self.minecraftdir, "launcher_profiles.json"), "w"), indent=2)
200215
json.dump(self.cache, open("cache.json", "w"), indent=2)
201216
self.win.withdraw()
217+
if self.update_version():
218+
atexit.register(lambda: self.run_updater())
202219
sys.exit()
203220

204221
def get_versions(self):
@@ -348,9 +365,13 @@ class App:
348365
def get_latest_version(self, type_):
349366
versions = [x[0] for x in os.walk(os.path.join(self.minecraftdir, "versions"))]
350367
if type_ == "release":
351-
filtered = [x.split("\\")[-1][:6] for x in versions if bool(re.match("1\.[1-9][1-9]\.[1-9]", x.split("\\")[-1]))]
368+
filtered = [x.split("\\")[-1][:6] for x in versions if bool(re.match("1\.[0-9]+\.[1-9]+", x.split("\\")[-1])) or bool(re.match("1\.[0-9]+", x.split("\\")[-1]))]
369+
for x in range(len(filtered)):
370+
if bool(re.match("1\.[0-9]+", filtered[x])):
371+
filtered[x] += ".0"
352372
ranked = [int(x.replace(".", "")) for x in filtered]
353-
return filtered[ranked.index(max(ranked))]
373+
if filtered[ranked.index(max(ranked))].endswith(".0"):
374+
return filtered[ranked.index(max(ranked))].rstrip(".0")
354375
elif type_ == "snapshot":
355376
filtered = [x.split("\\")[-1][:6] for x in versions if bool(re.match("[0-9][0-9]w[0-9][0-9]a", x.split("\\")[-1]))]
356377
ranked = [int(x.replace("w", "").replace("a", "")) for x in filtered]
@@ -392,6 +413,42 @@ class App:
392413
zf.close()
393414
return
394415

416+
def update_version(self):
417+
request = requests.get("https://api.github.com/repos/SpacePython12/AP-Launcher/releases").json()
418+
if os.path.isfile("APLauncher.exe") and os.path.isfile("launcher_process.exe"):
419+
hash1 = hashlib.sha1()
420+
for f in ["APLauncher.exe", "launcher_process.exe"]:
421+
with open(f, "rb") as f2:
422+
data = f2.read()
423+
hash1.update(data)
424+
f2.close()
425+
durl = None
426+
for asset in request[0]["assets"]:
427+
if asset["name"] == "update.zip":
428+
durl = asset["browser_download_url"]
429+
break
430+
if durl is None:
431+
return False
432+
if not os.path.isdir("update"):
433+
os.mkdir("update")
434+
urlretrieve(url=durl, filename="update/update.zip")
435+
with ZipFile(open("update/update.zip", "rb")) as zf:
436+
zf.extractall("update")
437+
zf.close()
438+
os.remove("update/update.zip")
439+
hash2 = hashlib.sha1()
440+
for f in ["update/APLauncher.exe", "update/launcher_process.exe"]:
441+
with open(f, "rb") as f2:
442+
data = f2.read()
443+
hash2.update(data)
444+
f2.close()
445+
return True
446+
else:
447+
return False
448+
449+
def run_updater(self):
450+
shutil.move("update/APLauncher.exe", "APLauncher.exe")
451+
shutil.move("update/launcher_process.exe", "launcher_process.exe")
395452

396453
if __name__ == "__main__":
397454
main = App()

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ You may need to install some libraries, including...
1313
* Premium accounts are NOT supported.
1414
* Modded clients (including Optifine) are NOT supported.
1515

16-
In the future, I will link some version packages as backups if Minecraft is blocked on your network.
17-
1816
# Changelog:
1917
* Made some cosmetic changes.
20-
* Added an icon for the launcher.
21-
* Minecraft sounds and other assets are now downloaded at the start.
18+
* Added an updater.

0 commit comments

Comments
 (0)