Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b81329950 | |||
68e9f57d22 | |||
ba54082b60 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,4 @@
|
|||||||
venv
|
venv
|
||||||
.idea
|
.idea
|
||||||
logs
|
|
||||||
|
|
||||||
*.jar
|
*.jar
|
||||||
*.log
|
|
73
GlowstoneBlock.py
Normal file
73
GlowstoneBlock.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QTreeView
|
||||||
|
from PyQt5.Qt import QStandardItemModel, QStandardItem
|
||||||
|
from PyQt5.QtCore import pyqtSlot, QAbstractListModel
|
||||||
|
import json
|
||||||
|
|
||||||
|
import GlowstoneDust
|
||||||
|
|
||||||
|
|
||||||
|
class App(QMainWindow):
|
||||||
|
|
||||||
|
def __init__(self, target_dir='.'):
|
||||||
|
super().__init__()
|
||||||
|
self.title = 'Project Glowstone: Block Edition'
|
||||||
|
self.left = 300
|
||||||
|
self.top = 300
|
||||||
|
self.width = 640
|
||||||
|
self.height = 480
|
||||||
|
self.target_dir = target_dir
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui(self):
|
||||||
|
self.setWindowTitle(self.title)
|
||||||
|
self.setGeometry(self.left, self.top, self.width, self.height)
|
||||||
|
|
||||||
|
self.treeView = QTreeView()
|
||||||
|
self.treeView.setHeaderHidden(True)
|
||||||
|
|
||||||
|
self.update_modlist(list(GlowstoneDust.get_modpack_info(self.target_dir)))
|
||||||
|
|
||||||
|
self.statusBar().showMessage('Message')
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
def update_modlist(self, modlist=None):
|
||||||
|
self.treeModel = QStandardItemModel()
|
||||||
|
self.rootNode = self.treeModel.invisibleRootItem()
|
||||||
|
|
||||||
|
self.modlist = modlist or []
|
||||||
|
print(json.dumps(self.modlist, indent=4))
|
||||||
|
|
||||||
|
mc = QStandardItem('Minecraft')
|
||||||
|
mc.setEditable(False)
|
||||||
|
self.rootNode.appendRow(mc)
|
||||||
|
|
||||||
|
for mod in self.modlist:
|
||||||
|
mod_row = QStandardItem(mod['modid'])
|
||||||
|
for dependant_mod in mod.get('dependencies', []):
|
||||||
|
if dependant_mod is dict:
|
||||||
|
mod_row.appendRow(QStandardItem(dependant_mod.get('modid')))
|
||||||
|
else:
|
||||||
|
mod_row.appendRow(QStandardItem(dependant_mod))
|
||||||
|
mc.appendRow(mod_row)
|
||||||
|
|
||||||
|
self.treeView.setModel(self.treeModel)
|
||||||
|
self.treeView.expandAll()
|
||||||
|
self.setCentralWidget(self.treeView)
|
||||||
|
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def on_click(self):
|
||||||
|
print('PyQt5 button click')
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def make_tree(self):
|
||||||
|
print("Making mod tree...")
|
||||||
|
modpack_info = GlowstoneDust.get_modpack_info('.')
|
||||||
|
print(json.dumps(modpack_info))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
ex = App(target_dir=r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
||||||
|
sys.exit(app.exec_())
|
@ -1,59 +1,50 @@
|
|||||||
import zipfile
|
import zipfile
|
||||||
import json
|
import json
|
||||||
import shutil
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import minecraft_launcher_lib
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
# action plan for final product:
|
def get_mod_info(target_file):
|
||||||
# 1) Get a list of mod jars from a directory
|
with zipfile.ZipFile(target_file) as z:
|
||||||
# 2) Install appropriate version of minecraft if it is not already installed
|
info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
|
||||||
# 3) Install appropriate version of minecraft forge if it is not already installed
|
rtn_json = json.loads(z.read(info_files[0]))[0]
|
||||||
# 4) Launch empty version of minecraft forge to generate boilerplate file structure
|
rtn_json['path'] = target_file
|
||||||
# 5) Exit the process after it launches successfully
|
return rtn_json
|
||||||
# 6) For each Jar:
|
|
||||||
# a) Copy jar to directory
|
|
||||||
# b) Attempt to launch the game
|
|
||||||
# c) Record whether or not the game successfully launched/built/etc
|
|
||||||
# d) If the game failed to launch, mark the jar as disabled
|
|
||||||
# e) Continue to next jar
|
|
||||||
|
|
||||||
def get_mod_list(target_dir: Path):
|
|
||||||
for f in target_dir.glob("*.jar"):
|
|
||||||
yield f
|
|
||||||
|
|
||||||
|
|
||||||
def setup_minecraft(target_version: str, target_path: Path):
|
def get_modpack_info(target_dir):
|
||||||
# install vanilla minecraft version if not installed
|
for f in os.scandir(target_dir):
|
||||||
# install forge minecraft version if not installed
|
if f.is_file():
|
||||||
pass
|
if '.jar' in f.name.lower():
|
||||||
|
try:
|
||||||
|
yield get_mod_info(f.path)
|
||||||
|
except (KeyError, IndexError) as e:
|
||||||
|
logging.warning(f'There is no .info in the file {f.name}!')
|
||||||
|
logging.debug(f"{e}")
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
logging.warning(f"The file {f.name} has a corrupted or malformed .info file - skipping!")
|
||||||
|
except BaseException as e:
|
||||||
|
logging.fatal(f"While parsing file {f.name}, encountered the following error: {e}")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def launch_minecraft(target_version: str, target_path: Path):
|
def main(directory='.'):
|
||||||
# launch minecraft forge
|
modpack_info = list(get_modpack_info(directory))
|
||||||
pass
|
root_mods = [mp for mp in modpack_info if not mp.get('dependencies')]
|
||||||
|
# print(json.dumps(modpack_info, indent=2))
|
||||||
|
# print(json.dumps(root_mods, indent=4))
|
||||||
|
dependant_mods = [mp for mp in modpack_info if mp.get('dependencies')]
|
||||||
|
|
||||||
|
mod_tree = []
|
||||||
|
for root_mod in root_mods:
|
||||||
|
mod_tree.append({
|
||||||
|
root_mod['modid']: [mod['modid'] for mod in dependant_mods if root_mod['modid'] in mod['dependencies']]
|
||||||
|
})
|
||||||
|
|
||||||
def test_mods(target_version: str, target_path: Path, modpack_path: Path):
|
print(json.dumps(mod_tree, indent=4))
|
||||||
for mod in get_mod_list(modpack_path):
|
|
||||||
shutil.copyfile(mod, target_path)
|
|
||||||
try:
|
|
||||||
logging.info(f"Adding mod {mod.name} to instance and launching...")
|
|
||||||
launch_minecraft(target_version, target_path)
|
|
||||||
logging.info(f"Mod {mod.name} passed!")
|
|
||||||
except BaseException as e:
|
|
||||||
# if forge failed to launch, disable the mod
|
|
||||||
logging.warning(f"Minecraft failed to launch with mod {mod} added, disabling.\n"
|
|
||||||
f"Returned error was: {e}")
|
|
||||||
shutil.move(target_path / mod.name, target_path / f"{mod.name}.disabled")
|
|
||||||
finally:
|
|
||||||
logging.debug(f"Test for {mod.name} completed, moving to next mod file...")
|
|
||||||
logging.info(f"Testing completed! Any mods that caused failures were marked as .disabled in the directory.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
main(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
||||||
# main(Path(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods"))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user