Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b81329950 | |||
68e9f57d22 | |||
ba54082b60 |
@ -1,50 +1,73 @@
|
|||||||
import zipfile
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
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
|
||||||
|
|
||||||
|
|
||||||
def get_mod_info(target_file):
|
class App(QMainWindow):
|
||||||
with zipfile.ZipFile(target_file) as z:
|
|
||||||
info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
|
def __init__(self, target_dir='.'):
|
||||||
rtn_json = json.loads(z.read(info_files[0]))[0]
|
super().__init__()
|
||||||
rtn_json['path'] = target_file
|
self.title = 'Project Glowstone: Block Edition'
|
||||||
return rtn_json
|
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)
|
||||||
|
|
||||||
|
|
||||||
def get_modpack_info(target_dir):
|
@pyqtSlot()
|
||||||
for f in os.scandir(target_dir):
|
def on_click(self):
|
||||||
if f.is_file():
|
print('PyQt5 button click')
|
||||||
if '.jar' in f.name.lower():
|
|
||||||
try:
|
@pyqtSlot()
|
||||||
yield get_mod_info(f.path)
|
def make_tree(self):
|
||||||
except (KeyError, IndexError) as e:
|
print("Making mod tree...")
|
||||||
logging.warning(f'There is no .info in the file {f.name}!')
|
modpack_info = GlowstoneDust.get_modpack_info('.')
|
||||||
logging.debug(f"{e}")
|
print(json.dumps(modpack_info))
|
||||||
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 main(directory='.'):
|
if __name__ == '__main__':
|
||||||
modpack_info = list(get_modpack_info(directory))
|
app = QApplication(sys.argv)
|
||||||
root_mods = [mp for mp in modpack_info if not mp.get('dependencies')]
|
ex = App(target_dir=r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
||||||
# print(json.dumps(modpack_info, indent=2))
|
sys.exit(app.exec_())
|
||||||
# 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']]
|
|
||||||
})
|
|
||||||
|
|
||||||
print(json.dumps(mod_tree, indent=4))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
|
||||||
main(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
|
||||||
|
50
GlowstoneDust.py
Normal file
50
GlowstoneDust.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import zipfile
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
def get_mod_info(target_file):
|
||||||
|
with zipfile.ZipFile(target_file) as z:
|
||||||
|
info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
|
||||||
|
rtn_json = json.loads(z.read(info_files[0]))[0]
|
||||||
|
rtn_json['path'] = target_file
|
||||||
|
return rtn_json
|
||||||
|
|
||||||
|
|
||||||
|
def get_modpack_info(target_dir):
|
||||||
|
for f in os.scandir(target_dir):
|
||||||
|
if f.is_file():
|
||||||
|
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 main(directory='.'):
|
||||||
|
modpack_info = list(get_modpack_info(directory))
|
||||||
|
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']]
|
||||||
|
})
|
||||||
|
|
||||||
|
print(json.dumps(mod_tree, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
||||||
|
main(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