Skip to content

Commit 34c55dc

Browse files
committed
Update 0.4
Finally. Took long enough. Changelog will be made soon.
1 parent 764f684 commit 34c55dc

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

launcher.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from json import loads, dumps
44
from math import ceil
55
from os.path import abspath, exists
6-
from os import makedirs, listdir, startfile, chdir
6+
from os import makedirs, listdir, startfile, chdir, environ
77
from requests import get as reqGet
8-
from subprocess import Popen
8+
import subprocess
99
import sys
1010
import threading
1111
import shutil
@@ -16,7 +16,7 @@
1616
from PyQt5.QtWebEngineWidgets import QWebEngineView
1717
from PyQt5.QtCore import pyqtSlot, Qt, QUrl
1818
from PyQt5.QtGui import QIcon, QPixmap
19-
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QMessageBox, QDialog, QTabWidget, QComboBox, QScrollArea
19+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QMessageBox, QDialog, QTabWidget, QComboBox, QScrollArea, QVBoxLayout
2020

2121
class mainWindow(QWidget):
2222
guiElements = []
@@ -224,13 +224,19 @@ def launch(self):
224224
raise TypeError
225225
elif not username.isalnum():
226226
raise TypeError
227-
print("java " + launcherConfig["javaargs"] + " -Xms" + launcherConfig["minram"] + " -Xmx" + launcherConfig["maxram"] + " -cp \"" + config.MC_DIR + "/instances/" + currentInstance + "/bin/minecraft.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/jinput.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/lwjgl.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/lwjgl_util.jar\" " + "-Duser.home=\"" + config.MC_DIR + "/instances/" + currentInstance + "\" -Dminecraft.applet.targetDirectory=\"" + config.MC_DIR + "/instances/" + currentInstance + "\" -Djava.library.path=\"" + config.MC_DIR + "/instances/" + currentInstance + "/bin/natives\" net.minecraft.client.Minecraft " + self.loginBox.text())
228-
prc = Popen("java " + launcherConfig["javaargs"] + " -Xms" + launcherConfig["minram"] + " -Xmx" + launcherConfig["maxram"] + " -cp \"" + config.MC_DIR + "/instances/" + currentInstance + "/bin/minecraft.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/jinput.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/lwjgl.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/bin/lwjgl_util.jar\" " + "-Duser.home=\"" + config.MC_DIR + "/instances/" + currentInstance + "\" -Dminecraft.applet.targetDirectory=\"" + config.MC_DIR + "/instances/" + currentInstance + "\" -Djava.library.path=\"" + config.MC_DIR + "/instances/" + currentInstance + "/bin/natives\" net.minecraft.client.Minecraft " + self.loginBox.text())
227+
# This better damn well work.
228+
print(platform.platform())
229+
if platform.platform().startswith("Windows"):
230+
environ["APPDATA"] = config.MC_DIR + "/instances/" + currentInstance
231+
prc = subprocess.Popen("java " + launcherConfig["javaargs"] + " -Xms" + launcherConfig["minram"] + " -Xmx" + launcherConfig["maxram"] + " -cp \"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/minecraft.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/jinput.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl_util.jar\" " + "-Djava.library.path=\"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/natives\" net.minecraft.client.Minecraft " + self.loginBox.text(), env=dict(environ, APPDATA=config.MC_DIR + "/instances/" + currentInstance))
232+
elif platform.platform().startswith("Darwin"):
233+
prc = subprocess.Popen("java " + launcherConfig["javaargs"] + " -Xms" + launcherConfig["minram"] + " -Xmx" + launcherConfig["maxram"] + " -cp \"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/minecraft.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/jinput.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl_util.jar\" " + "-Djava.library.path=\"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/natives\" net.minecraft.client.Minecraft " + self.loginBox.text(), env=dict(environ, HOME=config.MC_DIR + "/instances/" + currentInstance))
234+
else:
235+
prc = subprocess.Popen("java " + launcherConfig["javaargs"] + " -Xms" + launcherConfig["minram"] + " -Xmx" + launcherConfig["maxram"] + " -cp \"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/minecraft.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/jinput.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl.jar;" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/lwjgl_util.jar\" " + "-Duser.home=\"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "\" -Dminecraft.applet.targetDirectory=\"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "\" -Djava.library.path=\"" + config.MC_DIR + "/instances/" + currentInstance + "/.minecraft" + "/bin/natives\" net.minecraft.client.Minecraft " + self.loginBox.text())
229236
launcherConfig["lastusedname"] = self.loginBox.text()
230237
utils.saveSettings(launcherConfig)
231238
except Exception as e:
232-
self.error(
233-
"Minecraft is unable to start. Make sure you have java and minecraft installed and an alphanumeric username set.")
239+
self.error("Minecraft is unable to start. Make sure you have java and minecraft installed and an alphanumeric username set.")
234240
traceback.print_exc()
235241

236242
def error(self, err):
@@ -329,37 +335,49 @@ def initUI(self):
329335
self.setWindowTitle(self.title)
330336
self.setGeometry(self.left, self.top, 480, 240)
331337
self.setFixedSize(self.size())
332-
#self.listInstances()
338+
self.listInstances()
333339
self.createButtons()
340+
self.createInput()
334341

335342
def listInstances(self):
336-
try:
337-
for widget in self.widgets:
343+
for widget in self.widgets:
344+
try:
338345
widget.deleteLater()
339-
except: pass
340-
341-
listBox = QVBoxLayout(self)
342-
self.setLayout(listBox)
343-
346+
except:pass
347+
self.widgets=[]
348+
box = QVBoxLayout(self)
349+
self.setLayout(box)
344350
scroll = QScrollArea(self)
345-
listBox.addWidget(scroll)
351+
box.addWidget(scroll)
346352
scroll.setWidgetResizable(True)
347353
scrollContent = QWidget(scroll)
348-
349354
scrollLayout = QVBoxLayout(scrollContent)
350355
scrollContent.setLayout(scrollLayout)
351-
for item in items:
352-
scrollLayout.addWidget(item)
356+
for instance in listdir(config.MC_DIR+"/instances"):
357+
widget = QPushButton(self, text="Delete " + instance + ".")
358+
widget.clicked.connect(lambda: utils.rmModpack(instance, widget, self))
359+
scrollLayout.addWidget(widget)
360+
self.widgets.append(widget)
353361
scroll.setWidget(scrollContent)
354362

355363
def createButtons(self):
356364
self.openDirButton = QPushButton("Open " + config.NAME + " Install Dir", self)
357-
self.openDirButton.resize(70, 22)
358-
self.openDirButton.move(20, 20)
359-
self.openDirButton.clicked.connect(self.installModpack)
365+
self.openDirButton.resize(150, 22)
366+
self.openDirButton.move(self.width()-155, 5)
367+
self.openDirButton.clicked.connect(self.openDir)
368+
369+
self.installModpackButton = QPushButton("Install Local Modpack", self)
370+
self.installModpackButton.resize(150, 22)
371+
self.installModpackButton.move(5, 5)
372+
self.installModpackButton.clicked.connect(self.installModpack)
373+
374+
def createInput(self):
375+
self.modpackZipDir = QLineEdit(self)
376+
self.modpackZipDir.resize(170, 22)
377+
self.modpackZipDir.move(155, 5)
360378

361379
def installModpack(self):
362-
utils.installModpack(utils.getModapackFS("D:\Downloads\LowMango Pack b1.7.3 (Feb 2019 Update).zip"))
380+
utils.installModpack(utils.getModapackFS(self.modpackZipDir.text()))
363381

364382
def openDir(self):
365383
path = config.MC_DIR

setup and compile.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ echo Creating venv.
1212
%pythonver% -m venv venv
1313

1414
echo Activating venv.
15-
venv\Scripts\activate & echo Adding dependencies. & pip install pyqt5 requests appdirs & echo Using pyinstaller. & pyinstaller -y -F -w -i "favicon.ico" --add-data "background.png";"." --add-data "logo.png";"." launcher.py & echo Complete! & PAUSE
15+
venv\Scripts\activate & echo Adding dependencies. & pip install pyqt5 requests appdirs & echo Using pyinstaller. & pyinstaller -y -F -w -i "favicon.ico" --add-data "background.png";"." --add-data "logo.png";"." --add-data "favicon.ico";"." launcher.py & echo Complete! & PAUSE

setup and compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ echo Adding dependencies.
1717
pip install pyqt5 requests appdirs
1818

1919
echo Using pyinstaller.
20-
pyinstaller -y -F -w -i "favicon.ico" --add-data "background.png":"." --add-data "logo.png":"." launcher.py
20+
pyinstaller -y -F -w -i "favicon.ico" --add-data "background.png":"." --add-data "logo.png":"." --add-data "favicon.ico":"." launcher.py
2121

2222
echo Complete!
2323
read -p "Press enter to continue..."

utils.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import urllib
1111
from distutils.dir_util import copy_tree, remove_tree
1212

13+
from PyQt5.QtWidgets import QMessageBox
14+
1315

1416
def resourcePath(relative_path):
1517
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
@@ -99,12 +101,15 @@ def getModpackURL(modpackURL):
99101

100102

101103
def getModapackFS(modpackDir):
102-
if not os.path.exists(config.MC_DIR+"/modpackzips/"):
103-
os.makedirs(config.MC_DIR+"/modpackzips/")
104-
modpackName = os.path.splitext(os.path.basename(modpackDir))[0]
105-
if os.path.exists(config.MC_DIR + "/modpackzips/" + modpackName + ".zip"):
106-
os.remove(config.MC_DIR + "/modpackzips/" + modpackName + ".zip")
107-
shutil.copy(modpackDir, config.MC_DIR + "/modpackzips/"+modpackName + ".zip")
104+
try:
105+
if not os.path.exists(config.MC_DIR+"/modpackzips/"):
106+
os.makedirs(config.MC_DIR+"/modpackzips/")
107+
modpackName = os.path.splitext(os.path.basename(modpackDir))[0]
108+
if os.path.exists(config.MC_DIR + "/modpackzips/" + modpackName + ".zip"):
109+
os.remove(config.MC_DIR + "/modpackzips/" + modpackName + ".zip")
110+
shutil.copy(modpackDir, config.MC_DIR + "/modpackzips/"+modpackName + ".zip")
111+
except:
112+
modpackName = "Error"
108113
return modpackName
109114

110115

@@ -130,22 +135,29 @@ def installModpack(modpackName):
130135
if not os.path.exists(config.MC_DIR + "/instances/" + modpackJsonName):
131136
os.makedirs(config.MC_DIR + "/instances/" + modpackJsonName)
132137

133-
copy_tree(config.MC_DIR + "/tmp/" + modpackName + "/.minecraft", config.MC_DIR + "/instances/" + modpackJsonName)
138+
copy_tree(config.MC_DIR + "/tmp/" + modpackName, config.MC_DIR + "/instances/" + modpackJsonName)
134139
print("Finding Readmes")
135-
files = [f for f in os.listdir(config.MC_DIR + "/tmp/" + modpackName) if os.path.isfile(config.MC_DIR + "/tmp/" + modpackName + "/" + f)]
140+
files = [f for f in os.listdir(config.MC_DIR + "/tmp/" + modpackName) if os.path.isfile(config.MC_DIR + "/instances/" + modpackJsonName + "/" + f)]
136141
try:
137142
for file in files:
138143
if (file.lower().__contains__("readme") or file.lower().__contains__("read me") or file.lower().__contains__("contains") or file.lower().__contains__("included")) and file.lower().endswith(".txt"):
139144
if sys.platform.startswith('darwin'):
140-
subprocess.call(('open', config.MC_DIR + "/tmp/" + modpackName + "/" + file))
145+
subprocess.call(('open', config.MC_DIR + "/instances/" + modpackJsonName + "/" + file))
141146
elif os.name == 'nt':
142-
os.startfile(config.MC_DIR + "/tmp/" + modpackName + "/" + file)
147+
os.startfile(config.MC_DIR + "/instances/" + modpackJsonName + "/" + file)
143148
elif os.name == 'posix':
144-
subprocess.call(('xdg-open', config.MC_DIR + "/tmp/" + modpackName + "/" + file))
149+
subprocess.call(('xdg-open', config.MC_DIR + "/instances/" + modpackJsonName + "/" + file))
145150
except Exception as e:
146151
print("There was a problem opening readmes.")
147152
print(e)
148153
remove_tree(config.MC_DIR + "/tmp/" + modpackName)
149154
except Exception as e:
150155
print("Modpack install failed. Try installing again.")
151156
print(e)
157+
158+
159+
def rmModpack(modpackName, widget, parent):
160+
confirm = QMessageBox.question(parent, "Are you sure?", "Are you sure?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
161+
if confirm == QMessageBox.Yes:
162+
remove_tree(config.MC_DIR + "/instances/" + modpackName)
163+
widget.deleteLater()

0 commit comments

Comments
 (0)