// SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later #include "mainwindow.h" #include #include #include #include #include #include "filepropertieswindow.h" #include "filetreewindow.h" #include "hexpart.h" MainWindow::MainWindow(QString gamePath, GameData *data) : NovusMainWindow() , data(data) { setupMenubar(); auto dummyWidget = new QWidget(); setCentralWidget(dummyWidget); auto layout = new QHBoxLayout(); dummyWidget->setLayout(layout); auto tree = new FileTreeWindow(gamePath, data); connect(tree, &FileTreeWindow::extractFile, this, [this, data](QString path) { const QFileInfo info(path); const QString savePath = QFileDialog::getSaveFileName(this, tr("Save File"), info.fileName(), QStringLiteral("*.%1").arg(info.completeSuffix())); if (!savePath.isEmpty()) { qInfo() << "Saving to" << savePath; std::string savePathStd = path.toStdString(); auto fileData = physis_gamedata_extract_file(data, savePathStd.c_str()); QFile file(savePath); file.open(QIODevice::WriteOnly); file.write(reinterpret_cast(fileData.data), fileData.size); } }); connect(tree, &FileTreeWindow::pathSelected, this, [=](QString path) { refreshParts(path); }); tree->setMaximumWidth(200); layout->addWidget(tree); partHolder = new QTabWidget(); partHolder->setMinimumWidth(800); partHolder->setMinimumHeight(720); layout->addWidget(partHolder); refreshParts({}); } void MainWindow::refreshParts(QString path) { partHolder->clear(); std::string pathStd = path.toStdString(); if (path.isEmpty() || !physis_gamedata_exists(data, pathStd.c_str())) { return; } auto file = physis_gamedata_extract_file(data, path.toStdString().c_str()); // Add properties tab auto propertiesWidget = new FilePropertiesWindow(path, file); partHolder->addTab(propertiesWidget, QStringLiteral("Properties")); auto hexWidget = new HexPart(); hexWidget->loadFile(file); partHolder->addTab(hexWidget, QStringLiteral("Raw Hex")); }