From 2f5bb45d587e554bc5c50b8edeb69bbdf84e35f3 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Tue, 16 May 2023 20:49:31 +0300 Subject: [PATCH] [FS] OpenArchiveHandle returns Result --- include/services/fs.hpp | 2 +- src/core/fs/archive_sdmc.cpp | 2 +- src/core/services/fs.cpp | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/services/fs.hpp b/include/services/fs.hpp index 48fada6e..e79dbf02 100644 --- a/include/services/fs.hpp +++ b/include/services/fs.hpp @@ -31,7 +31,7 @@ class FSService { ExtSaveDataArchive sharedExtSaveData_cart; ArchiveBase* getArchiveFromID(u32 id, const FSPath& archivePath); - std::optional openArchiveHandle(u32 archiveID, const FSPath& path); + Rust::Result openArchiveHandle(u32 archiveID, const FSPath& path); Rust::Result openDirectoryHandle(ArchiveBase* archive, const FSPath& path); std::optional openFileHandle(ArchiveBase* archive, const FSPath& path, const FSPath& archivePath, const FilePerms& perms); FSPath readPath(u32 type, u32 pointer, u32 size); diff --git a/src/core/fs/archive_sdmc.cpp b/src/core/fs/archive_sdmc.cpp index 23564eaa..0759fcee 100644 --- a/src/core/fs/archive_sdmc.cpp +++ b/src/core/fs/archive_sdmc.cpp @@ -18,7 +18,7 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) Rust::Result SDMCArchive::openArchive(const FSPath& path) { printf("SDMCArchive::OpenArchive: Failed\n"); - return Ok((ArchiveBase*)nullptr); + return Err(FSResult::NotFormatted); } std::optional SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) { diff --git a/src/core/services/fs.cpp b/src/core/services/fs.cpp index 080c0b49..b790e229 100644 --- a/src/core/services/fs.cpp +++ b/src/core/services/fs.cpp @@ -121,12 +121,12 @@ Rust::Result FSService::openDirectoryHandle(ArchiveBase* archi } } -std::optional FSService::openArchiveHandle(u32 archiveID, const FSPath& path) { +Rust::Result FSService::openArchiveHandle(u32 archiveID, const FSPath& path) { ArchiveBase* archive = getArchiveFromID(archiveID, path); if (archive == nullptr) [[unlikely]] { Helpers::panic("OpenArchive: Tried to open unknown archive %d.", archiveID); - return std::nullopt; + return Err(FSResult::NotFormatted); } Rust::Result res = archive->openArchive(path); @@ -135,10 +135,10 @@ std::optional FSService::openArchiveHandle(u32 archiveID, const FSPath& auto& archiveObject = kernel.getObjects()[handle]; archiveObject.data = new ArchiveSession(res.unwrap(), path); - return handle; + return Ok(handle); } else { - return std::nullopt; + return Err(res.unwrapErr()); } } @@ -216,14 +216,14 @@ void FSService::openArchive(u32 messagePointer) { auto archivePath = readPath(archivePathType, archivePathPointer, archivePathSize); log("FS::OpenArchive(archive ID = %d, archive path type = %d)\n", archiveID, archivePathType); - std::optional handle = openArchiveHandle(archiveID, archivePath); + Rust::Result res = openArchiveHandle(archiveID, archivePath); mem.write32(messagePointer, IPC::responseHeader(0x80C, 3, 0)); - if (handle.has_value()) { + if (res.isOk()) { mem.write32(messagePointer + 4, ResultCode::Success); - mem.write64(messagePointer + 8, handle.value()); + mem.write64(messagePointer + 8, res.unwrap()); } else { log("FS::OpenArchive: Failed to open archive with id = %d\n", archiveID); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, static_cast(res.unwrapErr())); } }