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 "CoreController.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(std::shared_ptr<CoreController> controller, QWidget* parent)
25 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
26{
27 m_ui.setupUi(this);
28
29#ifdef USE_SQLITE3
30 const NoIntroDB* db = GBAApp::app()->gameDB();
31#endif
32 uint32_t crc32 = 0;
33
34 CoreController::Interrupter interrupter(controller);
35 mCore* core = controller->thread()->core;
36 char title[17] = {};
37 core->getGameTitle(core, title);
38 m_ui.title->setText(QLatin1String(title));
39 title[8] = '\0';
40 core->getGameCode(core, title);
41 if (title[0]) {
42 m_ui.id->setText(QLatin1String(title));
43 } else {
44 m_ui.id->setText(tr("(unknown)"));
45 }
46
47 core->checksum(core, &crc32, CHECKSUM_CRC32);
48
49 switch (controller->thread()->core->platform(controller->thread()->core)) {
50#ifdef M_CORE_GBA
51 case PLATFORM_GBA: {
52 GBA* gba = static_cast<GBA*>(core->board);
53 m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes"));
54 break;
55 }
56#endif
57#ifdef M_CORE_GB
58 case PLATFORM_GB: {
59 GB* gb = static_cast<GB*>(core->board);
60 m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes"));
61 break;
62 }
63#endif
64 default:
65 m_ui.size->setText(tr("(unknown)"));
66 break;
67 }
68 if (crc32) {
69 m_ui.crc->setText(QString::number(crc32, 16));
70#ifdef USE_SQLITE3
71 if (db) {
72 NoIntroGame game{};
73 if (NoIntroDBLookupGameByCRC(db, crc32, &game)) {
74 m_ui.name->setText(game.name);
75 } else {
76 m_ui.name->setText(tr("(unknown)"));
77 }
78 } else {
79 m_ui.name->setText(tr("(no database present)"));
80 }
81#else
82 m_ui.name->hide();
83#endif
84 } else {
85 m_ui.crc->setText(tr("(unknown)"));
86 m_ui.name->setText(tr("(unknown)"));
87 }
88}