Skip to content

Commit

Permalink
installer lesss gooo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcat101 committed Sep 27, 2023
1 parent d2ee64a commit 6c5d944
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
56 changes: 38 additions & 18 deletions installer/src/lib/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
from tempfile import TemporaryDirectory
from urllib import request
from zipfile import ZipFile
from json import load, dump

from .utils import _show_err, _clean_path, _is_windows

PATCH_COMMAND = "patch" if not _is_windows() else "C:\\Program Files\\Git\\usr\\bin\\patch.exe"

def start_install(win:Tk, instancedir:str, channel:str) -> None:
def start_install(win:Tk, instancedir:str, javabin:str, channel:str) -> None:
if not (_clean_path(instancedir).replace(" ", "") or _clean_path(javabin).replace(" ", "")):
_show_err(win, "Paths must not be empty.")
return

instancedir = path.sep.join(_clean_path(instancedir).split(path.sep)[:-1])
javabin = _clean_path(javabin)

if not instancedir:
_show_err(win, "Path must not be empty.")
return
if not path.exists(instancedir):
_show_err(win, "Unknown path.\nPlease check if it's correct.")
_show_err(win, "Unknown path \".minecraft\" path.\nPlease check if it's correct.")
return
if not path.exists(javabin):
_show_err(win, "Unknown path Java binary path.\nPlease check if it's correct.")
return
if run(("java", "-version"), stderr=DEVNULL).returncode!=0:
_show_err(win, "Java not found or your default installation is broken.")
if run((javabin, "-version"), stderr=DEVNULL).returncode!=0:
_show_err(win, "Incorrect Java path or your installation is broken.")
return
if run((PATCH_COMMAND, "-v"), stdout=DEVNULL).returncode!=0:
_show_err(win, "Patch command not found. If you are on Windows, please install git first.")
Expand All @@ -38,20 +44,21 @@ def start_install(win:Tk, instancedir:str, channel:str) -> None:
loading.geometry("250x150")
loading.title("Installing PissMC")
loading.grab_set()
mainlabel = Label(loading, text="Installing...")
label = StringVar()
label.set("Installing...")
mainlabel = Label(loading, textvariable=label)
mainlabel.pack(expand=True)

mainlabel.after(10, lambda: _install_pissmc(rdfile, channel, instancedir))
mainlabel.after(10, lambda: _install_pissmc(rdfile, channel, instancedir, javabin, loading, label))

def _install_pissmc(rdfile:str, channel:str, instancedir:str) -> None:
def _install_pissmc(rdfile:str, channel:str, instancedir:str, javabin:str, loading:Toplevel, label:StringVar) -> None:
with TemporaryDirectory() as tempdir:
chdir(tempdir)
_download_files(rdfile, channel)
_patch_jar(instancedir)
_patch_jar(instancedir, javabin)

print(tempdir)

while 1: pass
label.set("Install successful!")
loading.after(3000, lambda: (loading.grab_release() or loading.destroy()))

def _download_files(rdfile:str, channel:str) -> None:
WRAPPER_PATH = path.join("gradle", "wrapper")
Expand All @@ -68,7 +75,7 @@ def _download_files(rdfile:str, channel:str) -> None:
request.urlretrieve(f"https://github.com/intoolswetrust/jd-cli/releases/download/jd-cli-1.2.0/jd-cli-1.2.0-dist.zip", "jd-cli.zip")

with ZipFile("jd-cli.zip") as f: f.extract("jd-cli.jar")
def _patch_jar(instancedir:str) -> None:
def _patch_jar(instancedir:str, javabin:str) -> None:
run(("java", "-jar", "jd-cli.jar", "minecraft-rd-132211-client.jar", "-od", "decomp"), stdout=DEVNULL)

makedirs(path.join("src", "main", "java"), exist_ok=True)
Expand All @@ -78,10 +85,23 @@ def _patch_jar(instancedir:str) -> None:

run(PATCH_COMMAND+" -s -p0 < piss.patch", shell=True, stdout=DEVNULL)

if _is_windows(): run(("gradlew.bat", "build"), stdout=DEVNULL)
if _is_windows(): run(f"gradlew.bat shadowJar -Dorg.gradle.java.home=\"{path.sep.join(javabin.split(path.sep)[:-2])+path.sep}\"", shell=True, stdout=DEVNULL)
else:
run(("chmod", "+x", "gradlew"))
run(("./gradlew", "build"), stdout=DEVNULL)
run(f"./gradlew shadowJar -Dorg.gradle.java.home=\"{path.sep.join(javabin.split(path.sep)[:-2])+path.sep}\"", shell=True, stdout=DEVNULL)

pissjar = path.join(getcwd(), "build", "libs", "pissmc-all.jar")

chdir(instancedir)
makedirs("patches", exist_ok=True)
makedirs("libraries", exist_ok=True)


request.urlretrieve(f"https://raw.githubusercontent.com/Modern-Modpacks/PissMC/main/modloader/customjar.json", path.join("patches", "customjar.json"))
copy(pissjar, path.join("libraries", "customjar-1.jar"))

json = load(open("mmc-pack.json"))
json["components"].append({
"cachedName": "PissMC",
"uid": "customjar"
})
with open("mmc-pack.json", "w") as f: dump(json, f)
10 changes: 6 additions & 4 deletions installer/src/pissmc-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
channel.set(choices[0])
OptionMenu(inputs, channel, *choices).pack()
Label(inputs, text="Path to your \".minecraft\" folder (must be a multimc/prism instance):").pack()
mcdir = Text(inputs, height=1, width=70, wrap="none")
mcdir.pack()
mcdir.bind("<Return>", lambda _: "break")
mcdir = StringVar()
Entry(inputs, width=70, textvariable=mcdir).pack()
Label(inputs, text="Path to your Java binary (must be Java 8):").pack()
javabin = StringVar()
Entry(inputs, width=70, textvariable=javabin).pack()

Button(app, text="Submit", command=lambda: start_install(app, mcdir.get("1.0", END), channel.get().lower().split(" ")[0])).pack(side=BOTTOM, pady=10)
Button(app, text="Submit", command=lambda: start_install(app, mcdir.get(), javabin.get(), channel.get().lower().split(" ")[0])).pack(side=BOTTOM, pady=10)

try: app.mainloop()
except KeyboardInterrupt: exit(0)

0 comments on commit 6c5d944

Please sign in to comment.