This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSE.py
142 lines (124 loc) · 5.92 KB
/
SSE.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
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMessageBox, QMainWindow
from yaml import full_load as loadyaml
from os import environ, path, listdir
from datetime import datetime
from shutil import copytree
from time import ctime as tCtime
import xml.etree.ElementTree as ET
import sys
import gui
class MainForm(QMainWindow, gui.Ui_mainWindow):
"""Создание графического интерфейса.
Args:
QMainWindow: Главное окно программы
gui: Конфигурация окна
"""
def __init__(self) -> None:
super().__init__()
self.setupUi(self)
self.setWindowIcon(QIcon(path.join(path.dirname(__file__), 'imgs/SSE_icon.ico')))
self.saveButton.setIcon(QIcon(path.join(path.dirname(__file__), 'imgs/save_icon_16.ico')))
self.savesLabel.setText(self.getPaths()[0])
self.savesCombo.currentIndexChanged.connect(self.saveChangeSig)
self.saveButton.clicked.connect(self.rewriteSave)
self.statusBar.showMessage(f'v.: {buildInfo()[0]}, by {buildInfo()[1]} ({buildInfo()[2]})')
def getPaths(self) -> list:
"""Определяет основные пути до сохранения.
Returns:
list: Список путей c директорией сохранения и до самого файла world.xml
"""
self.myDocsPath = environ.get('USERPROFILE')
self.savePath = f'{self.myDocsPath}\\Documents\\My Games\\Stationeers\\saves'
self.saveWorld = f'{self.savePath}\\{self.savesCombo.currentText()}\\world.xml'
self.saveWorldS = f'{self.savePath}\\{self.savesCombo.currentText()}\\worldsettings.xml'
return self.savePath, self.saveWorld, self.saveWorldS
def getXML(self) -> list:
"""Парсит XML конфиг.
Returns:
list: Список с деревом XML и с корневым элементом
"""
worldXMLTree = ET.parse(self.saveWorld)
worldRootNode = worldXMLTree.getroot()
worldSXMLTree = ET.parse(self.saveWorldS)
worldSRootNode = worldSXMLTree.getroot()
return worldXMLTree, worldRootNode, worldSXMLTree, worldSRootNode
def saveChangeSig(self) -> None:
"""Обработка события смены редактируемого сейва.
"""
self.dateModifLabel.setText(tCtime(path.getmtime(self.getPaths()[1])))
w_rootNode = self.getXML()[1]
ws_rootNode = self.getXML()[3]
self.fillwRoot(w_rootNode)
self.fillwsRoot(ws_rootNode)
def fillwRoot(self, w_rootNode) -> None:
"""Заполняет дерево world.xml
Args:
w_rootNode: Корневой список XML
"""
for element in w_rootNode:
if str(element.tag) == 'ResearchKey':
self.researchCombo.setCurrentText(element.text)
elif str(element.tag) == 'DaysPast':
self.daysPastText.setText(element.text)
elif str(element.tag) == 'WorldName':
self.worldNameText.setText(element.text)
def fillwsRoot(self, ws_rootNode) -> None:
"""Заполняет дерево worldsettings.xml
Args:
ws_rootNode: Корневой список XML
"""
for element in ws_rootNode:
if str(element.tag) == 'Gravity':
self.gravityText.setText(element.text)
elif str(element.tag) == 'HungerRate':
self.hungerRateText.setText(element.text)
elif str(element.tag) == 'SolarScale':
self.solarScaleText.setText(element.text)
elif str(element.tag) == 'RotatingSky':
self.rotatingSkyBox.setCurrentText(element.text)
def rewriteSave(self) -> None:
"""Обработка сохранения отредактированного сейва.
"""
wXMLTree = self.getXML()[0]
wXMLTree.find('.//ResearchKey').text = self.researchCombo.currentText()
wXMLTree.find('.//DaysPast').text = self.daysPastText.text()
wXMLTree.find('.//WorldName').text = self.worldNameText.text()
wsXMLTree = self.getXML()[2]
wsXMLTree.find('.//Gravity').text = self.gravityText.text()
wsXMLTree.find('.//HungerRate').text = self.hungerRateText.text()
wsXMLTree.find('.//SolarScale').text = self.solarScaleText.text()
wsXMLTree.find('.//RotatingSky').text = self.rotatingSkyBox.currentText()
dateformat = '%Y_%m_%d_%H_%M_%S'
if self.backupCheck.isChecked():
copytree(f'{self.getPaths()[0]}\\{self.savesCombo.currentText()}',
f'{self.getPaths()[0]}\\{self.savesCombo.currentText()}_{datetime.now().strftime(dateformat)}')
wXMLTree.write(self.saveWorld)
wsXMLTree.write(self.saveWorldS)
msgbox('Save File modified!')
def msgbox(mText: str) -> None:
"""Вызывает информационное окно с результатом операции.
Args:
mText (string): Строка для отображения во всплывающем окне
"""
mBox = QMessageBox()
mBox.setWindowTitle('Info')
mBox.setText(mText)
mBox.setIcon(QMessageBox.Information)
mBox.exec_()
def buildInfo() -> list:
"""Выводит информацию о версии в статусбаре.
Returns:
list: Список данных о версии и авторе
"""
with open(path.join(path.dirname(__file__), 'config.yaml'), 'r') as config:
progAbout = loadyaml(config)
return progAbout['main']['version'], progAbout['main']['author'], progAbout['main']['authorlink']
if __name__ == '__main__':
app = QApplication(sys.argv)
form = MainForm()
form.show()
for i in (listdir(form.savePath)):
if path.isdir(f'{form.savePath}\\{i}'):
form.savesCombo.addItem(str(i))
app.exec()