2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-04-14 08:24:06 -04:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2023-07-08 10:33:12 -04:00
|
|
|
#include <QApplication>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QDesktopServices>
|
2023-10-12 19:04:19 -04:00
|
|
|
#include <QFileDialog>
|
2022-04-14 08:24:06 -04:00
|
|
|
#include <QHBoxLayout>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QMenuBar>
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2023-07-08 10:33:12 -04:00
|
|
|
#include "filepropertieswindow.h"
|
2023-09-23 15:45:38 -04:00
|
|
|
#include "filetreewindow.h"
|
2023-10-12 20:18:22 -04:00
|
|
|
#include "hexpart.h"
|
2023-07-08 10:33:12 -04:00
|
|
|
|
2023-10-12 20:30:17 -04:00
|
|
|
MainWindow::MainWindow(QString gamePath, GameData *data)
|
2023-10-10 18:22:38 -04:00
|
|
|
: NovusMainWindow()
|
|
|
|
, data(data)
|
2023-10-10 18:02:13 -04:00
|
|
|
{
|
2023-10-10 18:22:38 -04:00
|
|
|
setupMenubar();
|
2023-07-08 10:33:12 -04:00
|
|
|
|
2023-10-12 19:46:58 -04:00
|
|
|
auto dummyWidget = new QWidget();
|
|
|
|
setCentralWidget(dummyWidget);
|
|
|
|
|
|
|
|
auto layout = new QHBoxLayout();
|
|
|
|
dummyWidget->setLayout(layout);
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2023-10-12 20:30:17 -04:00
|
|
|
auto tree = new FileTreeWindow(gamePath, data);
|
2023-10-12 19:04:19 -04:00
|
|
|
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<const char *>(fileData.data), fileData.size);
|
|
|
|
}
|
|
|
|
});
|
2023-10-12 19:46:58 -04:00
|
|
|
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;
|
|
|
|
}
|
2022-04-14 08:24:06 -04:00
|
|
|
|
2023-10-12 20:18:22 -04:00
|
|
|
auto file = physis_gamedata_extract_file(data, path.toStdString().c_str());
|
|
|
|
|
2023-10-12 19:46:58 -04:00
|
|
|
// Add properties tab
|
2023-10-12 20:18:22 -04:00
|
|
|
auto propertiesWidget = new FilePropertiesWindow(path, file);
|
2023-10-12 19:46:58 -04:00
|
|
|
partHolder->addTab(propertiesWidget, QStringLiteral("Properties"));
|
2023-10-12 20:18:22 -04:00
|
|
|
|
|
|
|
auto hexWidget = new HexPart();
|
|
|
|
hexWidget->loadFile(file);
|
|
|
|
partHolder->addTab(hexWidget, QStringLiteral("Raw Hex"));
|
2022-04-14 08:24:06 -04:00
|
|
|
}
|