diff --git a/.gitignore b/.gitignore index 9897e7a..7dd4336 100644 --- a/.gitignore +++ b/.gitignore @@ -290,3 +290,5 @@ tmp/ /out/ rc_res.py ui_form.py + +MinecraftLCEClient/ diff --git a/config.py b/config.py index 6ebf2fd..c0b3a9e 100644 --- a/config.py +++ b/config.py @@ -8,6 +8,14 @@ class Config (QSettings): super().setValue("instances/repo", url_str) super().sync() + def set_instance_exe_name(self, filename : str): + super().setValue("instances/filename", filename) + super().sync() + + def set_instance_archive(self, archive : str): + super().setValue("instances/archive", archive) + super().sync() + def set_instance_name(self, name : str): super().setValue("instances/name", name) super().sync() @@ -29,6 +37,12 @@ class Config (QSettings): def get_instance_name(self) -> str: return self.value("instances/name", "default") + + def get_instance_exe_name(self) -> str: + return self.value("instances/filename", "Minecraft.Client.exe") + + def get_instance_archive(self) -> str: + return self.value("instances/archive", "LCEWindows64.zip") def get_instance_version(self) -> str: return self.value("instances/version", "default") @@ -42,6 +56,8 @@ class Config (QSettings): def generate_default_config(self): self.set_instance_url("https://github.com/smartcmd/MinecraftConsoles") self.set_instance_name("default") + self.set_instance_exe_name("Minecraft.Client.exe") + self.set_instance_archive("LCEWindows64.zip") self.set_instance_version("nightly") self.set_profile_skin("default") self.set_profile_name("Steve") diff --git a/launcher.py b/launcher.py index 2f4407a..a6f0550 100644 --- a/launcher.py +++ b/launcher.py @@ -1,4 +1,5 @@ -# This Python file uses the following encoding: utf-8 +#!/usr/bin/env python3 + import sys from PySide6.QtWidgets import QApplication, QMainWindow @@ -7,13 +8,70 @@ from PySide6.QtGui import QPalette, QPixmap, QBrush from config import Config import webbrowser +import requests +import zipfile +import io +import os + +config = Config() + +LAUNCHER_REPO = "https://github.com/xgui4/LCE_QT_Launcher" + +LAUNCHER_STRING = config.get__instance_url() + \ + "/releases/download/" + \ + config.get_instance_version() + "/" + \ + config.get_instance_archive() + +SUCCESS_STATUS_CODE = 200 + +BACKGROUND_PIXMAP_IMG = ":/assets/assets/background.png" + +GEN_CONFIG_CMD_ARG = "--gen-config" +GEN_CONFIG_CMD_ARG_SHORT = "-g" + +VERSION_CMD_ARG = "--version" +VERSION_CMD_ARG_SHORT = "-v" + +LICENSE_CMD_ARG = "--license" +LICENSE_CMD_ARG_SHORT = "-L" + +ABOUT_CMD_ARG = "--about" +ABOUT_CMD_ARG_SHORT = "-a" + +HELP_CMD_ARG = "--help" +HELP_CMD_ARG_SHORT = "-h" + +VERSION = "0.0.0.1-pre-alpha" +DESCRIPTION = """ +This is a custom MCLCE Launcher written in python and Qt with Freedom +and GNU/Linux support in mind. +""" def launch(): config = Config() print(f"Lauching {config.get_instance_name()} {config.get_instance_version()}") + + print(f"Downloading {LAUNCHER_STRING}.") + + response = requests.get(LAUNCHER_STRING) + + if response.status_code == SUCCESS_STATUS_CODE: + try: + with zipfile.ZipFile(io.BytesIO(response.content)) as archive: + archive.extractall("./MinecraftLCEClient") + except zipfile.BadZipFile as err: + print(f"Error : {err}") + except zipfile.zipfile.LargeZipFile as err: + print(f"Error : {err}") + else: + client = f"./MinecraftLCEClient/{config.get_instance_exe_name}" + print(f"Launching {client}") + os.system(client) + else: + print(f"Error : {response.status_code} during the dowbloading of the Minecraft LCE Client") def update_page(): - webbrowser.open_new_tab("https://github.com/xgui4/LCE_QT_Launcher") + webbrowser.open_new_tab(LAUNCHER_REPO) # Important: # You need to run the following command to generate the ui_form.py file @@ -25,7 +83,7 @@ class launcher(QMainWindow): def __init__(self, parent=None): super().__init__(parent) - background_pixmap = QPixmap(":/assets/assets/background.png") + background_pixmap = QPixmap(BACKGROUND_PIXMAP_IMG) if not background_pixmap.isNull(): palette = self.palette() palette.setBrush(QPalette.ColorRole.Window, QBrush(background_pixmap)) @@ -42,10 +100,9 @@ class launcher(QMainWindow): self.ui.actionAbout.triggered.connect(self.createPopupMenu) - if __name__ == "__main__": if len(sys.argv) > 1: - if sys.argv[1] == "--gen-config": + if sys.argv[1] == GEN_CONFIG_CMD_ARG: config = Config() config.generate_default_config() else: diff --git a/pkg/LCE-Qt-Launcher.desktop b/pkg/LCE-Qt-Launcher.desktop new file mode 100644 index 0000000..c919138 --- /dev/null +++ b/pkg/LCE-Qt-Launcher.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=2.0 +Type=Application +Name=LCE Qt Launcher +Comment=This is a custom MCLCE Launcher written in python and Qt with Freedom and GNU/Linux support in mind. +Exec=/usr/bin/python3 ./laucher.py +Icon=Launcher.png +Terminal=True +StartupNotify=true +Categories=Utility;Minecraft;Launcher;Qt;Games;Python diff --git a/pyproject.toml b/pyproject.toml index 89d974a..9a9e279 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,16 @@ -[project] +[project] name = "LCE-Qt-Launcher" [tool.pyside6-project] files = [ - "config.py", + "config.py", "form.ui", - "launcher.py", - "license.md", - "readme.md", - "requirements.txt", - "res.qrc", - "setup.bat", - "setup.sh" + "launcher.py", + "license.md", + "pkg/LCE-Qt-Launcher.desktop", + "readme.md", + "requirements.txt", + "res.qrc", + "setup.bat", + "setup.sh", ] diff --git a/readme.md b/readme.md index e1bec86..2468f79 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,7 @@ ## About -This is a upcoming MCLCE Launcher written in python and Qt with Freedom -and GNU/Linux support in mind. +This is a custom MCLCE Launcher written in python and Qt with Freedom and GNU/Linux support in mind. ## License [GPLV3](license.md) diff --git a/requirements.txt b/requirements.txt index 7fa34f0..e7bdb3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ PySide6 +requests diff --git a/setup.bat b/setup.bat index 0eada11..3ebeadf 100644 --- a/setup.bat +++ b/setup.bat @@ -1 +1,3 @@ pyside6-uic form.ui -o ui_form.py + +python -m pip install -r requirement.txt diff --git a/setup.sh b/setup.sh index 0528a70..76efc6f 100755 --- a/setup.sh +++ b/setup.sh @@ -1,3 +1,5 @@ #!/usr/bin/sh pyside6-uic form.ui -o ui_form.py + +python -m pip install -r requirement.txt