GameList: Auto set cache/database path from user directory

This commit is contained in:
Connor McLaughlin 2020-01-24 14:51:09 +10:00
parent feb48899c3
commit b4c06fdcc6
9 changed files with 35 additions and 64 deletions

View File

@ -676,7 +676,7 @@ const GameListDatabaseEntry* GameList::GetDatabaseEntryForCode(const std::string
return (iter != m_database.end()) ? &iter->second : nullptr; return (iter != m_database.end()) ? &iter->second : nullptr;
} }
void GameList::SetPathsFromSettings(SettingsInterface& si) void GameList::SetSearchDirectoriesFromSettings(SettingsInterface& si)
{ {
m_search_directories.clear(); m_search_directories.clear();
@ -687,9 +687,6 @@ void GameList::SetPathsFromSettings(SettingsInterface& si)
dirs = si.GetStringList("GameList", "RecursivePaths"); dirs = si.GetStringList("GameList", "RecursivePaths");
for (std::string& dir : dirs) for (std::string& dir : dirs)
m_search_directories.push_back({std::move(dir), true}); 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) void GameList::Refresh(bool invalidate_cache, bool invalidate_database)

View File

@ -63,7 +63,10 @@ public:
const GameListEntry* GetEntryForPath(const char* path) const; const GameListEntry* GetEntryForPath(const char* path) const;
const GameListDatabaseEntry* GetDatabaseEntryForCode(const std::string& code) 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 AddDirectory(std::string path, bool recursive);
void Refresh(bool invalidate_cache, bool invalidate_database); void Refresh(bool invalidate_cache, bool invalidate_database);

View File

@ -54,6 +54,8 @@ HostInterface::HostInterface()
{ {
SetUserDirectory(); SetUserDirectory();
m_game_list = std::make_unique<GameList>(); m_game_list = std::make_unique<GameList>();
m_game_list->SetCacheFilename(GetGameListCacheFileName());
m_game_list->SetDatabaseFilename(GetGameListDatabaseFileName());
m_settings.SetDefaults(); m_settings.SetDefaults();
m_last_throttle_time = Common::Timer::GetValue(); m_last_throttle_time = Common::Timer::GetValue();
} }
@ -485,6 +487,16 @@ std::string HostInterface::GetSettingsFileName() const
return GetUserDirectoryRelativePath("settings.ini"); 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() void HostInterface::RunFrame()
{ {
m_frame_timer.Reset(); m_frame_timer.Reset();

View File

@ -93,6 +93,12 @@ protected:
/// Returns the path of the settings file. /// Returns the path of the settings file.
std::string GetSettingsFileName() const; 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(); void RunFrame();
/// Throttles the system, i.e. sleeps until it's time to execute the next frame. /// Throttles the system, i.e. sleeps until it's time to execute the next frame.

View File

@ -188,7 +188,6 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface,
m_ui.setupUi(this); m_ui.setupUi(this);
m_search_directories_model = new GameListSearchDirectoriesModel(host_interface); 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->setModel(m_search_directories_model);
m_ui.searchDirectoryList->setSelectionMode(QAbstractItemView::SingleSelection); m_ui.searchDirectoryList->setSelectionMode(QAbstractItemView::SingleSelection);
m_ui.searchDirectoryList->setSelectionBehavior(QAbstractItemView::SelectRows); m_ui.searchDirectoryList->setSelectionBehavior(QAbstractItemView::SelectRows);
@ -205,9 +204,8 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface,
&GameListSettingsWidget::onRemoveSearchDirectoryButtonPressed); &GameListSettingsWidget::onRemoveSearchDirectoryButtonPressed);
connect(m_ui.refreshGameListButton, &QToolButton::pressed, this, connect(m_ui.refreshGameListButton, &QToolButton::pressed, this,
&GameListSettingsWidget::onRefreshGameListButtonPressed); &GameListSettingsWidget::onRefreshGameListButtonPressed);
connect(m_ui.browseRedumpPath, &QToolButton::pressed, this, &GameListSettingsWidget::onBrowseRedumpPathButtonPressed); connect(m_ui.updateRedumpDatabase, &QToolButton::pressed, this,
connect(m_ui.downloadRedumpDatabase, &QToolButton::pressed, this, &GameListSettingsWidget::onUpdateRedumpDatabaseButtonPressed);
&GameListSettingsWidget::onDownloadRedumpDatabaseButtonPressed);
} }
GameListSettingsWidget::~GameListSettingsWidget() = default; GameListSettingsWidget::~GameListSettingsWidget() = default;
@ -271,19 +269,7 @@ void GameListSettingsWidget::onRefreshGameListButtonPressed()
m_host_interface->refreshGameList(true); m_host_interface->refreshGameList(true);
} }
void GameListSettingsWidget::onBrowseRedumpPathButtonPressed() void GameListSettingsWidget::onUpdateRedumpDatabaseButtonPressed()
{
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()
{ {
QMessageBox::information(this, tr("TODO"), tr("TODO")); QMessageBox::information(this, tr("TODO"), tr("TODO"));
} }

View File

@ -24,8 +24,7 @@ private Q_SLOTS:
void onAddSearchDirectoryButtonPressed(); void onAddSearchDirectoryButtonPressed();
void onRemoveSearchDirectoryButtonPressed(); void onRemoveSearchDirectoryButtonPressed();
void onRefreshGameListButtonPressed(); void onRefreshGameListButtonPressed();
void onBrowseRedumpPathButtonPressed(); void onUpdateRedumpDatabaseButtonPressed();
void onDownloadRedumpDatabaseButtonPressed();
protected: protected:
void resizeEvent(QResizeEvent* event); void resizeEvent(QResizeEvent* event);

View File

@ -46,7 +46,7 @@
<string>Add</string> <string>Add</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="resources/icons.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset> <normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -60,7 +60,7 @@
<string>Remove</string> <string>Remove</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="resources/icons.qrc">
<normaloff>:/icons/list-remove.png</normaloff>:/icons/list-remove.png</iconset> <normaloff>:/icons/list-remove.png</normaloff>:/icons/list-remove.png</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -87,7 +87,7 @@
<string>Refresh</string> <string>Refresh</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="resources/icons.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset> <normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -95,44 +95,13 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Redump Database Path</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLineEdit" name="redumpDatabasePath"/> <widget class="QPushButton" name="updateRedumpDatabase">
</item>
<item>
<widget class="QToolButton" name="browseRedumpPath">
<property name="text"> <property name="text">
<string>Browse...</string> <string>Update Redump Database</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="resources/icons.qrc">
<normaloff>:/icons/system-search.png</normaloff>:/icons/system-search.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="downloadRedumpDatabase">
<property name="text">
<string>Download...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/applications-internet.png</normaloff>:/icons/applications-internet.png</iconset> <normaloff>:/icons/applications-internet.png</normaloff>:/icons/applications-internet.png</iconset>
</property> </property>
</widget> </widget>
@ -144,7 +113,7 @@
</layout> </layout>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="resources/icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -158,7 +158,7 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool
{ {
std::lock_guard<std::mutex> lock(m_qsettings_mutex); std::lock_guard<std::mutex> lock(m_qsettings_mutex);
QtSettingsInterface si(m_qsettings); QtSettingsInterface si(m_qsettings);
m_game_list->SetPathsFromSettings(si); m_game_list->SetSearchDirectoriesFromSettings(si);
m_game_list->Refresh(invalidate_cache, invalidate_database); m_game_list->Refresh(invalidate_cache, invalidate_database);
emit gameListRefreshed(); emit gameListRefreshed();
} }

View File

@ -114,7 +114,6 @@ private:
void checkSettings(); void checkSettings();
void updateQSettingsFromCoreSettings(); void updateQSettingsFromCoreSettings();
void createGameList();
void updateControllerInputMap(); void updateControllerInputMap();
void updateHotkeyInputMap(); void updateHotkeyInputMap();
void addButtonToInputMap(const QString& binding, InputButtonHandler handler); void addButtonToInputMap(const QString& binding, InputButtonHandler handler);