diff --git a/include/fs/archive_base.hpp b/include/fs/archive_base.hpp index 72255605..d9c7fb0f 100644 --- a/include/fs/archive_base.hpp +++ b/include/fs/archive_base.hpp @@ -61,7 +61,7 @@ namespace MediaType { enum : u8 { NAND = 0, SD = 1, - Gamecard = 2 + Gamecard = 2, }; }; @@ -230,26 +230,26 @@ public: virtual HorizonResult createFile(const FSPath& path, u64 size) = 0; virtual HorizonResult deleteFile(const FSPath& path) = 0; - virtual Rust::Result getFormatInfo(const FSPath& path) { - Helpers::panic("Unimplemented GetFormatInfo for %s archive", name().c_str()); - // Return a dummy struct just to avoid the UB of not returning anything, even if we panic - return Ok(FormatInfo{ .size = 0, .numOfDirectories = 0, .numOfFiles = 0, .duplicateData = false }); - } + virtual Rust::Result getFormatInfo(const FSPath& path) { + Helpers::panic("Unimplemented GetFormatInfo for %s archive", name().c_str()); + // Return a dummy struct just to avoid the UB of not returning anything, even if we panic + return Ok(FormatInfo{.size = 0, .numOfDirectories = 0, .numOfFiles = 0, .duplicateData = false}); + } virtual HorizonResult createDirectory(const FSPath& path) { - Helpers::panic("Unimplemented CreateDirectory for %s archive", name().c_str()); - return Result::FS::AlreadyExists; - } + Helpers::panic("Unimplemented CreateDirectory for %s archive", name().c_str()); + return Result::FS::AlreadyExists; + } virtual HorizonResult deleteDirectory(const FSPath& path) { - Helpers::warn("Stubbed DeleteDirectory for %s archive", name().c_str()); - return Result::Success; - } + Helpers::warn("Stubbed DeleteDirectory for %s archive", name().c_str()); + return Result::Success; + } virtual HorizonResult deleteDirectoryRecursively(const FSPath& path) { - Helpers::warn("Stubbed DeleteDirectoryRecursively for %s archive", name().c_str()); - return Result::Success; - } + Helpers::warn("Stubbed DeleteDirectoryRecursively for %s archive", name().c_str()); + return Result::Success; + } // Returns nullopt if opening the file failed, otherwise returns a file descriptor to it (nullptr if none is needed) virtual FileDescriptor openFile(const FSPath& path, const FilePerms& perms) = 0; diff --git a/src/core/fs/archive_ext_save_data.cpp b/src/core/fs/archive_ext_save_data.cpp index 6c88fc4e..184600af 100644 --- a/src/core/fs/archive_ext_save_data.cpp +++ b/src/core/fs/archive_ext_save_data.cpp @@ -208,7 +208,7 @@ void ExtSaveDataArchive::format(const FSPath& path, const FormatInfo& info) { fs::remove_all(saveDataPath); fs::create_directories(saveDataPath); - if(!isShared) { + if (!isShared) { fs::create_directories(saveDataPath / "user"); fs::create_directories(saveDataPath / "boss"); // todo: save icon. @@ -246,12 +246,13 @@ Rust::Result, HorizonResult> ExtSaveDataArchive::loadIcon() cons const fs::path iconPath = IOFile::getAppData() / backingFolder / "icon"; IOFile file(iconPath, "rb"); const s32 size = static_cast(file.size().value_or(-1)); - if(size < 0) { + if (size < 0) { return Err(Result::FS::NotFoundInvalid); } - std::unique_ptr data(new u8[size]); - file.readBytes(data.get(), size); - return Ok(std::vector(data.get(), data.get() + size)); + + std::vector icon(size); + file.readBytes(icon.data(), size); + return Ok(icon); } std::filesystem::path ExtSaveDataArchive::getFormatInfoPath(const FSPath& path) const { @@ -260,7 +261,7 @@ std::filesystem::path ExtSaveDataArchive::getFormatInfoPath(const FSPath& path) std::filesystem::path ExtSaveDataArchive::getUserDataPath() const { fs::path p = IOFile::getAppData() / backingFolder; - if(!isShared) { // todo: "boss"? + if (!isShared) { // todo: "boss"? p /= "user"; } return p; @@ -289,7 +290,7 @@ Rust::Result ExtSaveDataArchive::getForm } std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) const { - if(path.type != PathType::Binary) { + if (path.type != PathType::Binary) { Helpers::panic("GetExtSaveDataPathFromBinary called without a Binary FSPath!"); } diff --git a/src/core/services/fs.cpp b/src/core/services/fs.cpp index 657cb50d..da09c355 100644 --- a/src/core/services/fs.cpp +++ b/src/core/services/fs.cpp @@ -165,8 +165,9 @@ FSPath FSService::readPath(u32 type, u32 pointer, u32 size) { } void FSService::writePointer(const u8* data, u32 pointer, u32 size) { - for (u32 i = 0; i < size; i++) + for (u32 i = 0; i < size; i++) { mem.write8(pointer + i, data[i]); + } } void FSService::handleSyncRequest(u32 messagePointer) { @@ -535,16 +536,10 @@ void FSService::deleteExtSaveData(u32 messagePointer) { /* FSPath path = readPath(PathType::Binary, messagePointer + 4, 8); - switch(mediaType) { - case MediaType::NAND: - sharedExtSaveData_nand.clear(path); - break; - case MediaType::SD: - extSaveData_sdmc.clear(path); - break; - default: - Helpers::warn("FS::DeleteExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast(mediaType)); - break; + switch (mediaType) { + case MediaType::NAND: sharedExtSaveData_nand.clear(path); break; + case MediaType::SD: extSaveData_sdmc.clear(path); break; + default: Helpers::warn("FS::DeleteExtSaveData: Unhandled ExtSaveData MediaType %d", static_cast(mediaType)); break; } */ @@ -575,20 +570,15 @@ void FSService::createExtSaveData(u32 messagePointer) { ExtSaveDataArchive* selected = nullptr; switch(mediaType) { - case MediaType::NAND: - selected = &sharedExtSaveData_nand; - break; - case MediaType::SD: - selected = &extSaveData_sdmc; - break; - default: - Helpers::warn("FS::CreateExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast(mediaType)); - break; + case MediaType::NAND: selected = &sharedExtSaveData_nand; break; + case MediaType::SD: selected = &extSaveData_sdmc; break; + default: Helpers::warn("FS::CreateExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast(mediaType)); break; } if (selected != nullptr) { selected->format(path, info); - if(smdhSize > 0) { + + if (smdhSize > 0) { const FSPath smdh = readPath(PathType::Binary, smdhPointer, smdhSize); selected->saveIcon(smdh.binary); } @@ -621,7 +611,7 @@ void FSService::readExtSaveDataIcon(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x0851, 1, 0)); Rust::Result, HorizonResult> data = selected == nullptr ? Err(Result::FS::NotFoundInvalid) : selected->loadIcon(); - if(data.isErr()) { + if (data.isErr()) { mem.write32(messagePointer + 4, data.unwrapErr());; mem.write32(messagePointer + 8, 0); } else {