Qt: Cross-reference CRCs with game database
Vicki Pfau vi@endrift.com
Fri, 27 Jan 2017 01:56:10 -0800
5 files changed,
34 insertions(+),
1 deletions(-)
M
include/mgba/core/library.h
→
include/mgba/core/library.h
@@ -41,6 +41,9 @@ size_t mLibraryCount(struct mLibrary* library, const struct mLibraryEntry* constraints);
size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out, size_t numEntries, size_t offset, const struct mLibraryEntry* constraints); struct VFile* mLibraryOpenVFile(struct mLibrary* library, const struct mLibraryEntry* entry); +struct NoIntroDB; +void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db); + #endif CXX_GUARD_END
M
src/core/library.c
→
src/core/library.c
@@ -11,6 +11,7 @@
#ifdef USE_SQLITE3 #include <sqlite3.h> +#include "feature/sqlite3/no-intro.h" DEFINE_VECTOR(mLibraryListing, struct mLibraryEntry);@@ -25,6 +26,7 @@ sqlite3_stmt* deletePath;
sqlite3_stmt* deleteRoot; sqlite3_stmt* count; sqlite3_stmt* select; + const struct NoIntroDB* gameDB; }; #define CONSTRAINTS_ROMONLY \@@ -105,6 +107,8 @@ }
static const char createTables[] = " PRAGMA foreign_keys = ON;" + "\n PRAGMA journal_mode = MEMORY;" + "\n PRAGMA synchronous = NORMAL;" "\n CREATE TABLE IF NOT EXISTS version (" "\n tname TEXT NOT NULL PRIMARY KEY," "\n version INTEGER NOT NULL DEFAULT 1"@@ -366,6 +370,10 @@ for (i = 0; i < nCols; ++i) {
const char* colName = sqlite3_column_name(library->select, i); if (strcmp(colName, "crc32") == 0) { entry->crc32 = sqlite3_column_int(library->select, i); + struct NoIntroGame game; + if (NoIntroDBLookupGameByCRC(library->gameDB, entry->crc32, &game)) { + entry->title = strdup(game.name); + } } else if (strcmp(colName, "platform") == 0) { entry->platform = sqlite3_column_int(library->select, i); } else if (strcmp(colName, "size") == 0) {@@ -421,6 +429,10 @@ break;
} } return vf; +} + +void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db) { + library->gameDB = db; } #endif
M
src/platform/qt/LibraryModel.cpp
→
src/platform/qt/LibraryModel.cpp
@@ -20,6 +20,15 @@ LibraryModel::LibraryModel(const QString& path, QObject* parent)
: QAbstractItemModel(parent) { if (s_columns.empty()) { + s_columns["name"] = { + tr("Name"), + [](const mLibraryEntry& e) -> QString { + if (e.title) { + return QString::fromUtf8(e.title); + } + return QString::fromUtf8(e.filename); + } + }; s_columns["filename"] = { tr("Filename"), [](const mLibraryEntry& e) -> QString {@@ -80,7 +89,7 @@ m_library = new LibraryHandle(mLibraryCreateEmpty());
} memset(&m_constraints, 0, sizeof(m_constraints)); m_constraints.platform = PLATFORM_NONE; - m_columns.append(s_columns["filename"]); + m_columns.append(s_columns["name"]); m_columns.append(s_columns["location"]); m_columns.append(s_columns["platform"]); m_columns.append(s_columns["size"]);@@ -199,6 +208,10 @@ if (parent.isValid()) {
return 0; } return mLibraryCount(m_library->library, &m_constraints); +} + +void LibraryModel::attachGameDB(const NoIntroDB* gameDB) { + mLibraryAttachGameDB(m_library->library, gameDB); } void LibraryModel::constrainBase(const QString& path) {
M
src/platform/qt/LibraryModel.h
→
src/platform/qt/LibraryModel.h
@@ -16,6 +16,7 @@ #include <functional>
struct VDir; struct VFile; +struct NoIntroDB; namespace QGBA {@@ -40,6 +41,8 @@ virtual QModelIndex parent(const QModelIndex& index) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; + + void attachGameDB(const NoIntroDB* gameDB); signals: void doneLoading();
M
src/platform/qt/LibraryView.cpp
→
src/platform/qt/LibraryView.cpp
@@ -8,6 +8,7 @@
#include <mgba-util/vfs.h> #include "ConfigController.h" +#include "GBAApp.h" using namespace QGBA;@@ -16,6 +17,7 @@ : QWidget(parent)
, m_model(ConfigController::configDir() + "/library.sqlite3") { m_ui.setupUi(this); + m_model.attachGameDB(GBAApp::app()->gameDB()); connect(&m_model, SIGNAL(doneLoading()), this, SIGNAL(doneLoading())); connect(&m_model, SIGNAL(doneLoading()), this, SLOT(resizeColumns())); connect(m_ui.listing, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(accepted()));