[FS] Archive::OpenArchive returns Result<T, E> now

This commit is contained in:
wheremyfoodat 2023-05-14 19:31:51 +03:00
parent 37fb660c7f
commit 0b0d6dcf4b
12 changed files with 25 additions and 24 deletions

View file

@ -70,12 +70,12 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
return FileError;
}
ArchiveBase* ExtSaveDataArchive::openArchive(const FSPath& path) {
Rust::Result<ArchiveBase*, FSResult> ExtSaveDataArchive::openArchive(const FSPath& path) {
if (path.type != PathType::Binary || path.binary.size() != 12) {
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
}
return this;
return Ok((ArchiveBase*)this);
}
Rust::Result<DirectorySession, FSResult> ExtSaveDataArchive::openDirectory(const FSPath& path) {

View file

@ -48,7 +48,7 @@ FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms)
return NoFile;
}
ArchiveBase* NCCHArchive::openArchive(const FSPath& path) {
Rust::Result<ArchiveBase*, FSResult> NCCHArchive::openArchive(const FSPath& path) {
if (path.type != PathType::Binary || path.binary.size() != 16) {
Helpers::panic("NCCHArchive::OpenArchive: Invalid path");
}
@ -57,7 +57,7 @@ ArchiveBase* NCCHArchive::openArchive(const FSPath& path) {
if (mediaType != 0)
Helpers::panic("NCCH archive. Tried to access a mediatype other than the NAND. Type: %d", mediaType);
return this;
return Ok((ArchiveBase*)this);
}
std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {

View file

@ -98,13 +98,13 @@ ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
return FormatInfo{ .size = 0, .numOfDirectories = 255, .numOfFiles = 255, .duplicateData = false };
}
ArchiveBase* SaveDataArchive::openArchive(const FSPath& path) {
Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath& path) {
if (path.type != PathType::Empty) {
Helpers::panic("Unimplemented path type for SaveData archive: %d\n", path.type);
return nullptr;
return Err(FSResult::NotFoundInvalid);
}
return this;
return Ok((ArchiveBase*)this);
}
std::optional<u32> SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {

View file

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

View file

@ -40,13 +40,13 @@ FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& pe
return NoFile; // No file descriptor needed for RomFS
}
ArchiveBase* SelfNCCHArchive::openArchive(const FSPath& path) {
Rust::Result<ArchiveBase*, FSResult> SelfNCCHArchive::openArchive(const FSPath& path) {
if (path.type != PathType::Empty) {
printf("Invalid path type for SelfNCCH archive: %d\n", path.type);
return nullptr;
Helpers::panic("Invalid path type for SelfNCCH archive: %d\n", path.type);
return Err(FSResult::NotFoundInvalid);
}
return this;
return Ok((ArchiveBase*)this);
}
std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {