From b4c06fdcc6d67ef987ac4e06f50ad3b1f1ada5a8 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 24 Jan 2020 14:51:09 +1000 Subject: [PATCH] GameList: Auto set cache/database path from user directory --- src/core/game_list.cpp | 5 +-- src/core/game_list.h | 5 ++- src/core/host_interface.cpp | 12 +++++ src/core/host_interface.h | 6 +++ src/duckstation-qt/gamelistsettingswidget.cpp | 20 ++------- src/duckstation-qt/gamelistsettingswidget.h | 3 +- src/duckstation-qt/gamelistsettingswidget.ui | 45 +++---------------- src/duckstation-qt/qthostinterface.cpp | 2 +- src/duckstation-qt/qthostinterface.h | 1 - 9 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index d2258c460..56c41b81c 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -676,7 +676,7 @@ const GameListDatabaseEntry* GameList::GetDatabaseEntryForCode(const std::string return (iter != m_database.end()) ? &iter->second : nullptr; } -void GameList::SetPathsFromSettings(SettingsInterface& si) +void GameList::SetSearchDirectoriesFromSettings(SettingsInterface& si) { m_search_directories.clear(); @@ -687,9 +687,6 @@ void GameList::SetPathsFromSettings(SettingsInterface& si) dirs = si.GetStringList("GameList", "RecursivePaths"); for (std::string& dir : dirs) m_search_directories.push_back({std::move(dir), true}); - - m_database_filename = si.GetStringValue("GameList", "RedumpDatabasePath"); - m_cache_filename = si.GetStringValue("GameList", "CachePath"); } void GameList::Refresh(bool invalidate_cache, bool invalidate_database) diff --git a/src/core/game_list.h b/src/core/game_list.h index 7af3dd59c..cd66b26e1 100644 --- a/src/core/game_list.h +++ b/src/core/game_list.h @@ -63,7 +63,10 @@ public: const GameListEntry* GetEntryForPath(const char* path) const; const GameListDatabaseEntry* GetDatabaseEntryForCode(const std::string& code) const; - void SetPathsFromSettings(SettingsInterface& si); + void SetCacheFilename(std::string filename) { m_cache_filename = std::move(filename); } + void SetDatabaseFilename(std::string filename) { m_database_filename = std::move(filename); } + + void SetSearchDirectoriesFromSettings(SettingsInterface& si); void AddDirectory(std::string path, bool recursive); void Refresh(bool invalidate_cache, bool invalidate_database); diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index fc369dedb..1b08004d4 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -54,6 +54,8 @@ HostInterface::HostInterface() { SetUserDirectory(); m_game_list = std::make_unique(); + m_game_list->SetCacheFilename(GetGameListCacheFileName()); + m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName()); m_settings.SetDefaults(); m_last_throttle_time = Common::Timer::GetValue(); } @@ -485,6 +487,16 @@ std::string HostInterface::GetSettingsFileName() const return GetUserDirectoryRelativePath("settings.ini"); } +std::string HostInterface::GetGameListCacheFileName() const +{ + return GetUserDirectoryRelativePath("cache/gamelist.cache"); +} + +std::string HostInterface::GetGameListDatabaseFileName() const +{ + return GetUserDirectoryRelativePath("cache/redump.dat"); +} + void HostInterface::RunFrame() { m_frame_timer.Reset(); diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 64cdfdf2a..1e546809a 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -93,6 +93,12 @@ protected: /// Returns the path of the settings file. std::string GetSettingsFileName() const; + /// Returns the path of the game list cache file. + std::string GetGameListCacheFileName() const; + + /// Returns the path of the game database cache file. + std::string GetGameListDatabaseFileName() const; + void RunFrame(); /// Throttles the system, i.e. sleeps until it's time to execute the next frame. diff --git a/src/duckstation-qt/gamelistsettingswidget.cpp b/src/duckstation-qt/gamelistsettingswidget.cpp index 91d4ec442..daa5912cc 100644 --- a/src/duckstation-qt/gamelistsettingswidget.cpp +++ b/src/duckstation-qt/gamelistsettingswidget.cpp @@ -188,7 +188,6 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface, m_ui.setupUi(this); m_search_directories_model = new GameListSearchDirectoriesModel(host_interface); - m_ui.redumpDatabasePath->setText(host_interface->getSettingValue("GameList/RedumpDatabasePath").toString()); m_ui.searchDirectoryList->setModel(m_search_directories_model); m_ui.searchDirectoryList->setSelectionMode(QAbstractItemView::SingleSelection); m_ui.searchDirectoryList->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -205,9 +204,8 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface, &GameListSettingsWidget::onRemoveSearchDirectoryButtonPressed); connect(m_ui.refreshGameListButton, &QToolButton::pressed, this, &GameListSettingsWidget::onRefreshGameListButtonPressed); - connect(m_ui.browseRedumpPath, &QToolButton::pressed, this, &GameListSettingsWidget::onBrowseRedumpPathButtonPressed); - connect(m_ui.downloadRedumpDatabase, &QToolButton::pressed, this, - &GameListSettingsWidget::onDownloadRedumpDatabaseButtonPressed); + connect(m_ui.updateRedumpDatabase, &QToolButton::pressed, this, + &GameListSettingsWidget::onUpdateRedumpDatabaseButtonPressed); } GameListSettingsWidget::~GameListSettingsWidget() = default; @@ -271,19 +269,7 @@ void GameListSettingsWidget::onRefreshGameListButtonPressed() m_host_interface->refreshGameList(true); } -void GameListSettingsWidget::onBrowseRedumpPathButtonPressed() -{ - QString filename = QFileDialog::getOpenFileName(this, tr("Select Redump Database File"), QString(), - tr("Redump Database Files (*.dat)")); - if (filename.isEmpty()) - return; - - m_ui.redumpDatabasePath->setText(filename); - m_host_interface->putSettingValue(QStringLiteral("GameList/RedumpDatabasePath"), filename); - m_host_interface->refreshGameList(true, true); -} - -void GameListSettingsWidget::onDownloadRedumpDatabaseButtonPressed() +void GameListSettingsWidget::onUpdateRedumpDatabaseButtonPressed() { QMessageBox::information(this, tr("TODO"), tr("TODO")); } diff --git a/src/duckstation-qt/gamelistsettingswidget.h b/src/duckstation-qt/gamelistsettingswidget.h index a4b6b9045..26fa09305 100644 --- a/src/duckstation-qt/gamelistsettingswidget.h +++ b/src/duckstation-qt/gamelistsettingswidget.h @@ -24,8 +24,7 @@ private Q_SLOTS: void onAddSearchDirectoryButtonPressed(); void onRemoveSearchDirectoryButtonPressed(); void onRefreshGameListButtonPressed(); - void onBrowseRedumpPathButtonPressed(); - void onDownloadRedumpDatabaseButtonPressed(); + void onUpdateRedumpDatabaseButtonPressed(); protected: void resizeEvent(QResizeEvent* event); diff --git a/src/duckstation-qt/gamelistsettingswidget.ui b/src/duckstation-qt/gamelistsettingswidget.ui index fe52a8969..c5e30be01 100644 --- a/src/duckstation-qt/gamelistsettingswidget.ui +++ b/src/duckstation-qt/gamelistsettingswidget.ui @@ -46,7 +46,7 @@ Add - + :/icons/list-add.png:/icons/list-add.png @@ -60,7 +60,7 @@ Remove - + :/icons/list-remove.png:/icons/list-remove.png @@ -87,7 +87,7 @@ Refresh - + :/icons/view-refresh.png:/icons/view-refresh.png @@ -95,44 +95,13 @@ - - - - - - Redump Database Path - - - - - - - - - + - Browse... + Update Redump Database - - :/icons/system-search.png:/icons/system-search.png - - - Qt::ToolButtonTextBesideIcon - - - false - - - - - - - Download... - - - + :/icons/applications-internet.png:/icons/applications-internet.png @@ -144,7 +113,7 @@ - + diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 1a7c9863a..5d22f00ee 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -158,7 +158,7 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool { std::lock_guard lock(m_qsettings_mutex); QtSettingsInterface si(m_qsettings); - m_game_list->SetPathsFromSettings(si); + m_game_list->SetSearchDirectoriesFromSettings(si); m_game_list->Refresh(invalidate_cache, invalidate_database); emit gameListRefreshed(); } diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 1e616216c..26dd5613d 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -114,7 +114,6 @@ private: void checkSettings(); void updateQSettingsFromCoreSettings(); - void createGameList(); void updateControllerInputMap(); void updateHotkeyInputMap(); void addButtonToInputMap(const QString& binding, InputButtonHandler handler);