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

Commit 3c11492

Browse files
v0.8 (added support for old versions)
1 parent 675103e commit 3c11492

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

APLauncher.pyw

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from tkinter.scrolledtext import ScrolledText
44
from tkinter import messagebox, filedialog
55
from PIL import ImageTk, Image
66
from urllib.request import urlretrieve
7+
from urllib.error import *
78
from zipfile import ZipFile
89
import os
910
import json
@@ -20,7 +21,7 @@ import atexit
2021
import webbrowser
2122
import configparser
2223

23-
VERSION = "0.7"
24+
VERSION = "0.8"
2425

2526
class AboutPage(Frame):
2627

@@ -79,8 +80,13 @@ class App:
7980
os.mkdir("assets")
8081
if not os.path.isdir("temp"):
8182
os.mkdir("temp")
82-
urlretrieve(url="https://raw.github.com/SpacePython12/AP-Launcher/main/assets/background.png", filename="assets/background.png")
83-
urlretrieve(url="https://raw.github.com/SpacePython12/AP-Launcher/main/assets/icon.ico", filename="assets/icon.ico")
83+
try:
84+
urlretrieve(url="https://raw.github.com/SpacePython12/AP-Launcher/main/assets/background.png", filename="assets/background.png")
85+
urlretrieve(url="https://raw.github.com/SpacePython12/AP-Launcher/main/assets/icon.ico", filename="assets/icon.ico")
86+
except HTTPError:
87+
pass
88+
except URLError:
89+
pass
8490
self.background = ImageTk.PhotoImage(Image.open("assets/background.png"))
8591
self.icon = ImageTk.PhotoImage(file="assets/icon.ico")
8692
self.win.iconphoto(True, self.icon)
@@ -341,7 +347,7 @@ class App:
341347
stdin=subprocess.DEVNULL
342348
)
343349
while sb.poll() is None:
344-
line = sb.stdout.readline().decode("unicode-escape").rstrip()
350+
line = sb.stdout.readline().decode("ISO-8859-1").rstrip()
345351
if not line == "":
346352
self.update_procscreen(line)
347353
self.playbutton.config(state="normal", text="\nPlay\n")
@@ -391,9 +397,11 @@ class App:
391397
with ZipFile(open(filepath, "rb")) as zf:
392398
folders = list(set([os.path.dirname(x).split("/")[0] for x in zf.namelist()]))
393399
folders.remove("indexes")
400+
folders.remove("natives")
401+
folders.remove("")
402+
infofile = zf.open("manifest.json")
403+
info = json.load(infofile)
394404
for folder in folders:
395-
infofile = zf.open(f"{folder}/manifest.json")
396-
info = json.load(infofile)
397405
if os.path.isdir(os.path.join(self.minecraftdir, "versions", folder)):
398406
if not messagebox.askyesno("Confirm", "There is already a version by this name. Would you like to overwrite it?"):
399407
zf.close()
@@ -402,13 +410,16 @@ class App:
402410
shutil.rmtree(os.path.join(self.minecraftdir, "versions", folder))
403411
os.mkdir(os.path.join(self.minecraftdir, "versions", folder))
404412
for file_ in zf.namelist():
405-
if file_.startswith(folder) and not file_.endswith("manifest.json"):
413+
if file_.startswith(folder):
406414
zf.extract(file_, os.path.join(self.minecraftdir, "versions"))
407415
info["profile"][list(info["profile"].keys())[0]]["created"] = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
408416
self.accounts["profiles"][list(info["profile"].keys())[0]] = info["profile"][list(info["profile"].keys())[0]]
409417
for file_ in zf.namelist():
410418
if file_.startswith("indexes"):
411419
zf.extract(file_, os.path.join(self.minecraftdir, "assets"))
420+
for file_ in zf.namelist():
421+
if file_.startswith("natives"):
422+
zf.extract(file_, os.path.join(self.minecraftdir, "bin"))
412423
messagebox.showinfo("Success", "The version was successfully imported. Restart AP Launcher to see changes.")
413424
zf.close()
414425
return
@@ -432,6 +443,10 @@ class App:
432443
if not os.path.isdir("update"):
433444
os.mkdir("update")
434445
urlretrieve(url=durl, filename="update/update.zip")
446+
if os.path.isfile("update/APLauncher.exe"):
447+
os.remove("update/APLauncher.exe")
448+
if os.path.isfile("update/launcher_process.exe"):
449+
os.remove("update/launcher_process.exe")
435450
with ZipFile(open("update/update.zip", "rb")) as zf:
436451
zf.extractall("update")
437452
zf.close()
@@ -447,6 +462,10 @@ class App:
447462
return False
448463

449464
def run_updater(self):
465+
if os.path.isfile("APLauncher.exe"):
466+
os.remove("APLauncher.exe")
467+
if os.path.isfile("launcher_process.exe"):
468+
os.remove("launcher_process.exe")
450469
shutil.move("update/APLauncher.exe", "APLauncher.exe")
451470
shutil.move("update/launcher_process.exe", "launcher_process.exe")
452471

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ You may need to install some libraries, including...
1414
* Modded clients (including Optifine) are NOT supported.
1515

1616
# Changelog:
17-
* Made some cosmetic changes.
18-
* Added an updater.
17+
* Restructured the library loading system a bit.
18+
* Now supports older versions.
19+
* Tweaked the version installers, versions that didn't work before work now.

launcher_process.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,18 @@ def get_classpath(lib, mcDir):
106106
def move_libraries(mcdir, dest, libjson, cp, version):
107107
"""Moves libraries to natives path"""
108108
index = 0
109+
if not os.path.isdir(dest):
110+
os.mkdir(dest)
109111
shutil.copyfile(f"{mcDir}/versions/{version}/{version}.jar", os.path.join(dest, f"{version}.jar"))
110112
for c in cp.split(";"):
111113
name = c.split("\\")[-1]
112-
print(f"Looking for {name}...")
113114
if not os.path.isfile(os.path.join(dest, name)) and os.path.isfile(c):
114-
print(f"{name} is already cached, moving to natives folder")
115115
shutil.copyfile(os.path.join(mcDir, "libraries", c.replace("\\", "/")), os.path.join(dest, name))
116116
elif not os.path.isfile(c):
117-
print(f"{name} is not cached, trying to download")
118117
os.makedirs(os.path.join(mcDir, "libraries", *c.replace(f"{mcDir}\\libraries\\", "").split("\\")[:-1]), exist_ok=True)
119118
url = "https://libraries.minecraft.net/" + c.replace(f"{mcDir}\\libraries\\", "").replace("\\", "/")
120119
urlretrieve(url, os.path.join(mcDir, "libraries", c.replace("\\", "/")))
121120
shutil.copyfile(os.path.join(mcDir, "libraries", c.replace("\\", "/")), os.path.join(dest, name))
122-
print(f"{name} successfully moved to natives folder.")
123121
index += 1
124122

125123
def download_asset(hash_, failedlist):
@@ -143,6 +141,13 @@ def download_assets(assetsdir, assetindex):
143141
thread = threading.Thread(None, lambda: download_asset(hash_, failedlist))
144142
thread.start()
145143

144+
def move_natives(mcdir, nativesdir):
145+
src = os.path.join(mcdir, "bin", "natives")
146+
files = [f for f in os.listdir(src) if os.path.isfile(os.path.join(src, f))]
147+
for file_ in files:
148+
if not os.path.isfile(os.path.join(nativesdir, file_)):
149+
shutil.copyfile(os.path.join(mcdir, "bin", "natives", file_), os.path.join(nativesdir, file_))
150+
146151
try:
147152
username = sys.argv[sys.argv.index("-username")+1]
148153
version = sys.argv[sys.argv.index("-version")+1]
@@ -188,6 +193,7 @@ def download_assets(assetsdir, assetindex):
188193
os.mkdir(os.path.join(mcDir, 'versions', version, 'natives'))
189194
nativesDir = os.path.join(mcDir, 'versions', version, 'natives')
190195
move_libraries(classPath, nativesDir, clientJson["libraries"], classPath, version)
196+
move_natives(mcDir, nativesDir)
191197
if inheritor is None:
192198
mainClass = clientJson['mainClass']
193199
assetIndex = clientJson['assetIndex']['id']
@@ -245,6 +251,6 @@ def download_assets(assetsdir, assetindex):
245251
)
246252
isfirstpass = True
247253
while sb.poll() is None:
248-
line = sb.stdout.readline().decode("unicode-escape").rstrip()
254+
line = sb.stdout.readline().decode("ISO-8859-1").rstrip()
249255
if not line == "":
250256
print(line)

0 commit comments

Comments
 (0)