[FS] OpenArchiveHandle returns Result<T, E>

This commit is contained in:
wheremyfoodat 2023-05-16 20:49:31 +03:00
parent b817c72a9c
commit 2f5bb45d58
3 changed files with 10 additions and 10 deletions

View file

@ -31,7 +31,7 @@ class FSService {
ExtSaveDataArchive sharedExtSaveData_cart;
ArchiveBase* getArchiveFromID(u32 id, const FSPath& archivePath);
std::optional<Handle> openArchiveHandle(u32 archiveID, const FSPath& path);
Rust::Result<Handle, FSResult> openArchiveHandle(u32 archiveID, const FSPath& path);
Rust::Result<Handle, FSResult> openDirectoryHandle(ArchiveBase* archive, const FSPath& path);
std::optional<Handle> openFileHandle(ArchiveBase* archive, const FSPath& path, const FSPath& archivePath, const FilePerms& perms);
FSPath readPath(u32 type, u32 pointer, u32 size);

View file

@ -18,7 +18,7 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms)
Rust::Result<ArchiveBase*, FSResult> SDMCArchive::openArchive(const FSPath& path) {
printf("SDMCArchive::OpenArchive: Failed\n");
return Ok((ArchiveBase*)nullptr);
return Err(FSResult::NotFormatted);
}
std::optional<u32> SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {

View file

@ -121,12 +121,12 @@ Rust::Result<Handle, FSResult> FSService::openDirectoryHandle(ArchiveBase* archi
}
}
std::optional<Handle> FSService::openArchiveHandle(u32 archiveID, const FSPath& path) {
Rust::Result<Handle, FSResult> 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<ArchiveBase*, FSResult> res = archive->openArchive(path);
@ -135,10 +135,10 @@ std::optional<Handle> 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> handle = openArchiveHandle(archiveID, archivePath);
Rust::Result<Handle, FSResult> 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<u32>(res.unwrapErr()));
}
}