mirror of https://github.com/mgba-emu/mgba.git
Qt: Cross-reference CRCs with game database
This commit is contained in:
parent
0d6efaa3dc
commit
54b889df8c
|
@ -41,6 +41,9 @@ size_t mLibraryCount(struct mLibrary* library, const struct mLibraryEntry* const
|
||||||
size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out, size_t numEntries, size_t offset, 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 VFile* mLibraryOpenVFile(struct mLibrary* library, const struct mLibraryEntry* entry);
|
||||||
|
|
||||||
|
struct NoIntroDB;
|
||||||
|
void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CXX_GUARD_END
|
CXX_GUARD_END
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#ifdef USE_SQLITE3
|
#ifdef USE_SQLITE3
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include "feature/sqlite3/no-intro.h"
|
||||||
|
|
||||||
DEFINE_VECTOR(mLibraryListing, struct mLibraryEntry);
|
DEFINE_VECTOR(mLibraryListing, struct mLibraryEntry);
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ struct mLibrary {
|
||||||
sqlite3_stmt* deleteRoot;
|
sqlite3_stmt* deleteRoot;
|
||||||
sqlite3_stmt* count;
|
sqlite3_stmt* count;
|
||||||
sqlite3_stmt* select;
|
sqlite3_stmt* select;
|
||||||
|
const struct NoIntroDB* gameDB;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CONSTRAINTS_ROMONLY \
|
#define CONSTRAINTS_ROMONLY \
|
||||||
|
@ -105,6 +107,8 @@ struct mLibrary* mLibraryLoad(const char* path) {
|
||||||
|
|
||||||
static const char createTables[] =
|
static const char createTables[] =
|
||||||
" PRAGMA foreign_keys = ON;"
|
" PRAGMA foreign_keys = ON;"
|
||||||
|
"\n PRAGMA journal_mode = MEMORY;"
|
||||||
|
"\n PRAGMA synchronous = NORMAL;"
|
||||||
"\n CREATE TABLE IF NOT EXISTS version ("
|
"\n CREATE TABLE IF NOT EXISTS version ("
|
||||||
"\n tname TEXT NOT NULL PRIMARY KEY,"
|
"\n tname TEXT NOT NULL PRIMARY KEY,"
|
||||||
"\n version INTEGER NOT NULL DEFAULT 1"
|
"\n version INTEGER NOT NULL DEFAULT 1"
|
||||||
|
@ -366,6 +370,10 @@ size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out,
|
||||||
const char* colName = sqlite3_column_name(library->select, i);
|
const char* colName = sqlite3_column_name(library->select, i);
|
||||||
if (strcmp(colName, "crc32") == 0) {
|
if (strcmp(colName, "crc32") == 0) {
|
||||||
entry->crc32 = sqlite3_column_int(library->select, i);
|
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) {
|
} else if (strcmp(colName, "platform") == 0) {
|
||||||
entry->platform = sqlite3_column_int(library->select, i);
|
entry->platform = sqlite3_column_int(library->select, i);
|
||||||
} else if (strcmp(colName, "size") == 0) {
|
} else if (strcmp(colName, "size") == 0) {
|
||||||
|
@ -423,4 +431,8 @@ struct VFile* mLibraryOpenVFile(struct mLibrary* library, const struct mLibraryE
|
||||||
return vf;
|
return vf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db) {
|
||||||
|
library->gameDB = db;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,15 @@ LibraryModel::LibraryModel(const QString& path, QObject* parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
if (s_columns.empty()) {
|
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"] = {
|
s_columns["filename"] = {
|
||||||
tr("Filename"),
|
tr("Filename"),
|
||||||
[](const mLibraryEntry& e) -> QString {
|
[](const mLibraryEntry& e) -> QString {
|
||||||
|
@ -80,7 +89,7 @@ LibraryModel::LibraryModel(const QString& path, QObject* parent)
|
||||||
}
|
}
|
||||||
memset(&m_constraints, 0, sizeof(m_constraints));
|
memset(&m_constraints, 0, sizeof(m_constraints));
|
||||||
m_constraints.platform = PLATFORM_NONE;
|
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["location"]);
|
||||||
m_columns.append(s_columns["platform"]);
|
m_columns.append(s_columns["platform"]);
|
||||||
m_columns.append(s_columns["size"]);
|
m_columns.append(s_columns["size"]);
|
||||||
|
@ -201,6 +210,10 @@ int LibraryModel::rowCount(const QModelIndex& parent) const {
|
||||||
return mLibraryCount(m_library->library, &m_constraints);
|
return mLibraryCount(m_library->library, &m_constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryModel::attachGameDB(const NoIntroDB* gameDB) {
|
||||||
|
mLibraryAttachGameDB(m_library->library, gameDB);
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryModel::constrainBase(const QString& path) {
|
void LibraryModel::constrainBase(const QString& path) {
|
||||||
if (m_constraints.base) {
|
if (m_constraints.base) {
|
||||||
free(const_cast<char*>(m_constraints.base));
|
free(const_cast<char*>(m_constraints.base));
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
struct VDir;
|
struct VDir;
|
||||||
struct VFile;
|
struct VFile;
|
||||||
|
struct NoIntroDB;
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
|
@ -41,6 +42,8 @@ public:
|
||||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
|
|
||||||
|
void attachGameDB(const NoIntroDB* gameDB);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void doneLoading();
|
void doneLoading();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <mgba-util/vfs.h>
|
#include <mgba-util/vfs.h>
|
||||||
|
|
||||||
#include "ConfigController.h"
|
#include "ConfigController.h"
|
||||||
|
#include "GBAApp.h"
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ LibraryView::LibraryView(QWidget* parent)
|
||||||
, m_model(ConfigController::configDir() + "/library.sqlite3")
|
, m_model(ConfigController::configDir() + "/library.sqlite3")
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
m_model.attachGameDB(GBAApp::app()->gameDB());
|
||||||
connect(&m_model, SIGNAL(doneLoading()), this, SIGNAL(doneLoading()));
|
connect(&m_model, SIGNAL(doneLoading()), this, SIGNAL(doneLoading()));
|
||||||
connect(&m_model, SIGNAL(doneLoading()), this, SLOT(resizeColumns()));
|
connect(&m_model, SIGNAL(doneLoading()), this, SLOT(resizeColumns()));
|
||||||
connect(m_ui.listing, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(accepted()));
|
connect(m_ui.listing, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(accepted()));
|
||||||
|
|
Loading…
Reference in New Issue