diff options
| author | 2019-06-05 15:03:59 -0400 | |
|---|---|---|
| committer | 2019-06-05 15:03:59 -0400 | |
| commit | 4f7a1f6c8cd294d8f625afa4728a552901a949b2 (patch) | |
| tree | 52d1323fc6d8618b31fa1f88aef54d7f1a71037e /src | |
| parent | Merge pull request #2529 from lioncash/boot (diff) | |
| parent | game_list_worker: Use QFile over our own IOFile instance or std streams (diff) | |
| download | yuzu-4f7a1f6c8cd294d8f625afa4728a552901a949b2.tar.gz yuzu-4f7a1f6c8cd294d8f625afa4728a552901a949b2.tar.xz yuzu-4f7a1f6c8cd294d8f625afa4728a552901a949b2.zip | |
Merge pull request #2536 from lioncash/cache
game_list_worker: Use QFile over our own IOFile instance or std streams for the game list cache
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/game_list_worker.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 4d951a4e7..4f30e9147 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include <QDir> | 10 | #include <QDir> |
| 11 | #include <QFile> | ||
| 11 | #include <QFileInfo> | 12 | #include <QFileInfo> |
| 12 | #include <QSettings> | 13 | #include <QSettings> |
| 13 | 14 | ||
| @@ -32,11 +33,6 @@ | |||
| 32 | 33 | ||
| 33 | namespace { | 34 | namespace { |
| 34 | 35 | ||
| 35 | template <typename T> | ||
| 36 | T GetGameListCachedObject(const std::string& filename, const std::string& ext, | ||
| 37 | const std::function<T()>& generator); | ||
| 38 | |||
| 39 | template <> | ||
| 40 | QString GetGameListCachedObject(const std::string& filename, const std::string& ext, | 36 | QString GetGameListCachedObject(const std::string& filename, const std::string& ext, |
| 41 | const std::function<QString()>& generator) { | 37 | const std::function<QString()>& generator) { |
| 42 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") { | 38 | if (!UISettings::values.cache_game_list || filename == "0000000000000000") { |
| @@ -51,26 +47,22 @@ QString GetGameListCachedObject(const std::string& filename, const std::string& | |||
| 51 | if (!FileUtil::Exists(path)) { | 47 | if (!FileUtil::Exists(path)) { |
| 52 | const auto str = generator(); | 48 | const auto str = generator(); |
| 53 | 49 | ||
| 54 | std::ofstream stream(path); | 50 | QFile file{QString::fromStdString(path)}; |
| 55 | if (stream) { | 51 | if (file.open(QFile::WriteOnly)) { |
| 56 | stream << str.toStdString(); | 52 | file.write(str.toUtf8()); |
| 57 | } | 53 | } |
| 58 | 54 | ||
| 59 | return str; | 55 | return str; |
| 60 | } | 56 | } |
| 61 | 57 | ||
| 62 | std::ifstream stream(path); | 58 | QFile file{QString::fromStdString(path)}; |
| 63 | 59 | if (file.open(QFile::ReadOnly)) { | |
| 64 | if (stream) { | 60 | return QString::fromUtf8(file.readAll()); |
| 65 | const std::string out(std::istreambuf_iterator<char>{stream}, | ||
| 66 | std::istreambuf_iterator<char>{}); | ||
| 67 | return QString::fromStdString(out); | ||
| 68 | } | 61 | } |
| 69 | 62 | ||
| 70 | return generator(); | 63 | return generator(); |
| 71 | } | 64 | } |
| 72 | 65 | ||
| 73 | template <> | ||
| 74 | std::pair<std::vector<u8>, std::string> GetGameListCachedObject( | 66 | std::pair<std::vector<u8>, std::string> GetGameListCachedObject( |
| 75 | const std::string& filename, const std::string& ext, | 67 | const std::string& filename, const std::string& ext, |
| 76 | const std::function<std::pair<std::vector<u8>, std::string>()>& generator) { | 68 | const std::function<std::pair<std::vector<u8>, std::string>()>& generator) { |
| @@ -88,58 +80,56 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject( | |||
| 88 | if (!FileUtil::Exists(path1) || !FileUtil::Exists(path2)) { | 80 | if (!FileUtil::Exists(path1) || !FileUtil::Exists(path2)) { |
| 89 | const auto [icon, nacp] = generator(); | 81 | const auto [icon, nacp] = generator(); |
| 90 | 82 | ||
| 91 | FileUtil::IOFile file1(path1, "wb"); | 83 | QFile file1{QString::fromStdString(path1)}; |
| 92 | if (!file1.IsOpen()) { | 84 | if (!file1.open(QFile::WriteOnly)) { |
| 93 | LOG_ERROR(Frontend, "Failed to open cache file."); | 85 | LOG_ERROR(Frontend, "Failed to open cache file."); |
| 94 | return generator(); | 86 | return generator(); |
| 95 | } | 87 | } |
| 96 | 88 | ||
| 97 | if (!file1.Resize(icon.size())) { | 89 | if (!file1.resize(icon.size())) { |
| 98 | LOG_ERROR(Frontend, "Failed to resize cache file to necessary size."); | 90 | LOG_ERROR(Frontend, "Failed to resize cache file to necessary size."); |
| 99 | return generator(); | 91 | return generator(); |
| 100 | } | 92 | } |
| 101 | 93 | ||
| 102 | if (file1.WriteBytes(icon.data(), icon.size()) != icon.size()) { | 94 | if (file1.write(reinterpret_cast<const char*>(icon.data()), icon.size()) != icon.size()) { |
| 103 | LOG_ERROR(Frontend, "Failed to write data to cache file."); | 95 | LOG_ERROR(Frontend, "Failed to write data to cache file."); |
| 104 | return generator(); | 96 | return generator(); |
| 105 | } | 97 | } |
| 106 | 98 | ||
| 107 | std::ofstream stream2(path2, std::ios::out); | 99 | QFile file2{QString::fromStdString(path2)}; |
| 108 | if (stream2) { | 100 | if (file2.open(QFile::WriteOnly)) { |
| 109 | stream2 << nacp; | 101 | file2.write(nacp.data(), nacp.size()); |
| 110 | } | 102 | } |
| 111 | 103 | ||
| 112 | return std::make_pair(icon, nacp); | 104 | return std::make_pair(icon, nacp); |
| 113 | } | 105 | } |
| 114 | 106 | ||
| 115 | FileUtil::IOFile file1(path1, "rb"); | 107 | QFile file1(QString::fromStdString(path1)); |
| 116 | std::ifstream stream2(path2); | 108 | QFile file2(QString::fromStdString(path2)); |
| 117 | 109 | ||
| 118 | if (!file1.IsOpen()) { | 110 | if (!file1.open(QFile::ReadOnly)) { |
| 119 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); | 111 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); |
| 120 | return generator(); | 112 | return generator(); |
| 121 | } | 113 | } |
| 122 | 114 | ||
| 123 | if (!stream2) { | 115 | if (!file2.open(QFile::ReadOnly)) { |
| 124 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); | 116 | LOG_ERROR(Frontend, "Failed to open cache file for reading."); |
| 125 | return generator(); | 117 | return generator(); |
| 126 | } | 118 | } |
| 127 | 119 | ||
| 128 | std::vector<u8> vec(file1.GetSize()); | 120 | std::vector<u8> vec(file1.size()); |
| 129 | file1.ReadBytes(vec.data(), vec.size()); | 121 | if (file1.read(reinterpret_cast<char*>(vec.data()), vec.size()) != |
| 130 | 122 | static_cast<s64>(vec.size())) { | |
| 131 | if (stream2 && !vec.empty()) { | 123 | return generator(); |
| 132 | const std::string out(std::istreambuf_iterator<char>{stream2}, | ||
| 133 | std::istreambuf_iterator<char>{}); | ||
| 134 | return std::make_pair(vec, out); | ||
| 135 | } | 124 | } |
| 136 | 125 | ||
| 137 | return generator(); | 126 | const auto data = file2.readAll(); |
| 127 | return std::make_pair(vec, data.toStdString()); | ||
| 138 | } | 128 | } |
| 139 | 129 | ||
| 140 | void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager, const FileSys::NCA& nca, | 130 | void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager, const FileSys::NCA& nca, |
| 141 | std::vector<u8>& icon, std::string& name) { | 131 | std::vector<u8>& icon, std::string& name) { |
| 142 | std::tie(icon, name) = GetGameListCachedObject<std::pair<std::vector<u8>, std::string>>( | 132 | std::tie(icon, name) = GetGameListCachedObject( |
| 143 | fmt::format("{:016X}", patch_manager.GetTitleID()), {}, [&patch_manager, &nca] { | 133 | fmt::format("{:016X}", patch_manager.GetTitleID()), {}, [&patch_manager, &nca] { |
| 144 | const auto [nacp, icon_f] = patch_manager.ParseControlNCA(nca); | 134 | const auto [nacp, icon_f] = patch_manager.ParseControlNCA(nca); |
| 145 | return std::make_pair(icon_f->ReadAllBytes(), nacp->GetApplicationName()); | 135 | return std::make_pair(icon_f->ReadAllBytes(), nacp->GetApplicationName()); |
| @@ -221,7 +211,7 @@ QList<QStandardItem*> MakeGameListEntry(const std::string& path, const std::stri | |||
| 221 | }; | 211 | }; |
| 222 | 212 | ||
| 223 | if (UISettings::values.show_add_ons) { | 213 | if (UISettings::values.show_add_ons) { |
| 224 | const auto patch_versions = GetGameListCachedObject<QString>( | 214 | const auto patch_versions = GetGameListCachedObject( |
| 225 | fmt::format("{:016X}", patch.GetTitleID()), "pv.txt", [&patch, &loader] { | 215 | fmt::format("{:016X}", patch.GetTitleID()), "pv.txt", [&patch, &loader] { |
| 226 | return FormatPatchNameVersions(patch, loader, loader.IsRomFSUpdatable()); | 216 | return FormatPatchNameVersions(patch, loader, loader.IsRomFSUpdatable()); |
| 227 | }); | 217 | }); |