From 0947e941b83b23b701edb31345c119f14e5ad56f Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sat, 8 Jul 2023 16:17:30 -0400 Subject: Modest cleanups for DSi_NAND (#1714) * Add a definition for TMD files * Wrap TitleMetadata in a namespace * Add a comment * Remove TitleMetadataCertificate - melonDS ignores it anyway * Refactor the use of title metadata - Move bitwise operations on the title ID into helper methods - Use TitleMetadata objects instead of pointers to raw data * Slight cleanup in DSi_NAND - Replace some constants with sizeof - Use an NDSHeader object instead of a raw array of bytes * Add a DSi_NAND::ImportFile overload that loads a file from memory * Split most of ImportTitle into InitTitleFileStructure - It will be reused in the next commit * Add ability to import title from memory * Fix another potential issue * Fix broken DSiWare installation - The bytes of the title ID/category were being swapped in most places, but not all * Add some logging calls * Declare array sizes in DSi_TMD in decimal, not hex * Add a space after the #endif - To adhere to the style guide * Assert the size of TitleMetadataContent * Change the type of SignatureName * Don't mark the TMD structs as packed * Remove extraneous comments * Cut down some newlines --- src/frontend/qt_sdl/TitleManagerDialog.cpp | 20 ++++++++++---------- src/frontend/qt_sdl/TitleManagerDialog.h | 8 +++++--- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/frontend/qt_sdl') diff --git a/src/frontend/qt_sdl/TitleManagerDialog.cpp b/src/frontend/qt_sdl/TitleManagerDialog.cpp index 72d19ec..3d52bdd 100644 --- a/src/frontend/qt_sdl/TitleManagerDialog.cpp +++ b/src/frontend/qt_sdl/TitleManagerDialog.cpp @@ -176,7 +176,7 @@ void TitleManagerDialog::done(int r) void TitleManagerDialog::on_btnImportTitle_clicked() { - TitleImportDialog* importdlg = new TitleImportDialog(this, importAppPath, importTmdData, importReadOnly); + TitleImportDialog* importdlg = new TitleImportDialog(this, importAppPath, &importTmdData, importReadOnly); importdlg->open(); connect(importdlg, &TitleImportDialog::finished, this, &TitleManagerDialog::onImportTitleFinished); @@ -188,8 +188,8 @@ void TitleManagerDialog::onImportTitleFinished(int res) if (res != QDialog::Accepted) return; u32 titleid[2]; - titleid[0] = (importTmdData[0x18C] << 24) | (importTmdData[0x18D] << 16) | (importTmdData[0x18E] << 8) | importTmdData[0x18F]; - titleid[1] = (importTmdData[0x190] << 24) | (importTmdData[0x191] << 16) | (importTmdData[0x192] << 8) | importTmdData[0x193]; + titleid[0] = importTmdData.GetCategory(); + titleid[1] = importTmdData.GetID(); // remove anything that might hinder the install DSi_NAND::DeleteTitle(titleid[0], titleid[1]); @@ -381,7 +381,7 @@ void TitleManagerDialog::onExportTitleData() } -TitleImportDialog::TitleImportDialog(QWidget* parent, QString& apppath, u8* tmd, bool& readonly) +TitleImportDialog::TitleImportDialog(QWidget* parent, QString& apppath, const DSi_TMD::TitleMetadata* tmd, bool& readonly) : QDialog(parent), ui(new Ui::TitleImportDialog), appPath(apppath), tmdData(tmd), readOnly(readonly) { ui->setupUi(this); @@ -440,12 +440,12 @@ void TitleImportDialog::accept() return; } - fread(tmdData, 0x208, 1, f); + fread((void *) tmdData, sizeof(DSi_TMD::TitleMetadata), 1, f); fclose(f); u32 tmdtitleid[2]; - tmdtitleid[0] = (tmdData[0x18C] << 24) | (tmdData[0x18D] << 16) | (tmdData[0x18E] << 8) | tmdData[0x18F]; - tmdtitleid[1] = (tmdData[0x190] << 24) | (tmdData[0x191] << 16) | (tmdData[0x192] << 8) | tmdData[0x193]; + tmdtitleid[0] = tmdData->GetCategory(); + tmdtitleid[1] = tmdData->GetID(); if (tmdtitleid[1] != titleid[0] || tmdtitleid[0] != titleid[1]) { @@ -507,11 +507,11 @@ void TitleImportDialog::tmdDownloaded() } else { - netreply->read((char*)tmdData, 520); + netreply->read((char*)tmdData, sizeof(*tmdData)); u32 tmdtitleid[2]; - tmdtitleid[0] = (tmdData[0x18C] << 24) | (tmdData[0x18D] << 16) | (tmdData[0x18E] << 8) | tmdData[0x18F]; - tmdtitleid[1] = (tmdData[0x190] << 24) | (tmdData[0x191] << 16) | (tmdData[0x192] << 8) | tmdData[0x193]; + tmdtitleid[0] = tmdData->GetCategory(); + tmdtitleid[1] = tmdData->GetID(); if (tmdtitleid[1] != titleid[0] || tmdtitleid[0] != titleid[1]) { diff --git a/src/frontend/qt_sdl/TitleManagerDialog.h b/src/frontend/qt_sdl/TitleManagerDialog.h index cba7047..fc92fd8 100644 --- a/src/frontend/qt_sdl/TitleManagerDialog.h +++ b/src/frontend/qt_sdl/TitleManagerDialog.h @@ -29,6 +29,8 @@ #include #include +#include "DSi_TMD.h" + namespace Ui { class TitleManagerDialog; @@ -90,7 +92,7 @@ private: Ui::TitleManagerDialog* ui; QString importAppPath; - u8 importTmdData[0x208]; + DSi_TMD::TitleMetadata importTmdData; bool importReadOnly; QAction* actImportTitleData[3]; @@ -104,7 +106,7 @@ class TitleImportDialog : public QDialog Q_OBJECT public: - explicit TitleImportDialog(QWidget* parent, QString& apppath, u8* tmd, bool& readonly); + explicit TitleImportDialog(QWidget* parent, QString& apppath, const DSi_TMD::TitleMetadata* tmd, bool& readonly); ~TitleImportDialog(); private slots: @@ -124,7 +126,7 @@ private: QNetworkReply* netreply; QString& appPath; - u8* tmdData; + const DSi_TMD::TitleMetadata* tmdData; bool& readOnly; u32 titleid[2]; -- cgit v1.2.3