mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-09 16:09:08 +01:00
game_list_worker: Use QFile over our own IOFile instance or std streams
Stays consistent in our code with using Qt's provided mechanisms, and also properly handles Unicode paths (which file streams on Windows don't do very well).
This commit is contained in:
parent
de2533d389
commit
d0d97de1e4
1 changed files with 24 additions and 28 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
|
||||
|
@ -46,20 +47,17 @@ QString GetGameListCachedObject(const std::string& filename, const std::string&
|
|||
if (!FileUtil::Exists(path)) {
|
||||
const auto str = generator();
|
||||
|
||||
std::ofstream stream(path);
|
||||
if (stream) {
|
||||
stream << str.toStdString();
|
||||
QFile file{QString::fromStdString(path)};
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
file.write(str.toUtf8());
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::ifstream stream(path);
|
||||
|
||||
if (stream) {
|
||||
const std::string out(std::istreambuf_iterator<char>{stream},
|
||||
std::istreambuf_iterator<char>{});
|
||||
return QString::fromStdString(out);
|
||||
QFile file{QString::fromStdString(path)};
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
return QString::fromUtf8(file.readAll());
|
||||
}
|
||||
|
||||
return generator();
|
||||
|
@ -82,53 +80,51 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject(
|
|||
if (!FileUtil::Exists(path1) || !FileUtil::Exists(path2)) {
|
||||
const auto [icon, nacp] = generator();
|
||||
|
||||
FileUtil::IOFile file1(path1, "wb");
|
||||
if (!file1.IsOpen()) {
|
||||
QFile file1{QString::fromStdString(path1)};
|
||||
if (!file1.open(QFile::WriteOnly)) {
|
||||
LOG_ERROR(Frontend, "Failed to open cache file.");
|
||||
return generator();
|
||||
}
|
||||
|
||||
if (!file1.Resize(icon.size())) {
|
||||
if (!file1.resize(icon.size())) {
|
||||
LOG_ERROR(Frontend, "Failed to resize cache file to necessary size.");
|
||||
return generator();
|
||||
}
|
||||
|
||||
if (file1.WriteBytes(icon.data(), icon.size()) != icon.size()) {
|
||||
if (file1.write(reinterpret_cast<const char*>(icon.data()), icon.size()) != icon.size()) {
|
||||
LOG_ERROR(Frontend, "Failed to write data to cache file.");
|
||||
return generator();
|
||||
}
|
||||
|
||||
std::ofstream stream2(path2, std::ios::out);
|
||||
if (stream2) {
|
||||
stream2 << nacp;
|
||||
QFile file2{QString::fromStdString(path2)};
|
||||
if (file2.open(QFile::WriteOnly)) {
|
||||
file2.write(nacp.data(), nacp.size());
|
||||
}
|
||||
|
||||
return std::make_pair(icon, nacp);
|
||||
}
|
||||
|
||||
FileUtil::IOFile file1(path1, "rb");
|
||||
std::ifstream stream2(path2);
|
||||
QFile file1(QString::fromStdString(path1));
|
||||
QFile file2(QString::fromStdString(path2));
|
||||
|
||||
if (!file1.IsOpen()) {
|
||||
if (!file1.open(QFile::ReadOnly)) {
|
||||
LOG_ERROR(Frontend, "Failed to open cache file for reading.");
|
||||
return generator();
|
||||
}
|
||||
|
||||
if (!stream2) {
|
||||
if (!file2.open(QFile::ReadOnly)) {
|
||||
LOG_ERROR(Frontend, "Failed to open cache file for reading.");
|
||||
return generator();
|
||||
}
|
||||
|
||||
std::vector<u8> vec(file1.GetSize());
|
||||
file1.ReadBytes(vec.data(), vec.size());
|
||||
|
||||
if (stream2 && !vec.empty()) {
|
||||
const std::string out(std::istreambuf_iterator<char>{stream2},
|
||||
std::istreambuf_iterator<char>{});
|
||||
return std::make_pair(vec, out);
|
||||
std::vector<u8> vec(file1.size());
|
||||
if (file1.read(reinterpret_cast<char*>(vec.data()), vec.size()) !=
|
||||
static_cast<s64>(vec.size())) {
|
||||
return generator();
|
||||
}
|
||||
|
||||
return generator();
|
||||
const auto data = file2.readAll();
|
||||
return std::make_pair(vec, data.toStdString());
|
||||
}
|
||||
|
||||
void GetMetadataFromControlNCA(const FileSys::PatchManager& patch_manager, const FileSys::NCA& nca,
|
||||
|
|
Loading…
Reference in a new issue