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;
}
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)

View File

@ -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);

View File

@ -54,6 +54,8 @@ HostInterface::HostInterface()
{
SetUserDirectory();
m_game_list = std::make_unique<GameList>();
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();

View File

@ -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.

View File

@ -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"));
}

View File

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

View File

@ -46,7 +46,7 @@
<string>Add</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
<property name="toolButtonStyle">
@ -60,7 +60,7 @@
<string>Remove</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/list-remove.png</normaloff>:/icons/list-remove.png</iconset>
</property>
<property name="toolButtonStyle">
@ -87,7 +87,7 @@
<string>Refresh</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
<property name="toolButtonStyle">
@ -95,44 +95,13 @@
</property>
</widget>
</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>
<widget class="QLineEdit" name="redumpDatabasePath"/>
</item>
<item>
<widget class="QToolButton" name="browseRedumpPath">
<widget class="QPushButton" name="updateRedumpDatabase">
<property name="text">
<string>Browse...</string>
<string>Update Redump Database</string>
</property>
<property name="icon">
<iconset resource="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">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/applications-internet.png</normaloff>:/icons/applications-internet.png</iconset>
</property>
</widget>
@ -144,7 +113,7 @@
</layout>
</widget>
<resources>
<include location="icons.qrc"/>
<include location="resources/icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -158,7 +158,7 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool
{
std::lock_guard<std::mutex> 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();
}

View File

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