diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/game_list_worker.cpp | 60 |
2 files changed, 42 insertions, 23 deletions
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index d708d6786..b1942bedc 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -645,7 +645,8 @@ void Config::ReadUIGamelistValues() { | |||
| 645 | UISettings::values.icon_size = ReadSetting(QStringLiteral("icon_size"), 64).toUInt(); | 645 | UISettings::values.icon_size = ReadSetting(QStringLiteral("icon_size"), 64).toUInt(); |
| 646 | UISettings::values.row_1_text_id = ReadSetting(QStringLiteral("row_1_text_id"), 3).toUInt(); | 646 | UISettings::values.row_1_text_id = ReadSetting(QStringLiteral("row_1_text_id"), 3).toUInt(); |
| 647 | UISettings::values.row_2_text_id = ReadSetting(QStringLiteral("row_2_text_id"), 2).toUInt(); | 647 | UISettings::values.row_2_text_id = ReadSetting(QStringLiteral("row_2_text_id"), 2).toUInt(); |
| 648 | UISettings::values.cache_game_list = ReadSetting(QStringLiteral("cache_game_list"), true).toBool(); | 648 | UISettings::values.cache_game_list = |
| 649 | ReadSetting(QStringLiteral("cache_game_list"), true).toBool(); | ||
| 649 | 650 | ||
| 650 | qt_config->endGroup(); | 651 | qt_config->endGroup(); |
| 651 | } | 652 | } |
| @@ -1010,7 +1011,7 @@ void Config::SaveUIGamelistValues() { | |||
| 1010 | WriteSetting(QStringLiteral("icon_size"), UISettings::values.icon_size, 64); | 1011 | WriteSetting(QStringLiteral("icon_size"), UISettings::values.icon_size, 64); |
| 1011 | WriteSetting(QStringLiteral("row_1_text_id"), UISettings::values.row_1_text_id, 3); | 1012 | WriteSetting(QStringLiteral("row_1_text_id"), UISettings::values.row_1_text_id, 3); |
| 1012 | WriteSetting(QStringLiteral("row_2_text_id"), UISettings::values.row_2_text_id, 2); | 1013 | WriteSetting(QStringLiteral("row_2_text_id"), UISettings::values.row_2_text_id, 2); |
| 1013 | WriteSetting(QStringLiteral("cache_game_list"), UISettings::values.cache_game_list, true); | 1014 | WriteSetting(QStringLiteral("cache_game_list"), UISettings::values.cache_game_list, true); |
| 1014 | 1015 | ||
| 1015 | qt_config->endGroup(); | 1016 | qt_config->endGroup(); |
| 1016 | } | 1017 | } |
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index bc1833289..4d951a4e7 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -39,11 +39,12 @@ T GetGameListCachedObject(const std::string& filename, const std::string& ext, | |||
| 39 | template <> | 39 | template <> |
| 40 | QString GetGameListCachedObject(const std::string& filename, const std::string& ext, | 40 | QString GetGameListCachedObject(const std::string& filename, const std::string& ext, |
| 41 | const std::function<QString()>& generator) { | 41 | const std::function<QString()>& generator) { |
| 42 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") | 42 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") { |
| 43 | return generator(); | 43 | return generator(); |
| 44 | } | ||
| 44 | 45 | ||
| 45 | const auto& path = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" + | 46 | const auto path = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" + |
| 46 | DIR_SEP + filename + "." + ext; | 47 | DIR_SEP + filename + '.' + ext; |
| 47 | 48 | ||
| 48 | FileUtil::CreateFullPath(path); | 49 | FileUtil::CreateFullPath(path); |
| 49 | 50 | ||
| @@ -51,10 +52,10 @@ QString GetGameListCachedObject(const std::string& filename, const std::string& | |||
| 51 | const auto str = generator(); | 52 | const auto str = generator(); |
| 52 | 53 | ||
| 53 | std::ofstream stream(path); | 54 | std::ofstream stream(path); |
| 54 | if (stream) | 55 | if (stream) { |
| 55 | stream << str.toStdString(); | 56 | stream << str.toStdString(); |
| 57 | } | ||
| 56 | 58 | ||
| 57 | stream.close(); | ||
| 58 | return str; | 59 | return str; |
| 59 | } | 60 | } |
| 60 | 61 | ||
| @@ -63,7 +64,6 @@ QString GetGameListCachedObject(const std::string& filename, const std::string& | |||
| 63 | if (stream) { | 64 | if (stream) { |
| 64 | const std::string out(std::istreambuf_iterator<char>{stream}, | 65 | const std::string out(std::istreambuf_iterator<char>{stream}, |
| 65 | std::istreambuf_iterator<char>{}); | 66 | std::istreambuf_iterator<char>{}); |
| 66 | stream.close(); | ||
| 67 | return QString::fromStdString(out); | 67 | return QString::fromStdString(out); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| @@ -74,13 +74,14 @@ template <> | |||
| 74 | std::pair<std::vector<u8>, std::string> GetGameListCachedObject( | 74 | std::pair<std::vector<u8>, std::string> GetGameListCachedObject( |
| 75 | const std::string& filename, const std::string& ext, | 75 | const std::string& filename, const std::string& ext, |
| 76 | const std::function<std::pair<std::vector<u8>, std::string>()>& generator) { | 76 | const std::function<std::pair<std::vector<u8>, std::string>()>& generator) { |
| 77 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") | 77 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") { |
| 78 | return generator(); | 78 | return generator(); |
| 79 | } | ||
| 79 | 80 | ||
| 80 | const auto& path1 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + | 81 | const auto path1 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" + |
| 81 | "game_list" + DIR_SEP + filename + ".jpeg"; | 82 | DIR_SEP + filename + ".jpeg"; |
| 82 | const auto& path2 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + | 83 | const auto path2 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" + |
| 83 | "game_list" + DIR_SEP + filename + ".appname.txt"; | 84 | DIR_SEP + filename + ".appname.txt"; |
| 84 | 85 | ||
| 85 | FileUtil::CreateFullPath(path1); | 86 | FileUtil::CreateFullPath(path1); |
| 86 | 87 | ||
| @@ -88,28 +89,48 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject( | |||
| 88 | const auto [icon, nacp] = generator(); | 89 | const auto [icon, nacp] = generator(); |
| 89 | 90 | ||
| 90 | FileUtil::IOFile file1(path1, "wb"); | 91 | FileUtil::IOFile file1(path1, "wb"); |
| 91 | file1.Resize(icon.size()); | 92 | if (!file1.IsOpen()) { |
| 92 | file1.WriteBytes(icon.data(), icon.size()); | 93 | LOG_ERROR(Frontend, "Failed to open cache file."); |
| 94 | return generator(); | ||
| 95 | } | ||
| 96 | |||
| 97 | if (!file1.Resize(icon.size())) { | ||
| 98 | LOG_ERROR(Frontend, "Failed to resize cache file to necessary size."); | ||
| 99 | return generator(); | ||
| 100 | } | ||
| 101 | |||
| 102 | if (file1.WriteBytes(icon.data(), icon.size()) != icon.size()) { | ||
| 103 | LOG_ERROR(Frontend, "Failed to write data to cache file."); | ||
| 104 | return generator(); | ||
| 105 | } | ||
| 93 | 106 | ||
| 94 | std::ofstream stream2(path2, std::ios::out); | 107 | std::ofstream stream2(path2, std::ios::out); |
| 95 | if (stream2) | 108 | if (stream2) { |
| 96 | stream2 << nacp; | 109 | stream2 << nacp; |
| 110 | } | ||
| 97 | 111 | ||
| 98 | file1.Close(); | ||
| 99 | stream2.close(); | ||
| 100 | return std::make_pair(icon, nacp); | 112 | return std::make_pair(icon, nacp); |
| 101 | } | 113 | } |
| 102 | 114 | ||
| 103 | FileUtil::IOFile file1(path1, "rb"); | 115 | FileUtil::IOFile file1(path1, "rb"); |
| 104 | std::ifstream stream2(path2); | 116 | std::ifstream stream2(path2); |
| 105 | 117 | ||
| 118 | if (!file1.IsOpen()) { | ||
| 119 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); | ||
| 120 | return generator(); | ||
| 121 | } | ||
| 122 | |||
| 123 | if (!stream2) { | ||
| 124 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); | ||
| 125 | return generator(); | ||
| 126 | } | ||
| 127 | |||
| 106 | std::vector<u8> vec(file1.GetSize()); | 128 | std::vector<u8> vec(file1.GetSize()); |
| 107 | file1.ReadBytes(vec.data(), vec.size()); | 129 | file1.ReadBytes(vec.data(), vec.size()); |
| 108 | 130 | ||
| 109 | if (stream2 && !vec.empty()) { | 131 | if (stream2 && !vec.empty()) { |
| 110 | const std::string out(std::istreambuf_iterator<char>{stream2}, | 132 | const std::string out(std::istreambuf_iterator<char>{stream2}, |
| 111 | std::istreambuf_iterator<char>{}); | 133 | std::istreambuf_iterator<char>{}); |
| 112 | stream2.close(); | ||
| 113 | return std::make_pair(vec, out); | 134 | return std::make_pair(vec, out); |
| 114 | } | 135 | } |
| 115 | 136 | ||
| @@ -118,14 +139,11 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject( | |||
| 118 | 139 | ||
| 119 | void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager, const FileSys::NCA& nca, | 140 | void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager, const FileSys::NCA& nca, |
| 120 | std::vector<u8>& icon, std::string& name) { | 141 | std::vector<u8>& icon, std::string& name) { |
| 121 | auto res = GetGameListCachedObject<std::pair<std::vector<u8>, std::string>>( | 142 | std::tie(icon, name) = GetGameListCachedObject<std::pair<std::vector<u8>, std::string>>( |
| 122 | fmt::format("{:016X}", patch_manager.GetTitleID()), {}, [&patch_manager, &nca] { | 143 | fmt::format("{:016X}", patch_manager.GetTitleID()), {}, [&patch_manager, &nca] { |
| 123 | const auto [nacp, icon_f] = patch_manager.ParseControlNCA(nca); | 144 | const auto [nacp, icon_f] = patch_manager.ParseControlNCA(nca); |
| 124 | return std::make_pair(icon_f->ReadAllBytes(), nacp->GetApplicationName()); | 145 | return std::make_pair(icon_f->ReadAllBytes(), nacp->GetApplicationName()); |
| 125 | }); | 146 | }); |
| 126 | |||
| 127 | icon = std::move(res.first); | ||
| 128 | name = std::move(res.second); | ||
| 129 | } | 147 | } |
| 130 | 148 | ||
| 131 | bool HasSupportedFileExtension(const std::string& file_name) { | 149 | bool HasSupportedFileExtension(const std::string& file_name) { |