Qt: Download No-Intro database

This commit is contained in:
Jeffrey Pfau 2015-12-20 18:58:49 -08:00
parent 413881fec2
commit 54413a8fd1
10 changed files with 17828 additions and 10 deletions

17572
res/nointro.dat Normal file

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,7 @@ set(SOURCE_FILES
CheatsModel.cpp
CheatsView.cpp
ConfigController.cpp
DatDownloadView.cpp
Display.cpp
DisplayGL.cpp
DisplayQt.cpp
@ -106,6 +107,7 @@ set(SOURCE_FILES
qt5_wrap_ui(UI_FILES
AboutScreen.ui
CheatsView.ui
DatDownloadView.ui
GIFView.ui
IOViewer.ui
LoadSaveState.ui

View File

@ -0,0 +1,83 @@
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DatDownloadView.h"
#include "GBAApp.h"
#include <QFile>
#include <QNetworkAccessManager>
extern "C" {
#include "gba/context/config.h"
#include "util/version.h"
}
using namespace QGBA;
DatDownloadView::DatDownloadView(QWidget* parent)
: QDialog(parent)
, m_reply(nullptr)
{
m_ui.setupUi(this);
m_netman = new QNetworkAccessManager(this);
connect(m_netman, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
connect(m_ui.dialogButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonPressed(QAbstractButton*)));
}
void DatDownloadView::start() {
if (m_reply) {
return;
}
QNetworkRequest request(QUrl("https://raw.githubusercontent.com/mgba-emu/mgba/master/res/nointro.dat"));
request.setHeader(QNetworkRequest::UserAgentHeader, QString("%1 %2").arg(projectName).arg(projectVersion));
m_reply = m_netman->get(request);
connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(errored(QNetworkReply::NetworkError)));
}
void DatDownloadView::finished(QNetworkReply* reply) {
if (!m_reply) {
return;
}
char path[PATH_MAX];
GBAConfigDirectory(path, sizeof(path));
QFile outfile(QString::fromUtf8(path) + "/nointro.dat");
outfile.open(QIODevice::WriteOnly);
outfile.write(m_reply->readAll());
GBAApp::app()->reloadGameDB();
m_reply->deleteLater();
m_reply = nullptr;
setAttribute(Qt::WA_DeleteOnClose);
close();
}
void DatDownloadView::downloadProgress(qint64 read, qint64 size) {
if (size < 0) {
return;
}
m_ui.progressBar->setMaximum(size);
m_ui.progressBar->setValue(read);
}
void DatDownloadView::errored(QNetworkReply::NetworkError) {
m_ui.status->setText(tr("An error occurred"));
m_reply->deleteLater();
m_reply = nullptr;
}
void DatDownloadView::buttonPressed(QAbstractButton* button) {
switch (m_ui.dialogButtonBox->standardButton(button)) {
case QDialogButtonBox::Cancel:
if (m_reply) {
m_reply->abort();
}
break;
default:
break;
}
}

View File

@ -0,0 +1,40 @@
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef QGBA_DAT_DOWNLOAD_VIEW
#define QGBA_DAT_DOWNLOAD_VIEW
#include <QNetworkReply>
#include "ui_DatDownloadView.h"
class QNetworkAccessManager;
namespace QGBA {
class DatDownloadView : public QDialog {
Q_OBJECT
public:
DatDownloadView(QWidget* parent = nullptr);
public slots:
void start();
private slots:
void finished(QNetworkReply*);
void downloadProgress(qint64, qint64);
void errored(QNetworkReply::NetworkError);
void buttonPressed(QAbstractButton* button);
private:
Ui::DatDownloadView m_ui;
QNetworkAccessManager* m_netman;
QNetworkReply* m_reply;
};
}
#endif

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DatDownloadView</class>
<widget class="QDialog" name="DatDownloadView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>274</width>
<height>101</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="QLabel" name="status">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Downloading database…</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>dialogButtonBox</sender>
<signal>accepted()</signal>
<receiver>DatDownloadView</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>dialogButtonBox</sender>
<signal>rejected()</signal>
<receiver>DatDownloadView</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -63,13 +63,7 @@ GBAApp::GBAApp(int& argc, char* argv[])
return;
}
char path[PATH_MAX];
GBAConfigDirectory(path, sizeof(path));
VFile* vf = VFileDevice::open(QString::fromUtf8(path) + "/nointro.dat", O_RDONLY);
if (vf) {
m_db = NoIntroDBLoad(vf);
vf->close(vf);
}
reloadGameDB();
if (!m_configController.getQtOption("audioDriver").isNull()) {
AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController.getQtOption("audioDriver").toInt()));
@ -180,6 +174,21 @@ QFileDialog* GBAApp::getSaveFileDialog(QWidget* owner, const QString& title, con
return dialog;
}
bool GBAApp::reloadGameDB() {
NoIntroDB* db = nullptr;
char path[PATH_MAX];
GBAConfigDirectory(path, sizeof(path));
VFile* vf = VFileDevice::open(QString::fromUtf8(path) + "/nointro.dat", O_RDONLY);
if (vf) {
db = NoIntroDBLoad(vf);
vf->close(vf);
}
if (db && m_db) {
NoIntroDBDestroy(m_db);
}
m_db = db;
}
GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& caption, const QString& filter)
: QFileDialog(parent, caption, app->m_configController.getQtOption("lastDirectory").toString(), filter)
, m_app(app)

View File

@ -38,7 +38,8 @@ public:
QFileDialog* getOpenFileDialog(QWidget* owner, const QString& title, const QString& filter = QString());
QFileDialog* getSaveFileDialog(QWidget* owner, const QString& title, const QString& filter = QString());
const NoIntroDB* noIntroDB() const { return m_db; }
const NoIntroDB* gameDB() const { return m_db; }
bool reloadGameDB();
public slots:
void interruptAll();

View File

@ -21,7 +21,7 @@ ROMInfo::ROMInfo(GameController* controller, QWidget* parent) {
return;
}
const NoIntroDB* db = GBAApp::app()->noIntroDB();
const NoIntroDB* db = GBAApp::app()->gameDB();
controller->threadInterrupt();
GBA* gba = controller->thread()->gba;

View File

@ -17,6 +17,7 @@
#include "AboutScreen.h"
#include "CheatsView.h"
#include "ConfigController.h"
#include "DatDownloadView.h"
#include "Display.h"
#include "GameController.h"
#include "GBAApp.h"
@ -407,6 +408,12 @@ void Window::openROMInfo() {
openView(romInfo);
}
void Window::openDatDownloadWindow() {
DatDownloadView* datView = new DatDownloadView();
datView->show();
datView->start();
}
#ifdef BUILD_SDL
void Window::openGamepadWindow() {
const char* profile = m_inputController.profileForType(SDL_BINDING_BUTTON);
@ -715,7 +722,7 @@ void Window::updateTitle(float fps) {
m_controller->threadInterrupt();
if (m_controller->isLoaded()) {
const NoIntroDB* db = GBAApp::app()->noIntroDB();
const NoIntroDB* db = GBAApp::app()->gameDB();
NoIntroGame game;
if (db && NoIntroDBLookupGameByCRC(db, m_controller->thread()->gba->romCrc32, &game)) {
title = QLatin1String(game.name);
@ -1187,6 +1194,10 @@ void Window::setupMenu(QMenuBar* menubar) {
addControlledAction(toolsMenu, gdbWindow, "gdbWindow");
#endif
QAction* updateDat = new QAction(tr("Update game database..."), toolsMenu);
connect(updateDat, SIGNAL(triggered()), this, SLOT(openDatDownloadWindow()));
addControlledAction(toolsMenu, updateDat, "updateDat");
toolsMenu->addSeparator();
addControlledAction(toolsMenu, toolsMenu->addAction(tr("Settings..."), this, SLOT(openSettingsWindow())),
"settings");

View File

@ -89,6 +89,7 @@ public slots:
void openAboutScreen();
void openROMInfo();
void openDatDownloadWindow();
#ifdef BUILD_SDL
void openGamepadWindow();