From cb6d58b5381fed91ca3ff843b21153be37e5b1aa Mon Sep 17 00:00:00 2001 From: Pengfei Date: Tue, 6 Jul 2021 16:42:22 +0800 Subject: [PATCH] Replace file writes with new helper --- src/core/extdata.cpp | 13 +------------ src/core/importer.cpp | 13 +------------ src/frontend/utilities.cpp | 8 ++------ 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/core/extdata.cpp b/src/core/extdata.cpp index 08dddfb..c3d8ed6 100644 --- a/src/core/extdata.cpp +++ b/src/core/extdata.cpp @@ -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 { diff --git a/src/core/importer.cpp b/src/core/importer.cpp index 28e8f77..731a782 100644 --- a/src/core/importer.cpp +++ b/src/core/importer.cpp @@ -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, diff --git a/src/frontend/utilities.cpp b/src/frontend/utilities.cpp index 2ce3ab5..5e4ae24 100644 --- a/src/frontend/utilities.cpp +++ b/src/frontend/utilities.cpp @@ -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()); }); }