mirror of
https://github.com/Luca1991/NDSFactory.git
synced 2026-02-04 05:36:15 +01:00
Implemented better error handling
This commit is contained in:
@@ -2,19 +2,18 @@
|
||||
#include "./../../mainwindow.h"
|
||||
|
||||
|
||||
bool MainWindow::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||
NFResult MainWindow::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs)
|
||||
{
|
||||
return ndsFactory.extractFatData(fatDataSectionPath, fatSectionPath, fntSectionPath, originalFatDataAddr, savePath, logFileIDs);
|
||||
}
|
||||
|
||||
bool MainWindow::patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath)
|
||||
NFResult MainWindow::patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.patchFat(loadPath, shiftSize, savePath);
|
||||
}
|
||||
|
||||
bool MainWindow::buildFatData(const std::string& fatDataDirPath, const std::string& originalFatPath, uint32_t fatDataAddr, const std::string& savePath)
|
||||
NFResult MainWindow::buildFatData(const std::string& fatDataDirPath, const std::string& originalFatPath, uint32_t fatDataAddr, const std::string& savePath)
|
||||
{
|
||||
if (!std::filesystem::exists(fatDataDirPath + "/_file_IDs.txt")) return false;
|
||||
return ndsFactory.buildFatData(fatDataDirPath, originalFatPath, fatDataAddr, savePath);
|
||||
}
|
||||
|
||||
@@ -55,14 +55,16 @@ void MainWindow::on_fatExtractorExtractBtn_clicked()
|
||||
"",
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if (!dirPath.isNull())
|
||||
extractFatData(ui->fatExtractorFatDataPathEdt->text().toStdString(),
|
||||
if (!dirPath.isNull()) {
|
||||
NFResult nfResult = extractFatData(ui->fatExtractorFatDataPathEdt->text().toStdString(),
|
||||
ui->fatExtractorFatPathEdt->text().toStdString(),
|
||||
ui->fatExtractorFntPathEdt->text().toStdString(),
|
||||
ui->fatExtractorOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16),
|
||||
dirPath.toStdString(),
|
||||
ui->fatExtractorSaveFileIDsCbx->isChecked()) ? QMessageBox::information(this, tr("NDSFactory"), tr("FAT files extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), tr("Error extracting FAT files!"));
|
||||
ui->fatExtractorSaveFileIDsCbx->isChecked());
|
||||
nfResult.result? QMessageBox::information(this, tr("NDSFactory"), tr("FAT files extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), nfResult.message.c_str());
|
||||
}
|
||||
|
||||
ui->fatExtractorExtractBtn->setEnabled(true);
|
||||
|
||||
@@ -99,9 +101,9 @@ void MainWindow::on_fatPatcherPatchFatBtn_clicked()
|
||||
else
|
||||
positionDiff = originalPos - newPos;
|
||||
|
||||
patchFat(ui->fatPatcherFatPathEdt->text().toStdString(), positionDiff, dirPath.toStdString())
|
||||
? QMessageBox::information(this, tr("NDSFactory"), tr("FAT patching completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), tr("Error patching FAT!"));
|
||||
NFResult nfResult = patchFat(ui->fatPatcherFatPathEdt->text().toStdString(), positionDiff, dirPath.toStdString());
|
||||
nfResult.result ? QMessageBox::information(this, tr("NDSFactory"), tr("FAT patching completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), nfResult.message.c_str());
|
||||
}
|
||||
|
||||
ui->fatPatcherPatchFatBtn->setEnabled(true);
|
||||
@@ -140,11 +142,14 @@ void MainWindow::on_fatBuilderBuildBtn_clicked()
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if (!dirPath.isNull())
|
||||
buildFatData(ui->fatBuilderFatDirPathEdt->text().toStdString(),
|
||||
ui->fatBuilderOriginalFatPathEdt->text().toStdString(),
|
||||
{
|
||||
NFResult nfResult = buildFatData(ui->fatBuilderFatDirPathEdt->text().toStdString(),
|
||||
ui->fatBuilderOriginalFatPathEdt->text().toStdString(),
|
||||
ui->fatBuilderFatAddrEdt->text().toUInt(nullptr, 16),
|
||||
dirPath.toStdString()) ? QMessageBox::information(this, tr("NDSFactory"), tr("fat_data.bin and fat.bin correctly built!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), tr("Error building FAT!"));
|
||||
dirPath.toStdString());
|
||||
nfResult.result? QMessageBox::information(this, tr("NDSFactory"), tr("fat_data.bin and fat.bin correctly built!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), nfResult.message.c_str());
|
||||
}
|
||||
|
||||
ui->fatBuilderOpenFatDataDirBtn->setEnabled(true);
|
||||
}
|
||||
@@ -102,17 +102,17 @@ void MainWindow::calcHeaderCrc16()
|
||||
ui->packerHeaderDataTable->model()->setData(headerCrcIndex, QString::number(ndsFactory.calcHeaderCrc16(romHeaderBuffer), 16), Qt::EditRole);
|
||||
}
|
||||
|
||||
bool MainWindow::writeHeader(const std::string& savePath)
|
||||
NFResult MainWindow::writeHeader(const std::string& savePath)
|
||||
{
|
||||
std::vector<char> romHeaderBuffer(sizeof(NDSHeader));
|
||||
NDSHeader* pRomHeader = reinterpret_cast<NDSHeader*>(romHeaderBuffer.data());
|
||||
|
||||
generateHeader(pRomHeader);
|
||||
|
||||
return ndsFactory.writeBytesToFile(romHeaderBuffer, savePath, 0, sizeof(NDSHeader));;
|
||||
return ndsFactory.writeBytesToFile(romHeaderBuffer, savePath, 0, sizeof(NDSHeader));
|
||||
}
|
||||
|
||||
bool MainWindow::writeHeaderPadding(char paddingType, const std::string& savePath)
|
||||
NFResult MainWindow::writeHeaderPadding(char paddingType, const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = sizeof(NDSHeader);
|
||||
uint32_t size = extractPackerHeaderTableData(NDSHeaderNames::ARM9RomAddress).toUInt(nullptr, 16) - startAddr;
|
||||
@@ -124,7 +124,7 @@ bool MainWindow::writeHeaderPadding(char paddingType, const std::string& savePat
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm9Bin(const std::string& savePath, bool isArm9FooterPresent)
|
||||
NFResult MainWindow::writeArm9Bin(const std::string& savePath, bool isArm9FooterPresent)
|
||||
{
|
||||
uint32_t size = extractPackerHeaderTableData(NDSHeaderNames::ARM9Size).toUInt(nullptr, 16);
|
||||
if (isArm9FooterPresent)
|
||||
@@ -137,7 +137,7 @@ bool MainWindow::writeArm9Bin(const std::string& savePath, bool isArm9FooterPres
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::writeArm9BinPadding(char paddingType, const std::string& savePath, bool isFooterPresent)
|
||||
NFResult MainWindow::writeArm9BinPadding(char paddingType, const std::string& savePath, bool isFooterPresent)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::ARM9RomAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM9Size).toUInt(nullptr, 16);
|
||||
@@ -160,7 +160,7 @@ bool MainWindow::writeArm9BinPadding(char paddingType, const std::string& savePa
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm9Overlay(const std::string& savePath)
|
||||
NFResult MainWindow::writeArm9Overlay(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedArm9OverlayPathEdt->text().toStdString(),
|
||||
@@ -169,7 +169,7 @@ bool MainWindow::writeArm9Overlay(const std::string& savePath)
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlaySize).toUInt(nullptr, 16));
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm9OverlayFiles(const std::string& savePath)
|
||||
NFResult MainWindow::writeArm9OverlayFiles(const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlayAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlaySize).toUInt(nullptr, 16);
|
||||
@@ -181,7 +181,7 @@ bool MainWindow::writeArm9OverlayFiles(const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm7Bin(const std::string& savePath)
|
||||
NFResult MainWindow::writeArm7Bin(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedArm7BinPathEdt->text().toStdString(),
|
||||
@@ -190,7 +190,7 @@ bool MainWindow::writeArm7Bin(const std::string& savePath)
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM7Size).toUInt(nullptr, 16));
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm7BinPadding(char paddingType, const std::string& savePath)
|
||||
NFResult MainWindow::writeArm7BinPadding(char paddingType, const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::ARM7RomAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM7Size).toUInt(nullptr, 16);
|
||||
@@ -207,7 +207,7 @@ bool MainWindow::writeArm7BinPadding(char paddingType, const std::string& savePa
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm7Overlay(const std::string& savePath)
|
||||
NFResult MainWindow::writeArm7Overlay(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedArm7OverlayPathEdt->text().toStdString(),
|
||||
@@ -216,7 +216,7 @@ bool MainWindow::writeArm7Overlay(const std::string& savePath)
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM7OverlaySize).toUInt(nullptr, 16));
|
||||
}
|
||||
|
||||
bool MainWindow::writeArm7OverlayFiles(const std::string& savePath)
|
||||
NFResult MainWindow::writeArm7OverlayFiles(const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::ARM7OverlayAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM7OverlaySize).toUInt(nullptr, 16);
|
||||
@@ -228,7 +228,7 @@ bool MainWindow::writeArm7OverlayFiles(const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeFnt(const std::string& savePath)
|
||||
NFResult MainWindow::writeFnt(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedFntPathEdt->text().toStdString(),
|
||||
@@ -237,7 +237,7 @@ bool MainWindow::writeFnt(const std::string& savePath)
|
||||
extractPackerHeaderTableData(NDSHeaderNames::FilenameTableSize).toUInt(nullptr, 16));
|
||||
}
|
||||
|
||||
bool MainWindow::writeFntPadding(char paddingType, const std::string& savePath)
|
||||
NFResult MainWindow::writeFntPadding(char paddingType, const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::FilenameTableAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::FilenameTableSize).toUInt(nullptr, 16);
|
||||
@@ -250,7 +250,7 @@ bool MainWindow::writeFntPadding(char paddingType, const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeFat(const std::string& savePath)
|
||||
NFResult MainWindow::writeFat(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedFatPathEdt->text().toStdString(),
|
||||
@@ -259,7 +259,7 @@ bool MainWindow::writeFat(const std::string& savePath)
|
||||
extractPackerHeaderTableData(NDSHeaderNames::FATSize).toUInt(nullptr, 16));
|
||||
}
|
||||
|
||||
bool MainWindow::writeFatPadding(char paddingType, const std::string& savePath)
|
||||
NFResult MainWindow::writeFatPadding(char paddingType, const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::FATAddress).toUInt(nullptr, 16) +
|
||||
extractPackerHeaderTableData(NDSHeaderNames::FATSize).toUInt(nullptr, 16);
|
||||
@@ -272,7 +272,7 @@ bool MainWindow::writeFatPadding(char paddingType, const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeIconTitle(const std::string& savePath)
|
||||
NFResult MainWindow::writeIconTitle(const std::string& savePath)
|
||||
{
|
||||
return ndsFactory.writeSectionToFile(
|
||||
ui->loadedIconTitlePathEdt->text().toStdString(),
|
||||
@@ -281,7 +281,7 @@ bool MainWindow::writeIconTitle(const std::string& savePath)
|
||||
IconTitleSize);
|
||||
}
|
||||
|
||||
bool MainWindow::writeFatFiles(const std::string& savePath)
|
||||
NFResult MainWindow::writeFatFiles(const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::IconTitleAddress).toUInt(nullptr, 16) + IconTitleSize;
|
||||
uint32_t size = extractPackerHeaderTableData(NDSHeaderNames::UsedRomSize).toUInt(nullptr, 16) - startAddr;
|
||||
@@ -293,7 +293,7 @@ bool MainWindow::writeFatFiles(const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeRomPadding(const std::string& savePath)
|
||||
NFResult MainWindow::writeRomPadding(const std::string& savePath)
|
||||
{
|
||||
uint32_t startAddr = extractPackerHeaderTableData(NDSHeaderNames::UsedRomSize).toUInt(nullptr, 16);
|
||||
uint32_t size = static_cast<uint32_t>(ndsFactory.getCardSizeInBytes(extractPackerHeaderTableData(NDSHeaderNames::CardSize).toInt())) - startAddr;
|
||||
@@ -305,9 +305,9 @@ bool MainWindow::writeRomPadding(const std::string& savePath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::writeEverything(const std::string& savePath)
|
||||
NFResult MainWindow::writeEverything(const std::string& savePath)
|
||||
{
|
||||
bool res = true;
|
||||
NFResult nfResult;
|
||||
char paddingType;
|
||||
bool isArm9FooterPresent = ndsFactory.checkArm9FooterPresence(ui->loadedArm9BinPathEdt->text().toStdString(),
|
||||
extractPackerHeaderTableData(NDSHeaderNames::ARM9Size).toUInt(nullptr, 16));
|
||||
@@ -318,32 +318,49 @@ bool MainWindow::writeEverything(const std::string& savePath)
|
||||
|
||||
std::remove(savePath.c_str());
|
||||
|
||||
res &= writeHeader(savePath);
|
||||
res &= writeHeaderPadding(paddingType, savePath);
|
||||
res &= writeArm9Bin(savePath, isArm9FooterPresent);
|
||||
res &= writeArm9BinPadding(paddingType, savePath, isArm9FooterPresent);
|
||||
nfResult = writeHeader(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeHeaderPadding(paddingType, savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeArm9Bin(savePath, isArm9FooterPresent);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeArm9BinPadding(paddingType, savePath, isArm9FooterPresent);
|
||||
if (!nfResult.result) return nfResult;
|
||||
if (extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlayAddress).toUInt(nullptr, 16) != 0)
|
||||
{
|
||||
res &= writeArm9Overlay(savePath);
|
||||
res &= writeArm9OverlayFiles(savePath);
|
||||
nfResult = writeArm9Overlay(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeArm9OverlayFiles(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
}
|
||||
res &= writeArm7Bin(savePath);
|
||||
res &= writeArm7BinPadding(paddingType, savePath);
|
||||
nfResult = writeArm7Bin(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeArm7BinPadding(paddingType, savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
if (extractPackerHeaderTableData(NDSHeaderNames::ARM7OverlayAddress).toUInt(nullptr, 16) != 0) {
|
||||
res &= writeArm7Overlay(savePath);
|
||||
res &= writeArm7OverlayFiles(savePath);
|
||||
nfResult = writeArm7Overlay(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeArm7OverlayFiles(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
}
|
||||
res &= writeFnt(savePath);
|
||||
res &= writeFntPadding(paddingType, savePath);
|
||||
res &= writeFat(savePath);
|
||||
res &= writeFatPadding(paddingType, savePath);
|
||||
res &= writeIconTitle(savePath);
|
||||
res &= writeFatFiles(savePath);
|
||||
nfResult = writeFnt(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeFntPadding(paddingType, savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeFat(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeFatPadding(paddingType, savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeIconTitle(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = writeFatFiles(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
if(!ui->packerTrimRomsCbx->isChecked())
|
||||
{
|
||||
res &= writeRomPadding(savePath);
|
||||
nfResult = writeRomPadding(savePath);
|
||||
if (!nfResult.result) return nfResult;
|
||||
}
|
||||
return res;
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
QString MainWindow::extractPackerHeaderTableData(int index)
|
||||
|
||||
@@ -16,13 +16,9 @@ void MainWindow::on_packerLoadHeaderBtn_clicked()
|
||||
QDir::currentPath(),
|
||||
"NDS Header (*.bin)");
|
||||
|
||||
if(headerPath.isNull())
|
||||
{
|
||||
QMessageBox::critical(this, tr("NDSFactory"), tr("Unable to open file!"));
|
||||
return;
|
||||
}
|
||||
if (headerPath.isNull()) return;
|
||||
|
||||
if (ndsFactory.loadRomHeader(headerPath.toStdString(), romHeader))
|
||||
if (ndsFactory.loadRomHeader(headerPath.toStdString(), romHeader).result)
|
||||
{
|
||||
pNDSHeader = reinterpret_cast<NDSHeader*>(romHeader.data());
|
||||
populatePackerSectionHeader(pNDSHeader);
|
||||
@@ -180,9 +176,11 @@ void MainWindow::on_packerBuildNDSRomBtn_clicked()
|
||||
"NDS ROM (*.nds)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
writeEverything(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDSFactory"), tr("Creation completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), tr("Error during the creation!"));
|
||||
|
||||
{
|
||||
NFResult nfResult = writeEverything(dirPath.toStdString());
|
||||
nfResult.result? QMessageBox::information(this, tr("NDSFactory"), tr("Creation completed!"))
|
||||
: QMessageBox::critical(this, tr("NDSFactory"), nfResult.message.c_str());
|
||||
}
|
||||
ui->packerBuildNDSRomBtn->setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ void MainWindow::disableExtractionButtons()
|
||||
ui->unpackerExtraGbx->setEnabled(false);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpHeader(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpHeader(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -60,7 +60,7 @@ bool MainWindow::dumpHeader(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::HeaderSize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm9Bin(const std::string& dirPath, bool dumpExtraBytes)
|
||||
NFResult MainWindow::dumpArm9Bin(const std::string& dirPath, bool dumpExtraBytes)
|
||||
{
|
||||
uint32_t size = ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9Size, 1).data().toString().toUInt(nullptr,16);
|
||||
if (dumpExtraBytes)
|
||||
@@ -72,7 +72,7 @@ bool MainWindow::dumpArm9Bin(const std::string& dirPath, bool dumpExtraBytes)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm7Bin(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpArm7Bin(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -81,7 +81,7 @@ bool MainWindow::dumpArm7Bin(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7Size, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpFnt(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpFnt(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -90,7 +90,7 @@ bool MainWindow::dumpFnt(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::FilenameTableSize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpFat(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpFat(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -99,7 +99,7 @@ bool MainWindow::dumpFat(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::FATSize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm9Overlay(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpArm9Overlay(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -108,7 +108,7 @@ bool MainWindow::dumpArm9Overlay(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlaySize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm9OverlayFiles(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpArm9OverlayFiles(const std::string& dirPath)
|
||||
{
|
||||
uint32_t startAddr = ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlayAddress, 1).data().toString().toUInt(nullptr, 16) +
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlaySize, 1).data().toString().toUInt(nullptr, 16);
|
||||
@@ -121,7 +121,7 @@ bool MainWindow::dumpArm9OverlayFiles(const std::string& dirPath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm7Overlay(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpArm7Overlay(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -130,7 +130,7 @@ bool MainWindow::dumpArm7Overlay(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlaySize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm7OverlayFiles(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpArm7OverlayFiles(const std::string& dirPath)
|
||||
{
|
||||
uint32_t startAddr = ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlayAddress, 1).data().toString().toUInt(nullptr, 16) +
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlaySize, 1).data().toString().toUInt(nullptr, 16);
|
||||
@@ -143,7 +143,7 @@ bool MainWindow::dumpArm7OverlayFiles(const std::string& dirPath)
|
||||
size);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpIconTitle(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpIconTitle(const std::string& dirPath)
|
||||
{
|
||||
return ndsFactory.dumpDataFromFile(
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
@@ -152,7 +152,7 @@ bool MainWindow::dumpIconTitle(const std::string& dirPath)
|
||||
ICON_TITLE_SIZE);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpFatFiles(const std::string& dirPath)
|
||||
NFResult MainWindow::dumpFatFiles(const std::string& dirPath)
|
||||
{
|
||||
uint32_t startAddr = ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::IconTitleAddress, 1).data().toString().toUInt(nullptr,16) + IconTitleSize ;
|
||||
uint32_t size = ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::UsedRomSize, 1).data().toString().toUInt(nullptr,16) - startAddr;
|
||||
@@ -165,23 +165,34 @@ bool MainWindow::dumpFatFiles(const std::string& dirPath)
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::dumpEverything(QString dirPath)
|
||||
NFResult MainWindow::dumpEverything(QString dirPath)
|
||||
{
|
||||
bool result = true;
|
||||
result &= dumpHeader(QDir::toNativeSeparators(dirPath+"/header.bin").toStdString());
|
||||
result &= dumpArm9Bin(QDir::toNativeSeparators(dirPath+"/arm9.bin").toStdString(), true);
|
||||
result &= dumpArm7Bin(QDir::toNativeSeparators(dirPath+"/arm7.bin").toStdString());
|
||||
result &= dumpFnt(QDir::toNativeSeparators(dirPath+"/fnt.bin").toStdString());
|
||||
result &= dumpFat(QDir::toNativeSeparators(dirPath+"/fat.bin").toStdString());
|
||||
NFResult nfResult;
|
||||
nfResult = dumpHeader(QDir::toNativeSeparators(dirPath + "/header.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpArm9Bin(QDir::toNativeSeparators(dirPath+"/arm9.bin").toStdString(), true);
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpArm7Bin(QDir::toNativeSeparators(dirPath+"/arm7.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpFnt(QDir::toNativeSeparators(dirPath+"/fnt.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpFat(QDir::toNativeSeparators(dirPath+"/fat.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
if(ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlayAddress, 1).data().toString().toUInt(nullptr,16) != 0) {
|
||||
result &= dumpArm9Overlay(QDir::toNativeSeparators(dirPath+"/a9ovr.bin").toStdString());
|
||||
result &= dumpArm9OverlayFiles(QDir::toNativeSeparators(dirPath+"/a9ovr_data.bin").toStdString());
|
||||
nfResult = dumpArm9Overlay(QDir::toNativeSeparators(dirPath+"/a9ovr.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpArm9OverlayFiles(QDir::toNativeSeparators(dirPath+"/a9ovr_data.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
}
|
||||
if(ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlayAddress, 1).data().toString().toUInt(nullptr,16) != 0) {
|
||||
result &= dumpArm7Overlay(QDir::toNativeSeparators(dirPath+"/a7ovr.bin").toStdString());
|
||||
result &= dumpArm7OverlayFiles(QDir::toNativeSeparators(dirPath+"/a7ovr_data.bin").toStdString());
|
||||
}
|
||||
result &= dumpIconTitle(QDir::toNativeSeparators(dirPath+"/itl.bin").toStdString());
|
||||
result &= dumpFatFiles(QDir::toNativeSeparators(dirPath+"/fat_data.bin").toStdString());
|
||||
return result;
|
||||
nfResult = dumpArm7Overlay(QDir::toNativeSeparators(dirPath+"/a7ovr.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpArm7OverlayFiles(QDir::toNativeSeparators(dirPath+"/a7ovr_data.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
}
|
||||
nfResult = dumpIconTitle(QDir::toNativeSeparators(dirPath+"/itl.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
nfResult = dumpFatFiles(QDir::toNativeSeparators(dirPath+"/fat_data.bin").toStdString());
|
||||
if (!nfResult.result) return nfResult;
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
@@ -17,12 +17,11 @@ void MainWindow::on_loadRomBtn_clicked()
|
||||
QDir::currentPath(),
|
||||
"NDS Rom (*.nds)");
|
||||
|
||||
if( !romPath.isNull() )
|
||||
{
|
||||
ui->loadedRomPath->setText(romPath.toUtf8());
|
||||
}
|
||||
if (romPath.isNull()) return;
|
||||
|
||||
if (ndsFactory.loadRomHeader(ui->loadedRomPath->text().toStdString(), romHeader))
|
||||
ui->loadedRomPath->setText(romPath.toUtf8());
|
||||
|
||||
if (ndsFactory.loadRomHeader(ui->loadedRomPath->text().toStdString(), romHeader).result)
|
||||
{
|
||||
pNDSHeader = reinterpret_cast<NDSHeader*>(romHeader.data());
|
||||
populateHeader(pNDSHeader);
|
||||
|
||||
Reference in New Issue
Block a user