Replace file writes with new helper

This commit is contained in:
Pengfei
2021-07-06 16:42:22 +08:00
parent c81db424bb
commit cb6d58b538
3 changed files with 4 additions and 30 deletions
+1 -12
View File
@@ -92,12 +92,6 @@ bool Extdata::ExtractFile(const std::string& path, std::size_t index) const {
/// Maximum amount of device files a device directory can hold.
constexpr u32 DeviceDirCapacity = 126;
FileUtil::IOFile file(path, "wb");
if (!file) {
LOG_ERROR(Core, "Could not open file {}", path);
return false;
}
u32 file_index = index + 1;
u32 sub_directory_id = file_index / DeviceDirCapacity;
u32 sub_file_id = file_index % DeviceDirCapacity;
@@ -120,12 +114,7 @@ bool Extdata::ExtractFile(const std::string& path, std::size_t index) const {
return false;
}
if (file.WriteBytes(data[0].data(), data[0].size()) != data[0].size()) {
LOG_ERROR(Core, "Write data failed (file: {})", path);
return false;
}
return true;
return FileUtil::WriteBytesToFile(path, data[0].data(), data[0].size());
}
ArchiveFormatInfo Extdata::GetFormatInfo() const {
+1 -12
View File
@@ -293,18 +293,7 @@ bool SDMCImporter::ImportSystemArchive(u64 id,
return false;
}
FileUtil::IOFile target(target_path, "wb");
if (!target) {
LOG_ERROR(Core, "Could not open {}", target_path);
return false;
}
if (target.WriteBytes(romfs.data(), romfs.size()) != romfs.size()) {
LOG_ERROR(Core, "Failed to write to {}", target_path);
return false;
}
return true;
return FileUtil::WriteBytesToFile(target_path, romfs.data(), romfs.size());
}
bool SDMCImporter::ImportSysdata(u64 id,
+2 -6
View File
@@ -288,12 +288,8 @@ void UtilitiesDialog::RomFSExtractionTool() {
}
const auto& shared_romfs = Core::LoadSharedRomFS(data);
FileUtil::IOFile dest_file(destination.toStdString(), "wb");
if (dest_file.WriteBytes(shared_romfs.data(), shared_romfs.size()) != shared_romfs.size()) {
return false;
}
return true;
return FileUtil::WriteBytesToFile(destination.toStdString(), shared_romfs.data(),
shared_romfs.size());
});
}