From 227e4fd91546d4047762534d624e877c87091572 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Fri, 18 Sep 2020 23:06:55 +0200 Subject: [PATCH] more work --- .gitignore | 1 + Source/3rdParty/CMakeLists.txt | 21 ++-- Source/RMG/CMakeLists.txt | 3 +- Source/RMG/Globals.cpp | 3 +- Source/RMG/Globals.hpp | 6 +- Source/RMG/M64P/Wrapper/Config.cpp | 117 +++++++++++++++++- Source/RMG/M64P/Wrapper/Config.hpp | 13 ++ Source/RMG/UserInterface/MainWindow.cpp | 35 +++++- Source/RMG/UserInterface/MainWindow.hpp | 1 + Source/RMG/UserInterface/RomBrowserWidget.cpp | 8 +- Source/RMG/UserInterface/RomBrowserWidget.hpp | 3 + Source/RMG/{Util => Utilities}/Logger.cpp | 4 +- Source/RMG/{Util => Utilities}/Logger.hpp | 8 +- Source/RMG/Utilities/Settings.cpp | 50 ++++++++ Source/RMG/Utilities/Settings.hpp | 27 ++++ Source/RMG/main.cpp | 1 - 16 files changed, 273 insertions(+), 28 deletions(-) rename Source/RMG/{Util => Utilities}/Logger.cpp (96%) rename Source/RMG/{Util => Utilities}/Logger.hpp (90%) create mode 100644 Source/RMG/Utilities/Settings.cpp create mode 100644 Source/RMG/Utilities/Settings.hpp diff --git a/.gitignore b/.gitignore index 1fc78282..65e5d67f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # CMake build directory Build/ +Bin/ diff --git a/Source/3rdParty/CMakeLists.txt b/Source/3rdParty/CMakeLists.txt index e7d01ce2..8ffdb946 100644 --- a/Source/3rdParty/CMakeLists.txt +++ b/Source/3rdParty/CMakeLists.txt @@ -3,7 +3,10 @@ # include(ExternalProject) -set(M64P_CORE_DIR ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-core) +set(THIRDPARTY_DIR ${CMAKE_BINARY_DIR}/Source/3rdParty) + + +set(M64P_CORE_DIR ${THIRDPARTY_DIR}/mupen64plus-core) if(WIN32) set(SO_EXT "dll") set(CORE_FILE "mupen64plus.dll") @@ -43,9 +46,9 @@ ExternalProject_Add(mupen64plus-audio-sdl BUILD_COMMAND make all APIDIR=${APIDIR} BUILD_IN_SOURCE False - BINARY_DIR ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-audio-sdl/projects/unix + BINARY_DIR ${THIRDPARTY_DIR}/mupen64plus-audio-sdl/projects/unix - BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-audio-sdl/projects/unix/mupen64plus-audio-sdl.${SO_EXT} + BUILD_BYPRODUCTS ${THIRDPARTY_DIR}/mupen64plus-audio-sdl/projects/unix/mupen64plus-audio-sdl.${SO_EXT} DEPENDS mupen64plus-core ) @@ -61,9 +64,9 @@ ExternalProject_Add(mupen64plus-rsp-hle BUILD_COMMAND make all APIDIR=${APIDIR} BUILD_IN_SOURCE False - BINARY_DIR ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-rsp-hle/projects/unix + BINARY_DIR ${THIRDPARTY_DIR}/mupen64plus-rsp-hle/projects/unix - BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-rsp-hle/projects/unix/mupen64plus-rsp-hle.${SO_EXT} + BUILD_BYPRODUCTS ${THIRDPARTY_DIR}/mupen64plus-rsp-hle/projects/unix/mupen64plus-rsp-hle.${SO_EXT} DEPENDS mupen64plus-core ) @@ -79,9 +82,9 @@ ExternalProject_Add(mupen64plus-input-raphnetraw BUILD_COMMAND make all APIDIR=${APIDIR} BUILD_IN_SOURCE False - BINARY_DIR ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-input-raphnetraw/projects/unix + BINARY_DIR ${THIRDPARTY_DIR}/mupen64plus-input-raphnetraw/projects/unix - BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-input-raphnetraw/projects/unix/mupen64plus-input-raphnetraw.${SO_EXT} + BUILD_BYPRODUCTS ${THIRDPARTY_DIR}/mupen64plus-input-raphnetraw/projects/unix/mupen64plus-input-raphnetraw.${SO_EXT} DEPENDS mupen64plus-core ) @@ -97,7 +100,8 @@ ExternalProject_Add(mupen64plus-video-GLideN64 CMAKE_ARGS -DMUPENPLUSAPI=1 -DMUPENPLUSAPI_GLIDENUI=1 -Wno-dev SOURCE_SUBDIR ./src - BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/Source/3rdParty/mupen64plus-video-GLideN64/src/plugin/Release/mupen64plus-video-GLideN64.${SO_EXT} + BUILD_BYPRODUCTS ${THIRDPARTY_DIR}/mupen64plus-video-GLideN64/src/plugin/Release/mupen64plus-video-GLideN64.${SO_EXT} + BUILD_BYPRODUCTS ${THIRDPARTY_DIR}/mupen64plus-video-GLideN64/ini/GLideN64.custom.ini ) ExternalProject_Get_property(mupen64plus-core BUILD_BYPRODUCTS) @@ -105,7 +109,6 @@ set(MUPEN64PLUSCORE_LIB ${BUILD_BYPRODUCTS} PARENT_SCOPE) set(MUPEN64PLUSCORE_INI ${M64P_CORE_DIR}/data/mupen64plus.ini PARENT_SCOPE) set(MUPEN64PLUSCORE_CHT ${M64P_CORE_DIR}/data/mupencheat.txt PARENT_SCOPE) - ExternalProject_Get_property(mupen64plus-audio-sdl BUILD_BYPRODUCTS) set(MUPEN64PLUS_PLUGIN_AUDIO ${BUILD_BYPRODUCTS} PARENT_SCOPE) diff --git a/Source/RMG/CMakeLists.txt b/Source/RMG/CMakeLists.txt index 5c40e155..9b6bc88b 100644 --- a/Source/RMG/CMakeLists.txt +++ b/Source/RMG/CMakeLists.txt @@ -24,7 +24,8 @@ add_executable(RMG M64P/Wrapper/Core.cpp M64P/Wrapper/Plugin.cpp M64P/Wrapper/Api.cpp - Util/Logger.cpp + Utilities/Logger.cpp + Utilities/Settings.cpp Globals.cpp main.cpp ) diff --git a/Source/RMG/Globals.cpp b/Source/RMG/Globals.cpp index 774471a4..7d06ac07 100644 --- a/Source/RMG/Globals.cpp +++ b/Source/RMG/Globals.cpp @@ -1,4 +1,5 @@ #include -Util::Logger g_Logger; +Utilities::Logger g_Logger; +Utilities::Settings g_Settings; M64P::Wrapper::Api g_MupenApi; diff --git a/Source/RMG/Globals.hpp b/Source/RMG/Globals.hpp index 11ab76e4..7e43192b 100644 --- a/Source/RMG/Globals.hpp +++ b/Source/RMG/Globals.hpp @@ -1,10 +1,12 @@ #ifndef GLOBALS_HPP #define GLOBALS_HPP -#include "Util/Logger.hpp" +#include "Utilities/Logger.hpp" +#include "Utilities/Settings.hpp" #include "M64P/Wrapper/Api.hpp" -extern Util::Logger g_Logger; +extern Utilities::Logger g_Logger; +extern Utilities::Settings g_Settings; extern M64P::Wrapper::Api g_MupenApi; #endif // GLOBALS_HPP diff --git a/Source/RMG/M64P/Wrapper/Config.cpp b/Source/RMG/M64P/Wrapper/Config.cpp index 0f8a6183..0fdf4f4d 100644 --- a/Source/RMG/M64P/Wrapper/Config.cpp +++ b/Source/RMG/M64P/Wrapper/Config.cpp @@ -22,33 +22,144 @@ Config::~Config(void) bool Config::Init() { + m64p_error ret; + if (!M64P::Config.IsHooked()) { this->error_Message = "M64P::Config is not hooked!"; return false; } + /*ret = M64P::Config.ExternalOpen("Config/RMG.ini", &this->handle); + if (ret != M64ERR_SUCCESS) + { + this->error_Message = "Config::Init M64P::Config.ExternalOpen Failed: "; + this->error_Message += M64P::Core.ErrorMessage(ret); + return false; + }*/ + return true; } bool Config::SetOption(QString section, QString key, int value) { - + return this->section_Open(section) && + this->value_Set(key, M64TYPE_INT, (void *)&value); } bool Config::SetOption(QString section, QString key, float value) { - + return this->section_Open(section) && + this->value_Set(key, M64TYPE_FLOAT, (void *)&value); } bool Config::SetOption(QString section, QString key, bool value) { - + return this->section_Open(section) && + this->value_Set(key, M64TYPE_BOOL, (void *)&value); } bool Config::SetOption(QString section, QString key, QString value) { + const char *a = value.toStdString().c_str(); + return this->section_Open(section) && + this->value_Set(key, M64TYPE_STRING, (void *)a); +} + +bool Config::SetOption(QString section, QString key, char *value) +{ + return this->section_Open(section) && + this->value_Set(key, M64TYPE_STRING, (void *)value); +} + +bool Config::GetOption(QString section, QString key, int *value) +{ + return this->section_Open(section) && + this->value_Get(key, M64TYPE_INT, value, sizeof(*value)); +} + +bool Config::GetOption(QString section, QString key, float *value) +{ + return this->section_Open(section) && + this->value_Get(key, M64TYPE_INT, value, sizeof(*value)); +} + +bool Config::GetOption(QString section, QString key, bool *value) +{ + return this->section_Open(section) && + this->value_Get(key, M64TYPE_BOOL, value, sizeof(*value)); +} + +bool Config::GetOption(QString section, QString key, QString *value) +{ + char data[300]; + std::string str; + + if (!this->section_Open(section)) + return false; + + if (!this->value_Get(key, M64TYPE_STRING, data, sizeof(data))) + return false; + + str = std::string(data); + + *value = QString::fromStdString(str); + + return true; +} + +bool Config::section_Open(QString section) +{ + m64p_error ret; + + ret = M64P::Config.OpenSection(section.toStdString().c_str(), &this->section_Handle); + if (ret != M64ERR_SUCCESS) + { + this->error_Message = "Config::section_Open Failed: "; + this->error_Message = M64P::Core.ErrorMessage(ret); + return false; + } + + return true; +} + +bool Config::value_Set(QString key, m64p_type type, void *value) +{ + m64p_error ret; + + ret = M64P::Config.SetParameter(this->section_Handle, key.toStdString().c_str(), type, value); + if (ret != M64ERR_SUCCESS) + { + this->error_Message = "Config::value_Set M64P::Config.SetParameter Failed: "; + this->error_Message += M64P::Core.ErrorMessage(ret); + return false; + } + + ret = M64P::Config.SaveFile(); + if (ret != M64ERR_SUCCESS) + { + this->error_Message = "Config::value_Set M64P::Config.SaveFile Failed: "; + this->error_Message += M64P::Core.ErrorMessage(ret); + return false; + } + + return true; +} + +bool Config::value_Get(QString key, m64p_type type, void *data, int maxSize) +{ + m64p_error ret; + + ret = M64P::Config.GetParameter(this->section_Handle, key.toStdString().c_str(), type, data, maxSize); + if (ret != M64ERR_SUCCESS) + { + this->error_Message = "Config::value_Get M64P::Config.GetParameter Failed: "; + this->error_Message += M64P::Core.ErrorMessage(ret); + return false; + } + + return true; } QString Config::GetLastError(void) diff --git a/Source/RMG/M64P/Wrapper/Config.hpp b/Source/RMG/M64P/Wrapper/Config.hpp index 524a543c..0a23020c 100644 --- a/Source/RMG/M64P/Wrapper/Config.hpp +++ b/Source/RMG/M64P/Wrapper/Config.hpp @@ -30,11 +30,24 @@ namespace M64P bool SetOption(QString section, QString key, float value); bool SetOption(QString section, QString key, bool value); bool SetOption(QString section, QString key, QString value); + bool SetOption(QString section, QString key, char* value); + + bool GetOption(QString section, QString key, int* value); + bool GetOption(QString section, QString key, float* value); + bool GetOption(QString section, QString key, bool* value); + bool GetOption(QString section, QString key, QString* value); QString GetLastError(void); private: QString error_Message; + + m64p_handle handle; + m64p_handle section_Handle; + + bool section_Open(QString); + bool value_Set(QString, m64p_type, void*); + bool value_Get(QString, m64p_type, void*, int); }; } // namespace Wrapper } // namespace M64P diff --git a/Source/RMG/UserInterface/MainWindow.cpp b/Source/RMG/UserInterface/MainWindow.cpp index da020eb3..93e85aa6 100644 --- a/Source/RMG/UserInterface/MainWindow.cpp +++ b/Source/RMG/UserInterface/MainWindow.cpp @@ -8,7 +8,6 @@ * along with this program. If not, see . */ #include "MainWindow.hpp" -#include "../Util/Logger.hpp" #include "../Config.hpp" #include @@ -19,6 +18,7 @@ #include #include #include +#include using namespace UserInterface; @@ -38,7 +38,7 @@ MainWindow::~MainWindow() if (this->ui_Settings) delete this->ui_Settings; */ } - +#include bool MainWindow::Init(void) { if (!g_Logger.Init()) @@ -47,6 +47,12 @@ bool MainWindow::Init(void) return false; } + if (!g_Settings.Init()) + { + this->ui_MessageBox("Error", "Settings::Init Failed", g_Settings.GetLastError()); + return false; + } + if (!g_MupenApi.Init(MUPEN_CORE_FILE)) { this->ui_MessageBox("Error", "M64P::Wrapper::Api::Init Failed", g_MupenApi.GetLastError()); @@ -79,17 +85,21 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::ui_Init(void) { + this->ui_Icon = QIcon(":Icons/RMG.png"); this->ui_Widget_OpenGL = new QOpenGLWidget(); this->ui_Widget_RomBrowser = new RomBrowserWidget(); this->ui_Widgets = new QStackedWidget(); this->ui_Settings = new QSettings(APP_SETTINGS_ORG, APP_SETTINGS_NAME); + + this->ui_Widget_RomBrowser->SetDirectory(g_Settings.GetValue("tmp", "directory").toString()); + this->ui_Widget_RomBrowser->RefreshRomList(); } void MainWindow::ui_Setup(void) { this->ui_Stylesheet_Setup(); - this->setWindowIcon(QIcon(":Icons/RMG.png")); + this->setWindowIcon(this->ui_Icon); this->setWindowTitle(WINDOW_TITLE); this->setCentralWidget(this->ui_Widgets); this->restoreGeometry(this->ui_Settings->value(APP_SETTINGS_GEOMETRY).toByteArray()); @@ -118,6 +128,7 @@ void MainWindow::ui_MessageBox(QString title, QString text, QString details = "" g_Logger.AddText("MainWindow::ui_MessageBox: " + title + ", " + text + ", " + details); QMessageBox msgBox; + msgBox.setWindowIcon(this->ui_Icon); msgBox.setIcon(QMessageBox::Icon::Critical); msgBox.setWindowTitle(title); msgBox.setText(text); @@ -307,6 +318,24 @@ void MainWindow::on_Action_File_EndEmulation(void) void MainWindow::on_Action_File_ChooseDirectory(void) { + QFileDialog dialog; + int ret; + QString dir; + dialog.setParent(this); + dialog.setFileMode(QFileDialog::Directory); + dialog.setOption(QFileDialog::ShowDirsOnly, true); + dialog.setWindowIcon(this->ui_Icon); + dialog.show(); + ret = dialog.exec(); + + if (ret) + { + dir = dialog.selectedFiles().first(); + g_Settings.SetValue("tmp", "directory", dir); + this->ui_Widget_RomBrowser->SetDirectory(dir); + this->ui_Widget_RomBrowser->RefreshRomList(); + } + } void MainWindow::on_Action_File_RefreshRomList(void) diff --git a/Source/RMG/UserInterface/MainWindow.hpp b/Source/RMG/UserInterface/MainWindow.hpp index 2fe1b08c..9d756c70 100644 --- a/Source/RMG/UserInterface/MainWindow.hpp +++ b/Source/RMG/UserInterface/MainWindow.hpp @@ -36,6 +36,7 @@ namespace UserInterface private: Thread::EmulationThread* emulationThread; + QIcon ui_Icon; QOpenGLWidget *ui_Widget_OpenGL; RomBrowserWidget *ui_Widget_RomBrowser; QStackedWidget *ui_Widgets; diff --git a/Source/RMG/UserInterface/RomBrowserWidget.cpp b/Source/RMG/UserInterface/RomBrowserWidget.cpp index 13445d66..6eec821a 100644 --- a/Source/RMG/UserInterface/RomBrowserWidget.cpp +++ b/Source/RMG/UserInterface/RomBrowserWidget.cpp @@ -31,6 +31,11 @@ void RomBrowserWidget::RefreshRomList(void) this->model_Setup(); } +void RomBrowserWidget::SetDirectory(QString directory) +{ + this->directory = directory; +} + void RomBrowserWidget::model_Init(void) { this->model_Model = new QStandardItemModel(this); @@ -45,7 +50,8 @@ void RomBrowserWidget::model_Setup(void) this->rom_List_Recursive = false; this->model_Model->clear(); - this->rom_List_Fill("/home/rosalie/Downloads/n64_roms/"); + if (!this->directory.isEmpty()) + this->rom_List_Fill(this->directory); this->model_LabelList_Setup(); diff --git a/Source/RMG/UserInterface/RomBrowserWidget.hpp b/Source/RMG/UserInterface/RomBrowserWidget.hpp index f2efdeb6..a3a7da93 100644 --- a/Source/RMG/UserInterface/RomBrowserWidget.hpp +++ b/Source/RMG/UserInterface/RomBrowserWidget.hpp @@ -34,7 +34,10 @@ namespace UserInterface void RefreshRomList(void); + void SetDirectory(QString); private: + QString directory; + QStandardItemModel *model_Model; QStringList model_LabelList; void model_Init(void); diff --git a/Source/RMG/Util/Logger.cpp b/Source/RMG/Utilities/Logger.cpp similarity index 96% rename from Source/RMG/Util/Logger.cpp rename to Source/RMG/Utilities/Logger.cpp index 7f26aa12..25efa899 100644 --- a/Source/RMG/Util/Logger.cpp +++ b/Source/RMG/Utilities/Logger.cpp @@ -7,11 +7,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include +#include "Logger.hpp" #include -using namespace Util; +using namespace Utilities; Logger::Logger(void) { diff --git a/Source/RMG/Util/Logger.hpp b/Source/RMG/Utilities/Logger.hpp similarity index 90% rename from Source/RMG/Util/Logger.hpp rename to Source/RMG/Utilities/Logger.hpp index 15ffe879..897c8e81 100644 --- a/Source/RMG/Util/Logger.hpp +++ b/Source/RMG/Utilities/Logger.hpp @@ -10,12 +10,12 @@ #ifndef LOGGER_HPP #define LOGGER_HPP -#include +#include "../Config.hpp" #include #include -namespace Util +namespace Utilities { class Logger { @@ -39,6 +39,4 @@ namespace Util } // namespace Util -extern Util::Logger g_Logger; - -#endif // LOGGER_HPP \ No newline at end of file +#endif // LOGGER_HPP diff --git a/Source/RMG/Utilities/Settings.cpp b/Source/RMG/Utilities/Settings.cpp new file mode 100644 index 00000000..44b662c1 --- /dev/null +++ b/Source/RMG/Utilities/Settings.cpp @@ -0,0 +1,50 @@ +#include "Settings.hpp" + +using namespace Utilities; + +Settings::Settings(void) +{ + +} + +Settings::~Settings(void) +{ + delete this->settings; +} + +bool Settings::Init(void) +{ + this->settings = new QSettings("Config/RMG.ini", QSettings::IniFormat); + + if (!this->settings->isWritable()) + { + this->error_Message = "Settings::Init Failed: "; + this->error_Message += "QSettings is not writable!"; + return false; + } + + return true; +} + +void Settings::SetValue(QString section, QString key, QVariant value) +{ + this->settings->beginGroup(section); + this->settings->setValue(key, value); + this->settings->endGroup(); +} + +QVariant Settings::GetValue(QString section, QString key) +{ + QVariant ret; + + this->settings->beginGroup(section); + ret = this->settings->value(key); + this->settings->endGroup(); + + return ret; +} + +QString Settings::GetLastError(void) +{ + return this->error_Message; +} diff --git a/Source/RMG/Utilities/Settings.hpp b/Source/RMG/Utilities/Settings.hpp new file mode 100644 index 00000000..f2cfa190 --- /dev/null +++ b/Source/RMG/Utilities/Settings.hpp @@ -0,0 +1,27 @@ +#ifndef SETTINGS_HPP +#define SETTINGS_HPP + +#include + +namespace Utilities +{ + class Settings + { + public: + Settings(void); + ~Settings(void); + + bool Init(void); + + void SetValue(QString, QString, QVariant); + QVariant GetValue(QString, QString); + + QString GetLastError(void); + private: + QString error_Message; + + QSettings* settings; + }; +} // namespace Utilities + +#endif // SETTINGS_HPP diff --git a/Source/RMG/main.cpp b/Source/RMG/main.cpp index 39dd0dd9..93265f25 100644 --- a/Source/RMG/main.cpp +++ b/Source/RMG/main.cpp @@ -1,5 +1,4 @@ #include -#include #include #include