mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Qt: Add patching errors
This commit is contained in:
parent
66bcf384f3
commit
332fbcfff1
4 changed files with 51 additions and 6 deletions
|
@ -486,7 +486,7 @@ if(NOT BUILD_HYDRA_CORE)
|
||||||
qt_add_resources(AlberCore "app_images"
|
qt_add_resources(AlberCore "app_images"
|
||||||
PREFIX "/"
|
PREFIX "/"
|
||||||
FILES
|
FILES
|
||||||
docs/img/rsob_icon.png docs/img/rstarstruck_icon.png
|
docs/img/rsob_icon.png docs/img/rstarstruck_icon.png docs/img/rpog_icon.png
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp src/panda_sdl/mappings.cpp)
|
set(FRONTEND_SOURCE_FILES src/panda_sdl/main.cpp src/panda_sdl/frontend_sdl.cpp src/panda_sdl/mappings.cpp)
|
||||||
|
|
BIN
docs/img/rpog_icon.png
Normal file
BIN
docs/img/rpog_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
@ -13,6 +14,15 @@ class PatchWindow final : public QWidget {
|
||||||
~PatchWindow() = default;
|
~PatchWindow() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Show a message box
|
||||||
|
// Title: Title of the message box to display
|
||||||
|
// Message: Message to display
|
||||||
|
// Icon: The type of icon (error, warning, information, etc) to display
|
||||||
|
// IconPath: If non-null, then a path to an icon in our assets to display on the OK button
|
||||||
|
void displayMessage(
|
||||||
|
const QString& title, const QString& message, QMessageBox::Icon icon = QMessageBox::Icon::Warning, const char* iconPath = nullptr
|
||||||
|
);
|
||||||
|
|
||||||
std::filesystem::path inputPath = "";
|
std::filesystem::path inputPath = "";
|
||||||
std::filesystem::path patchPath = "";
|
std::filesystem::path patchPath = "";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#include "panda_qt/patch_window.hpp"
|
#include "panda_qt/patch_window.hpp"
|
||||||
|
|
||||||
|
#include <QAbstractButton>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QIcon>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -64,15 +66,20 @@ PatchWindow::PatchWindow(QWidget* parent) : QWidget(parent, Qt::Window) {
|
||||||
|
|
||||||
connect(applyPatchButton, &QPushButton::clicked, this, [this]() {
|
connect(applyPatchButton, &QPushButton::clicked, this, [this]() {
|
||||||
if (inputPath.empty() || patchPath.empty()) {
|
if (inputPath.empty() || patchPath.empty()) {
|
||||||
printf("Pls set paths properly");
|
displayMessage(tr("Paths not provided correctly"), tr("Please provide paths for both the input file and the patch file"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto path = QFileDialog::getSaveFileName(this, tr("Select file"), QString::fromStdU16String(inputPath.u16string()), tr("All files (*.*)"));
|
// std::filesystem::path only has += and not + for reasons unknown to humanity
|
||||||
|
auto defaultPath = inputPath.parent_path() / inputPath.stem();
|
||||||
|
defaultPath += "-patched";
|
||||||
|
defaultPath += inputPath.extension();
|
||||||
|
|
||||||
|
auto path = QFileDialog::getSaveFileName(this, tr("Select file"), QString::fromStdU16String(defaultPath.u16string()), tr("All files (*.*)"));
|
||||||
std::filesystem::path outputPath = std::filesystem::path(path.toStdU16String());
|
std::filesystem::path outputPath = std::filesystem::path(path.toStdU16String());
|
||||||
|
|
||||||
if (outputPath.empty()) {
|
if (outputPath.empty()) {
|
||||||
printf("Pls set paths properly");
|
displayMessage(tr("No output path"), tr("No path was provided for the output file, no patching was done"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +94,7 @@ PatchWindow::PatchWindow(QWidget* parent) : QWidget(parent, Qt::Window) {
|
||||||
} else if (extension == ".bps") {
|
} else if (extension == ".bps") {
|
||||||
patchType = Hips::PatchType::BPS;
|
patchType = Hips::PatchType::BPS;
|
||||||
} else {
|
} else {
|
||||||
printf("Unknown patch format\n");
|
displayMessage(tr("Unknown patch format"), tr("Unknown format for patch file. Currently IPS, UPS and BPS are supported"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +103,7 @@ PatchWindow::PatchWindow(QWidget* parent) : QWidget(parent, Qt::Window) {
|
||||||
IOFile patch(patchPath, "rb");
|
IOFile patch(patchPath, "rb");
|
||||||
|
|
||||||
if (!input.isOpen() || !patch.isOpen()) {
|
if (!input.isOpen() || !patch.isOpen()) {
|
||||||
printf("Failed to open input or patch file.\n");
|
displayMessage(tr("Failed to open input files"), tr("Make sure they're in a directory Panda3DS has access to"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,5 +126,33 @@ PatchWindow::PatchWindow(QWidget* parent) : QWidget(parent, Qt::Window) {
|
||||||
IOFile output(outputPath, "wb");
|
IOFile output(outputPath, "wb");
|
||||||
output.writeBytes(bytes.data(), bytes.size());
|
output.writeBytes(bytes.data(), bytes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case Hips::Result::Success:
|
||||||
|
displayMessage(
|
||||||
|
tr("Patching Success"), tr("Your file was patched successfully."), QMessageBox::Icon::Information, ":/docs/img/rpog_icon.png"
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Hips::Result::ChecksumMismatch:
|
||||||
|
displayMessage(
|
||||||
|
tr("Checksum mismatch"),
|
||||||
|
tr("Patch was applied successfully but a checksum mismatch was detected. The input or output files might not be correct")
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: displayMessage(tr("Patching error"), tr("An error occured while patching")); break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PatchWindow::PatchWindow::displayMessage(const QString& title, const QString& message, QMessageBox::Icon icon, const char* iconPath) {
|
||||||
|
QMessageBox messageBox(icon, title, message);
|
||||||
|
QAbstractButton* button = messageBox.addButton(tr("OK"), QMessageBox::ButtonRole::YesRole);
|
||||||
|
|
||||||
|
if (iconPath != nullptr) {
|
||||||
|
button->setIcon(QIcon(iconPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
messageBox.exec();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue