From f1ecfcb8bc17b949a5d17d0c50f1a41350485e01 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 1 Dec 2018 22:48:57 -0500 Subject: [PATCH 1/3] yuzu/game_list_worker: Tidy up string handling in FillControlMap() We don't need to call out to our own file handling functions when we're going to construct a QFileInfo instance right after it. We also don't need to convert to a std::string again just to compare the file extension. --- src/yuzu/game_list_worker.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 362902e460..3d5f2c0f4b 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -155,14 +155,15 @@ void GameListWorker::AddInstalledTitlesToGameList() { void GameListWorker::FillControlMap(const std::string& dir_path) { const auto nca_control_callback = [this](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { - std::string physical_name = directory + DIR_SEP + virtual_name; + const std::string physical_name = directory + DIR_SEP + virtual_name; - if (stop_processing) - return false; // Breaks the callback loop. + if (stop_processing) { + // Breaks the callback loop + return false; + } - bool is_dir = FileUtil::IsDirectory(physical_name); - QFileInfo file_info(physical_name.c_str()); - if (!is_dir && file_info.suffix().toStdString() == "nca") { + const QFileInfo file_info(QString::fromStdString(physical_name)); + if (!file_info.isDir() && file_info.suffix() == QStringLiteral("nca")) { auto nca = std::make_unique(vfs->OpenFile(physical_name, FileSys::Mode::Read)); if (nca->GetType() == FileSys::NCAContentType::Control) { From 8c108eaca7387ab6c8d79f36c78ab517c1719129 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 1 Dec 2018 23:23:02 -0500 Subject: [PATCH 2/3] yuzu/game_list_worker: Deduplicate game list entry creation Avoids duplicating the same code twice verbatim. --- src/yuzu/game_list_worker.cpp | 80 +++++++++++++++-------------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 3d5f2c0f4b..3d8787dd0a 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -86,6 +86,35 @@ QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, out.chop(1); return out; } + +QList MakeGameListEntry(const std::string& path, const std::string& name, + const std::vector& icon, Loader::AppLoader& loader, + u64 program_id, const CompatibilityList& compatibility_list, + const FileSys::PatchManager& patch) { + const auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); + + // The game list uses this as compatibility number for untested games + QString compatibility{"99"}; + if (it != compatibility_list.end()) { + compatibility = it->second.first; + } + + QList list{ + new GameListItemPath( + FormatGameName(path), icon, QString::fromStdString(name), + QString::fromStdString(Loader::GetFileTypeString(loader.GetFileType())), program_id), + new GameListItemCompat(compatibility), + new GameListItem(QString::fromStdString(Loader::GetFileTypeString(loader.GetFileType()))), + new GameListItemSize(FileUtil::GetSize(path)), + }; + + if (UISettings::values.show_add_ons) { + list.insert( + 2, new GameListItem(FormatPatchNameVersions(patch, loader, loader.IsRomFSUpdatable()))); + } + + return list; +} } // Anonymous namespace GameListWorker::GameListWorker(FileSys::VirtualFilesystem vfs, QString dir_path, bool deep_scan, @@ -116,29 +145,8 @@ void GameListWorker::AddInstalledTitlesToGameList() { if (control != nullptr) GetMetadataFromControlNCA(patch, *control, icon, name); - auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); - - // The game list uses this as compatibility number for untested games - QString compatibility("99"); - if (it != compatibility_list.end()) - compatibility = it->second.first; - - QList list{ - new GameListItemPath( - FormatGameName(file->GetFullPath()), icon, QString::fromStdString(name), - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())), - program_id), - new GameListItemCompat(compatibility), - new GameListItem( - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), - new GameListItemSize(file->GetSize()), - }; - - if (UISettings::values.show_add_ons) { - list.insert(2, new GameListItem(FormatPatchNameVersions(patch, *loader))); - } - - emit EntryReady(list); + emit EntryReady(MakeGameListEntry(file->GetFullPath(), name, icon, *loader, program_id, + compatibility_list, patch)); } const auto control_data = cache->ListEntriesFilter(FileSys::TitleType::Application, @@ -215,30 +223,8 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign } } - auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); - - // The game list uses this as compatibility number for untested games - QString compatibility("99"); - if (it != compatibility_list.end()) - compatibility = it->second.first; - - QList list{ - new GameListItemPath( - FormatGameName(physical_name), icon, QString::fromStdString(name), - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())), - program_id), - new GameListItemCompat(compatibility), - new GameListItem( - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), - new GameListItemSize(FileUtil::GetSize(physical_name)), - }; - - if (UISettings::values.show_add_ons) { - list.insert(2, new GameListItem(FormatPatchNameVersions( - patch, *loader, loader->IsRomFSUpdatable()))); - } - - emit EntryReady(std::move(list)); + emit EntryReady(MakeGameListEntry(physical_name, name, icon, *loader, program_id, + compatibility_list, patch)); } else if (is_dir && recursion > 0) { watch_list.append(QString::fromStdString(physical_name)); AddFstEntriesToGameList(physical_name, recursion - 1); From a49fd7fd57ed9a2a1a40dc0b99942bd1b18db414 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 4 Dec 2018 18:39:32 -0500 Subject: [PATCH 3/3] yuzu/game_list_worker: Move std::string construction after the termination check in callbacks Avoids potentially allocating a std::string instance when it isn't needed. --- src/yuzu/game_list_worker.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 3d8787dd0a..6d41809fbd 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -163,13 +163,12 @@ void GameListWorker::AddInstalledTitlesToGameList() { void GameListWorker::FillControlMap(const std::string& dir_path) { const auto nca_control_callback = [this](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { - const std::string physical_name = directory + DIR_SEP + virtual_name; - if (stop_processing) { // Breaks the callback loop return false; } + const std::string physical_name = directory + DIR_SEP + virtual_name; const QFileInfo file_info(QString::fromStdString(physical_name)); if (!file_info.isDir() && file_info.suffix() == QStringLiteral("nca")) { auto nca = @@ -188,12 +187,13 @@ void GameListWorker::FillControlMap(const std::string& dir_path) { void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) { const auto callback = [this, recursion](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { - std::string physical_name = directory + DIR_SEP + virtual_name; + if (stop_processing) { + // Breaks the callback loop. + return false; + } - if (stop_processing) - return false; // Breaks the callback loop. - - bool is_dir = FileUtil::IsDirectory(physical_name); + const std::string physical_name = directory + DIR_SEP + virtual_name; + const bool is_dir = FileUtil::IsDirectory(physical_name); if (!is_dir && (HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) { std::unique_ptr loader =