From bbe10619efaf5c691e57747101029b3d194add3b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 24 Dec 2015 15:57:56 -0800 Subject: [PATCH] Qt: Remove game DB downloader and just bundle it --- src/platform/qt/CMakeLists.txt | 11 ++-- src/platform/qt/DatDownloadView.cpp | 83 ------------------------ src/platform/qt/DatDownloadView.h | 40 ------------ src/platform/qt/DatDownloadView.ui | 99 ----------------------------- src/platform/qt/GBAApp.cpp | 22 +++++-- src/platform/qt/GBAApp.h | 2 + src/platform/qt/ShaderSelector.cpp | 10 +-- src/platform/qt/Window.cpp | 11 ---- src/platform/qt/Window.h | 1 - 9 files changed, 27 insertions(+), 252 deletions(-) delete mode 100644 src/platform/qt/DatDownloadView.cpp delete mode 100644 src/platform/qt/DatDownloadView.h delete mode 100644 src/platform/qt/DatDownloadView.ui diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index 4f7399116..74e01d72a 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -70,7 +70,6 @@ set(SOURCE_FILES CheatsModel.cpp CheatsView.cpp ConfigController.cpp - DatDownloadView.cpp Display.cpp DisplayGL.cpp DisplayQt.cpp @@ -108,7 +107,6 @@ set(SOURCE_FILES qt5_wrap_ui(UI_FILES AboutScreen.ui CheatsView.ui - DatDownloadView.ui GIFView.ui IOViewer.ui LoadSaveState.ui @@ -168,13 +166,14 @@ if(WIN32) endif() endif() if(APPLE) - set(SHADER_DIR Applications/${PROJECT_NAME}.app/Contents/Resources) + set(DATA_DIR Applications/${PROJECT_NAME}.app/Contents/Resources) else() - set(SHADER_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) + set(DATA_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) endif() -install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${SHADER_DIR} COMPONENT ${BINARY_NAME}-qt) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATA_DIR} COMPONENT ${BINARY_NAME}-qt) +install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATA_DIR} COMPONENT ${BINARY_NAME}-qt) if(NOT WIN32 AND NOT APPLE) - list(APPEND QT_DEFINES QT_SHADER_DIR="${SHADER_DIR}/shaders") + list(APPEND QT_DEFINES DATA_DIR="${DATA_DIR}") endif() add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES}) diff --git a/src/platform/qt/DatDownloadView.cpp b/src/platform/qt/DatDownloadView.cpp deleted file mode 100644 index 3bbe95a4a..000000000 --- a/src/platform/qt/DatDownloadView.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* 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 -#include - -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; - } -} diff --git a/src/platform/qt/DatDownloadView.h b/src/platform/qt/DatDownloadView.h deleted file mode 100644 index ce3682d24..000000000 --- a/src/platform/qt/DatDownloadView.h +++ /dev/null @@ -1,40 +0,0 @@ -/* 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 - -#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 diff --git a/src/platform/qt/DatDownloadView.ui b/src/platform/qt/DatDownloadView.ui deleted file mode 100644 index 17b469c02..000000000 --- a/src/platform/qt/DatDownloadView.ui +++ /dev/null @@ -1,99 +0,0 @@ - - - DatDownloadView - - - - 0 - 0 - 274 - 101 - - - - Dialog - - - - QLayout::SetFixedSize - - - - - Qt::LeftToRight - - - Downloading database… - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - 0 - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Close - - - - - - - - - dialogButtonBox - accepted() - DatDownloadView - hide() - - - 248 - 254 - - - 157 - 274 - - - - - dialogButtonBox - rejected() - DatDownloadView - hide() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 0eb6fc9a6..9fb96b303 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -174,11 +174,21 @@ QFileDialog* GBAApp::getSaveFileDialog(QWidget* owner, const QString& title, con return dialog; } +QString GBAApp::dataDir() { +#ifdef DATA_DIR + QString path = QString::fromUtf8(DATA_DIR); +#else + QString path = QCoreApplication::applicationDirPath(); +#ifdef Q_OS_MAC + path += QLatin1String("/../Resources"); +#endif +#endif + return path; +} + 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); + VFile* vf = VFileDevice::open(dataDir() + "/nointro.dat", O_RDONLY); if (vf) { db = NoIntroDBLoad(vf); vf->close(vf); @@ -186,7 +196,11 @@ bool GBAApp::reloadGameDB() { if (db && m_db) { NoIntroDBDestroy(m_db); } - m_db = db; + if (db) { + m_db = db; + return true; + } + return false; } GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& caption, const QString& filter) diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index aeee9a479..e84f8f422 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -30,6 +30,8 @@ public: GBAApp(int& argc, char* argv[]); static GBAApp* app(); + static QString dataDir(); + Window* newWindow(); QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString()); diff --git a/src/platform/qt/ShaderSelector.cpp b/src/platform/qt/ShaderSelector.cpp index cbebfc739..599a1e5fe 100644 --- a/src/platform/qt/ShaderSelector.cpp +++ b/src/platform/qt/ShaderSelector.cpp @@ -6,6 +6,7 @@ #include "ShaderSelector.h" #include "ConfigController.h" +#include "GBAApp.h" #include "Display.h" #include "VFileDevice.h" @@ -57,16 +58,9 @@ void ShaderSelector::clear() { } void ShaderSelector::selectShader() { -#ifdef QT_SHADER_DIR - QFileDialog dialog(nullptr, tr("Load shader"), QT_SHADER_DIR, tr("%1 Shader (%.shader)").arg(projectName)); -#else - QString path = QCoreApplication::applicationDirPath(); -#ifdef Q_OS_MAC - path += QLatin1String("/../Resources"); -#endif + QString path(GBAApp::dataDir()); path += QLatin1String("/shaders"); QFileDialog dialog(nullptr, tr("Load shader"), path, tr("%1 Shader (%.shader)").arg(projectName)); -#endif dialog.setFileMode(QFileDialog::Directory); dialog.exec(); QStringList names = dialog.selectedFiles(); diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 63891b795..3f79af03c 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -17,7 +17,6 @@ #include "AboutScreen.h" #include "CheatsView.h" #include "ConfigController.h" -#include "DatDownloadView.h" #include "Display.h" #include "GameController.h" #include "GBAApp.h" @@ -408,12 +407,6 @@ 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); @@ -1194,10 +1187,6 @@ 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"); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index c78311a70..32a8f459a 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -89,7 +89,6 @@ public slots: void openAboutScreen(); void openROMInfo(); - void openDatDownloadWindow(); #ifdef BUILD_SDL void openGamepadWindow();