-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (64 loc) · 2.49 KB
/
app.py
File metadata and controls
83 lines (64 loc) · 2.49 KB
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
from os import path, access, W_OK
from converter.converter_3ds import Converter3DS
from converter.converter_wiiu import ConverterWiiU
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFormLayout, QFileDialog, QTextEdit, QMessageBox
class App():
def start(self):
app = QApplication([])
app.setStyle('Fusion')
self.app = app
self.window = QWidget()
self.window.setWindowTitle('MH3U Save Converter')
layout = QFormLayout()
loadSrcButton = QPushButton('Load save file')
loadSrcButton.clicked.connect(self.loadSrc)
self.srcPath = QTextEdit(self.window)
self.srcPath.setFixedHeight(24)
setOutputButton = QPushButton('Set output file')
setOutputButton.clicked.connect(self.setDst)
self.dstPath = QTextEdit(self.window)
self.dstPath.setFixedHeight(24)
convertButton = QPushButton('Convert')
convertButton.clicked.connect(self.convert)
layout.addRow(loadSrcButton, self.srcPath)
layout.addRow(setOutputButton, self.dstPath)
layout.addRow(convertButton)
self.window.setLayout(layout)
self.window.show()
app.exec()
def loadSrc(self):
filePath = QFileDialog.getOpenFileName(self.window, 'Load save file')
if filePath:
self.srcPath.setText(filePath[0])
def setDst(self):
filePath = QFileDialog.getSaveFileName(self.window, 'Set output file')
if filePath:
self.dstPath.setText(filePath[0])
def convert(self):
srcPath = self.srcPath.toPlainText()
dstPath = self.dstPath.toPlainText()
if not path.exists(srcPath):
return
inputSize = path.getsize(srcPath)
self.error = None
self.success = None
if inputSize == 0x8A00:
converter = ConverterWiiU(srcPath)
elif inputSize == 0x8A24:
converter = Converter3DS(srcPath)
else:
self.error = QMessageBox()
self.error.setText('Invalid save file')
if not access(path.dirname(dstPath), W_OK):
self.error = QMessageBox()
self.error.setText('Output path not writable')
if self.error:
self.error.show()
else:
converter.convert(dstPath)
self.success = QMessageBox()
self.success.setText('File converted successfully')
if self.success:
self.success.show()
if __name__ == '__main__':
App().start()