Commit a41d2165 authored by Canvas123's avatar Canvas123

Manhattan with RSC support only

parent e594c44e
......@@ -87,6 +87,8 @@ def unpack(rsc_name):
if ':\\' in file.path:
file.path = file.path.split('\\')[-1]
file.path = file.path.replace('\\', '/')
file_name = folder_name + '/' + file.path
os.makedirs(os.path.dirname(file_name), exist_ok=True)
......
from PyQt5 import QtCore, QtWidgets, QtGui
class AboutDialog(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi()
self.show()
def setupUi(self):
self.setObjectName("Dialog")
self.setWindowModality(QtCore.Qt.NonModal)
self.resize(480, 320)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
self.setSizePolicy(sizePolicy)
self.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
self.setSizeGripEnabled(False)
self.setModal(False)
self.buttonBox = QtWidgets.QDialogButtonBox(self)
self.buttonBox.setGeometry(QtCore.QRect(200, 280, 85, 28))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setCenterButtons(True)
self.buttonBox.setObjectName("buttonBox")
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(160, 10, 321, 231))
self.label.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label.setTextFormat(QtCore.Qt.AutoText)
self.label.setScaledContents(False)
self.label.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.label.setWordWrap(True)
self.label.setOpenExternalLinks(True)
self.label.setObjectName("label")
self.manhattan_logo = QtWidgets.QLabel(self)
self.manhattan_logo.setGeometry(QtCore.QRect(0, 10, 151, 171))
self.manhattan_logo.setObjectName("manhattan_logo")
pix = QtGui.QPixmap("images/manhattan_logo.png")
self.manhattan_logo.setPixmap(pix)
self.manhattan_logo.setScaledContents(True)
self.retranslateUi(self)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "About Manhattan"))
self.label.setText(_translate("Dialog",
"<html><head/><body><p><span style=\" font-style:italic;\">Mannhattan</span> is <span style=\" font-weight:600;\">BYOND</span>-reversial project of <span style=\" font-style:italic;\">Canvas123</span> and <span style=\" font-style:italic;\">ACCount.</span></p><p><span style=\" font-style:italic;\">To contact author: </span><a href=\"emailto:canvas123@protonmail.com\"><span style=\" text-decoration: underline; color:#0000ff;\">email</span></a></p></body></html>"))
......@@ -22,7 +22,7 @@ def showResources(path, list_widget: QListWidget):
except Exception as e:
error = QMessageBox()
error.critical(None, 'Error', e.__str__())
return
return False
list_widget.clear() # Remove items from widget
......@@ -34,3 +34,33 @@ def showResources(path, list_widget: QListWidget):
list_widget.addItem(item)
list_widget.sortItems()
return True
def loadDisassembled(path, list_widget: QListWidget):
... # TODO: Make this function working when finish with Krampus
def saveAll(folder_name, list_widget):
files = [[list_widget.item(index).data(Qt.DisplayRole), list_widget.item(index).data(Qt.UserRole)]\
for index in range(list_widget.count())]
for file in files:
if not file[0]:
continue
if ':\\' in file[0]:
file[0] = file[0].split('\\')[-1]
file[0] = file[0].replace('\\', '/')
file_name = folder_name + '/' + file[0]
os.makedirs(os.path.dirname(file_name), exist_ok=True)
try:
with open(file_name, 'wb') as f:
f.write(file[1])
except Exception as e:
logging.error(f'{e}, {file[0]}')
\ No newline at end of file
......@@ -3,9 +3,6 @@ from main_window import *
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
#MainWindow = QtWidgets.QWidget()
ui = KrampusQt()
ui.setupUi()
ui.show()
sys.exit(app.exec_())
......@@ -6,10 +6,13 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, qApp, QMenu, QApplication
from PyQt5.QtCore import Qt
from m2k_interface import *
from about_window import AboutDialog
import os
WindowName = "Manhattan Reversing Tool"
RSC = 0
DMB = 1
class KrampusQt(QtWidgets.QWidget):
......@@ -19,8 +22,11 @@ class KrampusQt(QtWidgets.QWidget):
self.opened = False
self.opened_type = None
def initUI(self):
...
self.initUi()
def initUi(self):
self.setupUi()
self.show()
def setupUi(self):
# Set QMainWindow name, modaily and size, window title
......@@ -46,7 +52,6 @@ class KrampusQt(QtWidgets.QWidget):
# Menu Bar
self.menuBar = QtWidgets.QMenuBar(self)
self.menuBarLayout.addWidget(self.menuBar)
self.openFile = ...
# Other objects
self.gridLayout = QtWidgets.QGridLayout() # Make layout
......@@ -95,20 +100,40 @@ class KrampusQt(QtWidgets.QWidget):
self.adjustSize()
def createActions(self):
# File menu
self.openFile = QtWidgets.QAction('Open file', self)
self.openFile.setShortcuts(QtGui.QKeySequence.Open)
self.openFile.setStatusTip('Open file to disassemble')
self.openFile.setToolTip('Open file to disassemble')
self.openFile.triggered.connect(self.openFileAction)
self.saveFile = QtWidgets.QAction("Save all", self)
self.saveFile.setShortcuts(QtGui.QKeySequence.SaveAs)
self.saveFile.setToolTip("Save all files to directory")
self.saveFile.setDisabled(True)
self.saveFile.triggered.connect(self.saveFileAction)
self.exitFile = QtWidgets.QAction("Exit", self)
self.exitFile.setShortcuts(QtGui.QKeySequence.Quit)
self.exitFile.setStatusTip('Exit application')
self.exitFile.setToolTip('Exit application')
self.exitFile.triggered.connect(self.exitFileAction)
# About menu
self.aboutHelp = QtWidgets.QAction("About", self)
self.aboutHelp.triggered.connect(self.aboutTriggered)
def createMenus(self):
menu = QtWidgets.QMenu("File", self)
menu.addAction(self.openFile)
self.menuBar.addMenu(menu)
self.fileMenu = QtWidgets.QMenu("File", self)
self.fileMenu.addAction(self.openFile)
self.fileMenu.addAction(self.saveFile)
self.fileMenu.addAction(self.exitFile)
self.helpMenu = QtWidgets.QMenu("Help", self)
self.helpMenu.addAction(self.aboutHelp)
self.menuBar.addMenu(self.fileMenu)
self.menuBar.addMenu(self.helpMenu)
def openFileAction(self):
filename, type_ = QtWidgets.QFileDialog.getOpenFileName(self,
......@@ -119,8 +144,30 @@ class KrampusQt(QtWidgets.QWidget):
if not filename:
return
if "rsc" in type_:
showResources(filename, self.ItemsList)
if "rsc" in type_ and showResources(filename, self.ItemsList):
self.filename = filename
self.opened = True
self.opened_type = RSC
elif "dmb" in type_ and loadDisassembled(filename, self.ItemsList):
self.filename = filename
self.opened = True
self.opened.type = RSC
if not self.saveFile.isEnabled():
self.saveFile.setEnabled(True)
def saveFileAction(self):
folder_name = QtWidgets.QFileDialog.getExistingDirectory(
self,
'Select target directory',
os.getcwd(),
QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks)
if self.opened_type == RSC:
saveAll(folder_name, self.ItemsList)
else:
... # TODO: When Krampus will be done implement
def ListItemDoubleClicked(self, item: QListWidgetItem):
......@@ -139,5 +186,11 @@ class KrampusQt(QtWidgets.QWidget):
item.setHidden(False)
def aboutTriggered(self):
dialog = AboutDialog(self)
dialog.exec_()
dialog.deleteLater()
def exitFileAction(self):
qApp.exit()
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>320</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>About Manhattan</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>false</bool>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>200</x>
<y>280</y>
<width>85</width>
<height>28</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>160</x>
<y>10</y>
<width>321</width>
<height>231</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Mannhattan&lt;/span&gt; is &lt;span style=&quot; font-weight:600;&quot;&gt;BYOND&lt;/span&gt;-reversial project of &lt;span style=&quot; font-style:italic;&quot;&gt;Canvas123&lt;/span&gt; and &lt;span style=&quot; font-style:italic;&quot;&gt;ACCount.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;To contact author: &lt;/span&gt;&lt;a href=&quot;emailto:canvas123@protonmail.com&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;email&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>151</width>
<height>171</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;
&lt;style&gt;
border-image:url(:/images/BYOND_logo.png);
&lt;/style&gt;
&lt;/html&gt;</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment