-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfomod.py
147 lines (117 loc) · 5.65 KB
/
fomod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from pathlib import Path
import sys
from xml.etree import ElementTree
from PySide6.QtWidgets import QLabel, QRadioButton, QApplication
from PySide6.QtCore import Qt, QCoreApplication
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QLabel,QRadioButton, QGridLayout, QWizard, QWizardPage, QTextEdit
class FomodParser:
def __init__(self, mod_folder:Path):
self.mod_folder = mod_folder
self.fomod_file = Path(mod_folder) / 'fomod/ModuleConfig.xml'
xml = ElementTree.parse(self.fomod_file).getroot()
self.module_name = xml.findtext("./moduleName")
self.install_steps = [InstallSteps(x) for x in xml.findall("./installSteps")]
self.build_ui()
def build_ui(self):
self.ui = QWizard()
for install_steps_collection in self.install_steps:
for install_step in install_steps_collection.install_steps:
for optional_file_group in install_step.optional_file_groups:
for group in optional_file_group.groups:
new_page = QWizardPage()
new_layout = QGridLayout()
new_layout.addWidget(QLabel(group.name), 0, 0)
for plugin_collection in group.plugin_collection:
for i, plugin in enumerate(plugin_collection.plugins):
target_radio = QRadioButton(plugin.name)
new_layout.addWidget(target_radio, i+1, 0)
target_radio.toggled.connect(plugin.update)
new_layout.addWidget(QTextEdit(plugin.description), i+1, 1)
if plugin.image:
parsed_img = self.mod_folder / plugin.image.replace('\\', '/')
img = QPixmap(parsed_img)
test = QLabel()
test.setPixmap(img)
new_layout.addWidget(test, i+1, 2)
new_page.setTitle(install_step.name)
new_page.setLayout(new_layout)
self.ui.addPage(new_page)
final_page = QWizardPage()
self.finished = self.ui.button(QWizard.FinishButton)
final_page.setFinalPage(True)
self.ui.addPage(final_page)
def handle_results(self) -> dict:
tmp = {}
print("hanlding results")
for install_steps_collection in self.install_steps:
for i, install_step in enumerate(install_steps_collection.install_steps):
for optional_file_group in install_step.optional_file_groups:
for group in optional_file_group.groups:
for plugins_collection in group.plugin_collection:
for plugin in plugins_collection.plugins:
if plugin.enabled:
for files in plugin.files_collection:
print(plugin.enabled, group.name)
for folder in files.folders:
tmp[f"{str(i)}{group.name}"] = folder.to_dict()
return tmp
class InstallSteps:
def __init__(self, xml: ElementTree.Element):
self.order = xml.get("order")
self.install_steps = [InstallStep(x) for x in xml.findall("./installStep")]
class InstallStep:
def __init__(self, xml:ElementTree.Element):
self.name = xml.get("name")
self.optional_file_groups = [OptionalFileGroups(x) for x in xml.findall("./optionalFileGroups")]
class OptionalFileGroups:
def __init__(self, xml:ElementTree.Element):
self.order = xml.get("order")
self.groups = [Group(x) for x in xml.findall("./group")]
class Group:
def __init__(self, xml:ElementTree.Element):
self.name = xml.get("name")
self.type = xml.get("type")
self.plugin_collection = [Plugins(x) for x in xml.findall("./plugins")]
class Plugins:
def __init__(self, xml:ElementTree.Element):
self.name = xml.get("name")
self.description = xml.findtext("description")
self.plugins = [Plugin(x) for x in xml.findall("./plugin")]
class Plugin:
def __init__(self, xml:ElementTree.Element):
self.name = xml.get("name")
self.description = xml.findtext("description")
self.flags = [x.get("name") for x in xml.findall("./conditionFlags/flag")]
self.enabled = False
try:
self.image = xml.find("./image").get('path')
except AttributeError:
self.image = None
self.files_collection = [Files(x) for x in xml.findall("./files")]
def update(self, arg):
"""Update if the plugin is enabled or not."""
self.enabled = arg
class Files:
def __init__(self, xml:ElementTree.Element):
self.folders = [Folder(x) for x in xml.findall("./folder")]
class Folder:
def __init__(self, xml:ElementTree.Element):
self.source = xml.get("source")
self.destination = xml.get("destination")
self.priority = xml.get("priority")
def to_dict(self) -> dict:
"""Convert to a dictionary."""
return {
"source": self.source,
"destination": self.destination,
"priority": self.priority
}
if __name__ == "__main__":
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
app = QApplication(sys.argv)
payload = sys.argv[1]
parser = FomodParser(Path(payload))
parser.ui.show()
app.exec()
parser.handle_results()