src/platform/qt/ROMInfo.cpp (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "ROMInfo.h"
7
8#include "GBAApp.h"
9#include "GameController.h"
10
11#include <mgba/core/core.h>
12#ifdef M_CORE_GB
13#include <mgba/internal/gb/gb.h>
14#endif
15#ifdef M_CORE_GBA
16#include <mgba/internal/gba/gba.h>
17#endif
18#ifdef USE_SQLITE3
19#include "feature/sqlite3/no-intro.h"
20#endif
21
22using namespace QGBA;
23
24ROMInfo::ROMInfo(GameController* controller, QWidget* parent)
25 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
26{
27 m_ui.setupUi(this);
28
29 if (!controller->isLoaded()) {
30 return;
31 }
32
33#ifdef USE_SQLITE3
34 const NoIntroDB* db = GBAApp::app()->gameDB();
35#endif
36 uint32_t crc32 = 0;
37
38 GameController::Interrupter interrupter(controller);
39 mCore* core = controller->thread()->core;
40 char title[17] = {};
41 core->getGameTitle(core, title);
42 m_ui.title->setText(QLatin1String(title));
43 title[8] = '\0';
44 core->getGameCode(core, title);
45 if (title[0]) {
46 m_ui.id->setText(QLatin1String(title));
47 } else {
48 m_ui.id->setText(tr("(unknown)"));
49 }
50
51 switch (controller->thread()->core->platform(controller->thread()->core)) {
52#ifdef M_CORE_GBA
53 case PLATFORM_GBA: {
54 GBA* gba = static_cast<GBA*>(core->board);
55 m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes"));
56 crc32 = gba->romCrc32;
57 break;
58 }
59#endif
60#ifdef M_CORE_GB
61 case PLATFORM_GB: {
62 GB* gb = static_cast<GB*>(core->board);
63 m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes"));
64 crc32 = gb->romCrc32;
65 break;
66 }
67#endif
68 default:
69 m_ui.size->setText(tr("(unknown)"));
70 break;
71 }
72 if (crc32) {
73 m_ui.crc->setText(QString::number(crc32, 16));
74#ifdef USE_SQLITE3
75 if (db) {
76 NoIntroGame game{};
77 if (NoIntroDBLookupGameByCRC(db, crc32, &game)) {
78 m_ui.name->setText(game.name);
79 } else {
80 m_ui.name->setText(tr("(unknown)"));
81 }
82 } else {
83 m_ui.name->setText(tr("(no database present)"));
84 }
85#else
86 m_ui.name->hide();
87#endif
88 } else {
89 m_ui.crc->setText(tr("(unknown)"));
90 m_ui.name->setText(tr("(unknown)"));
91 }
92}