Add IOFile::GetData

This commit is contained in:
zhupengfei
2020-11-28 20:12:24 +08:00
parent 9cbec118cd
commit 5c595a8046
6 changed files with 39 additions and 55 deletions
+4 -11
View File
@@ -80,20 +80,13 @@ std::vector<u8> SDMCDecryptor::DecryptFile(const std::string& source) const {
aes.SetKeyWithIV(key.data(), key.size(), ctr.data());
FileUtil::IOFile file(root_folder + source, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open {}", root_folder + source);
std::vector<u8> encrypted_data = file.GetData();
if (encrypted_data.empty()) {
LOG_ERROR(Core, "Failed to read from {}", root_folder + source);
return {};
}
auto size = file.GetSize();
std::vector<u8> encrypted_data(size);
if (file.ReadBytes(encrypted_data.data(), size) != size) {
LOG_ERROR(Core, "Could not read file {}", root_folder + source);
return {};
}
std::vector<u8> data(size);
std::vector<u8> data(file.GetSize());
aes.ProcessData(data.data(), encrypted_data.data(), encrypted_data.size());
return data;
}
+9 -27
View File
@@ -194,13 +194,8 @@ bool SDMCImporter::ImportNandSavegame(u64 id, [[maybe_unused]] const ProgressCal
const auto path = fmt::format("sysdata/{:08x}/00000000", (id & 0xFFFFFFFF));
FileUtil::IOFile file(config.nand_data_path + path, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open file {}", path);
return false;
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
std::vector<u8> data = file.GetData();
if (data.empty()) {
LOG_ERROR(Core, "Failed to read from {}", path);
return false;
}
@@ -248,13 +243,8 @@ bool SDMCImporter::ImportSystemArchive(u64 id, [[maybe_unused]] const ProgressCa
const auto path = fmt::format("{}{:08x}/{:08x}.app", config.system_archives_path, (id >> 32),
(id & 0xFFFFFFFF));
FileUtil::IOFile file(path, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open {}", path);
return false;
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
std::vector<u8> data = file.GetData();
if (data.empty()) {
LOG_ERROR(Core, "Failed to read from {}", path);
return false;
}
@@ -373,12 +363,8 @@ bool SDMCImporter::ImportSysdata(u64 id, [[maybe_unused]] const ProgressCallback
}
case 5: { // Config savegame
FileUtil::IOFile file(config.config_savegame_path, "rb");
if (!file) {
return false;
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
std::vector<u8> data = file.GetData();
if (data.empty()) {
return false;
}
@@ -808,16 +794,12 @@ void SDMCImporter::ListNandSavegame(std::vector<ContentSpecifier>& out) const {
// Read the file to test.
FileUtil::IOFile file(path, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open {}", path);
return false;
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
std::vector<u8> data = file.GetData();
if (data.empty()) {
LOG_ERROR(Core, "Could not read from {}", path);
return false;
}
DataContainer container(std::move(data));
if (!container.IsGood()) {
return true;
+1 -11
View File
@@ -279,17 +279,7 @@ std::vector<u8> SDExtdata::ReadFile(const std::string& path) const {
return decryptor->DecryptFile(path);
} else {
FileUtil::IOFile file(path, "rb");
if (!file) {
LOG_ERROR(Core, "Failed to open {}", path);
return {};
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
LOG_ERROR(Core, "Failed to read from {}", path);
return {};
}
return data;
return file.GetData();
}
}