mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
[FS] Archive::OpenArchive returns Result<T, E> now
This commit is contained in:
parent
37fb660c7f
commit
0b0d6dcf4b
12 changed files with 25 additions and 24 deletions
|
@ -217,8 +217,8 @@ public:
|
||||||
|
|
||||||
// Returns nullopt if opening the file failed, otherwise returns a file descriptor to it (nullptr if none is needed)
|
// 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;
|
virtual FileDescriptor openFile(const FSPath& path, const FilePerms& perms) = 0;
|
||||||
|
virtual Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) = 0;
|
||||||
|
|
||||||
virtual ArchiveBase* openArchive(const FSPath& path) = 0;
|
|
||||||
virtual Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) {
|
virtual Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) {
|
||||||
Helpers::panic("Unimplemented OpenDirectory for %s archive", name().c_str());
|
Helpers::panic("Unimplemented OpenDirectory for %s archive", name().c_str());
|
||||||
return Err(FSResult::FileNotFound);
|
return Err(FSResult::FileNotFound);
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
FSResult createFile(const FSPath& path, u64 size) override;
|
FSResult createFile(const FSPath& path, u64 size) override;
|
||||||
FSResult deleteFile(const FSPath& path) override;
|
FSResult deleteFile(const FSPath& path) override;
|
||||||
|
|
||||||
ArchiveBase* openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) override;
|
||||||
Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) override;
|
Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) override;
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
FSResult createFile(const FSPath& path, u64 size) override;
|
FSResult createFile(const FSPath& path, u64 size) override;
|
||||||
FSResult deleteFile(const FSPath& path) override;
|
FSResult deleteFile(const FSPath& path) override;
|
||||||
|
|
||||||
ArchiveBase* openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) override;
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
FSResult deleteFile(const FSPath& path) override;
|
FSResult deleteFile(const FSPath& path) override;
|
||||||
FormatInfo getFormatInfo(const FSPath& path) override;
|
FormatInfo getFormatInfo(const FSPath& path) override;
|
||||||
|
|
||||||
ArchiveBase* openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) override;
|
||||||
Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) override;
|
Rust::Result<DirectorySession, FSResult> openDirectory(const FSPath& path) override;
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
FSResult createFile(const FSPath& path, u64 size) override;
|
FSResult createFile(const FSPath& path, u64 size) override;
|
||||||
FSResult deleteFile(const FSPath& path) override;
|
FSResult deleteFile(const FSPath& path) override;
|
||||||
|
|
||||||
ArchiveBase* openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) override;
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
||||||
};
|
};
|
|
@ -11,7 +11,7 @@ public:
|
||||||
FSResult createFile(const FSPath& path, u64 size) override;
|
FSResult createFile(const FSPath& path, u64 size) override;
|
||||||
FSResult deleteFile(const FSPath& path) override;
|
FSResult deleteFile(const FSPath& path) override;
|
||||||
|
|
||||||
ArchiveBase* openArchive(const FSPath& path) override;
|
Rust::Result<ArchiveBase*, FSResult> openArchive(const FSPath& path) override;
|
||||||
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
|
||||||
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
|
||||||
|
|
||||||
|
|
|
@ -70,12 +70,12 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
|
||||||
return FileError;
|
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) {
|
if (path.type != PathType::Binary || path.binary.size() != 12) {
|
||||||
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
|
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) {
|
Rust::Result<DirectorySession, FSResult> ExtSaveDataArchive::openDirectory(const FSPath& path) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms)
|
||||||
return NoFile;
|
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) {
|
if (path.type != PathType::Binary || path.binary.size() != 16) {
|
||||||
Helpers::panic("NCCHArchive::OpenArchive: Invalid path");
|
Helpers::panic("NCCHArchive::OpenArchive: Invalid path");
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ ArchiveBase* NCCHArchive::openArchive(const FSPath& path) {
|
||||||
if (mediaType != 0)
|
if (mediaType != 0)
|
||||||
Helpers::panic("NCCH archive. Tried to access a mediatype other than the NAND. Type: %d", mediaType);
|
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) {
|
std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||||
|
|
|
@ -98,13 +98,13 @@ ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
|
||||||
return FormatInfo{ .size = 0, .numOfDirectories = 255, .numOfFiles = 255, .duplicateData = false };
|
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) {
|
if (path.type != PathType::Empty) {
|
||||||
Helpers::panic("Unimplemented path type for SaveData archive: %d\n", path.type);
|
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) {
|
std::optional<u32> SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||||
|
|
|
@ -16,9 +16,9 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms)
|
||||||
return FileError;
|
return FileError;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveBase* SDMCArchive::openArchive(const FSPath& path) {
|
Rust::Result<ArchiveBase*, FSResult> SDMCArchive::openArchive(const FSPath& path) {
|
||||||
printf("SDMCArchive::OpenArchive: Failed\n");
|
printf("SDMCArchive::OpenArchive: Failed\n");
|
||||||
return nullptr;
|
return Ok((ArchiveBase*)nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u32> SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
std::optional<u32> SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||||
|
|
|
@ -40,13 +40,13 @@ FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& pe
|
||||||
return NoFile; // No file descriptor needed for RomFS
|
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) {
|
if (path.type != PathType::Empty) {
|
||||||
printf("Invalid path type for SelfNCCH archive: %d\n", path.type);
|
Helpers::panic("Invalid path type for SelfNCCH archive: %d\n", path.type);
|
||||||
return nullptr;
|
return Err(FSResult::NotFoundInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return Ok((ArchiveBase*)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||||
|
|
|
@ -129,11 +129,11 @@ std::optional<Handle> FSService::openArchiveHandle(u32 archiveID, const FSPath&
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool opened = archive->openArchive(path);
|
Rust::Result<ArchiveBase*, FSResult> res = archive->openArchive(path);
|
||||||
if (opened) {
|
if (res.isOk()) {
|
||||||
auto handle = kernel.makeObject(KernelObjectType::Archive);
|
auto handle = kernel.makeObject(KernelObjectType::Archive);
|
||||||
auto& archiveObject = kernel.getObjects()[handle];
|
auto& archiveObject = kernel.getObjects()[handle];
|
||||||
archiveObject.data = new ArchiveSession(archive, path);
|
archiveObject.data = new ArchiveSession(res.unwrap(), path);
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@ -334,10 +334,11 @@ void FSService::openFileDirectly(u32 messagePointer) {
|
||||||
auto filePath = readPath(filePathType, filePathPointer, filePathSize);
|
auto filePath = readPath(filePathType, filePathPointer, filePathSize);
|
||||||
const FilePerms perms(openFlags);
|
const FilePerms perms(openFlags);
|
||||||
|
|
||||||
archive = archive->openArchive(archivePath);
|
Rust::Result<ArchiveBase*, FSResult> res = archive->openArchive(archivePath);
|
||||||
if (archive == nullptr) [[unlikely]] {
|
if (res.isErr()) [[unlikely]] {
|
||||||
Helpers::panic("OpenFileDirectly: Failed to open archive with given path");
|
Helpers::panic("OpenFileDirectly: Failed to open archive with given path");
|
||||||
}
|
}
|
||||||
|
archive = res.unwrap();
|
||||||
|
|
||||||
std::optional<Handle> handle = openFileHandle(archive, filePath, archivePath, perms);
|
std::optional<Handle> handle = openFileHandle(archive, filePath, archivePath, perms);
|
||||||
mem.write32(messagePointer, IPC::responseHeader(0x803, 1, 2));
|
mem.write32(messagePointer, IPC::responseHeader(0x803, 1, 2));
|
||||||
|
|
Loading…
Add table
Reference in a new issue