mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-21 21:05:50 +12:00
hle: Add proper type for result code
This should clean up all HLE errorcode in the codebase. I didn't removed Rust::Result as this should be a cleanup for another iteration.
This commit is contained in:
parent
c6f5d19983
commit
122b1b2727
73 changed files with 540 additions and 419 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
FSResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
HorizonResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
if (size == 0)
|
||||
Helpers::panic("ExtSaveData file does not support size == 0");
|
||||
|
||||
|
@ -15,22 +15,22 @@ FSResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
|||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::exists(p))
|
||||
return FSResult::AlreadyExists;
|
||||
|
||||
return Result::FS::AlreadyExists;
|
||||
|
||||
// Create a file of size "size" by creating an empty one, seeking to size - 1 and just writing a 0 there
|
||||
IOFile file(p.string().c_str(), "wb");
|
||||
if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) {
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
return FSResult::FileTooLarge;
|
||||
return Result::FS::FileTooLarge;
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::OpenFile: Failed");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
||||
HorizonResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in ExtSaveData::DeleteFile");
|
||||
|
@ -43,7 +43,7 @@ FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
|||
}
|
||||
|
||||
if (!fs::is_regular_file(p)) {
|
||||
return FSResult::FileNotFound;
|
||||
return Result::FS::FileNotFoundAlt;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
@ -55,11 +55,11 @@ FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
|||
Helpers::warn("ExtSaveData::DeleteFile: fs::remove failed\n");
|
||||
}
|
||||
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::DeleteFile: Unknown path type");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -95,7 +95,7 @@ std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path)
|
|||
return backingFolder + std::to_string(saveLow) + std::to_string(saveHigh);
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> ExtSaveDataArchive::openArchive(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase*, HorizonResult> ExtSaveDataArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Binary || path.binary.size() != 12) {
|
||||
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
|
||||
}
|
||||
|
@ -105,13 +105,13 @@ Rust::Result<ArchiveBase*, FSResult> ExtSaveDataArchive::openArchive(const FSPat
|
|||
// fs::path formatInfopath = IOFile::getAppData() / "FormatInfo" / (getExtSaveDataPathFromBinary(path) + ".format");
|
||||
// Format info not found so the archive is not formatted
|
||||
// if (!fs::is_regular_file(formatInfopath)) {
|
||||
// return isShared ? Err(FSResult::NotFormatted) : Err(FSResult::NotFoundInvalid);
|
||||
// return isShared ? Err(Result::FS::NotFormatted) : Err(Result::FS::NotFoundInvalid);
|
||||
//}
|
||||
|
||||
return Ok((ArchiveBase*)this);
|
||||
}
|
||||
|
||||
Rust::Result<DirectorySession, FSResult> ExtSaveDataArchive::openDirectory(const FSPath& path) {
|
||||
Rust::Result<DirectorySession, HorizonResult> ExtSaveDataArchive::openDirectory(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in ExtSaveData::OpenDirectory");
|
||||
|
@ -121,18 +121,18 @@ Rust::Result<DirectorySession, FSResult> ExtSaveDataArchive::openDirectory(const
|
|||
|
||||
if (fs::is_regular_file(p)) {
|
||||
printf("ExtSaveData: OpenArchive used with a file path");
|
||||
return Err(FSResult::UnexpectedFileOrDir);
|
||||
return Err(Result::FS::UnexpectedFileOrDir);
|
||||
}
|
||||
|
||||
if (fs::is_directory(p)) {
|
||||
return Ok(DirectorySession(this, p));
|
||||
} else {
|
||||
return Err(FSResult::FileNotFound);
|
||||
return Err(Result::FS::FileNotFoundAlt);
|
||||
}
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::OpenDirectory: Unimplemented path type");
|
||||
return Err(FSResult::Success);
|
||||
return Err(Result::Success);
|
||||
}
|
||||
|
||||
std::optional<u32> ExtSaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||
|
|
|
@ -21,14 +21,14 @@ namespace MediaType {
|
|||
};
|
||||
};
|
||||
|
||||
FSResult NCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
HorizonResult NCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[NCCH] CreateFile not yet supported");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FSResult NCCHArchive::deleteFile(const FSPath& path) {
|
||||
HorizonResult NCCHArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[NCCH] Unimplemented DeleteFile");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -48,7 +48,7 @@ FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms)
|
|||
return NoFile;
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> NCCHArchive::openArchive(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase*, HorizonResult> NCCHArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Binary || path.binary.size() != 16) {
|
||||
Helpers::panic("NCCHArchive::OpenArchive: Invalid path");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
HorizonResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in SaveData::CreateFile");
|
||||
|
@ -13,28 +13,28 @@ FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
|||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::exists(p))
|
||||
return FSResult::AlreadyExists;
|
||||
|
||||
return Result::FS::AlreadyExists;
|
||||
|
||||
IOFile file(p.string().c_str(), "wb");
|
||||
|
||||
|
||||
// If the size is 0, leave the file empty and return success
|
||||
if (size == 0) {
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
// If it is not empty, seek to size - 1 and write a 0 to create a file of size "size"
|
||||
else if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) {
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
return FSResult::FileTooLarge;
|
||||
return Result::FS::FileTooLarge;
|
||||
}
|
||||
|
||||
Helpers::panic("SaveDataArchive::OpenFile: Failed");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FSResult SaveDataArchive::createDirectory(const FSPath& path) {
|
||||
HorizonResult SaveDataArchive::createDirectory(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in SaveData::OpenFile");
|
||||
|
@ -43,19 +43,19 @@ FSResult SaveDataArchive::createDirectory(const FSPath& path) {
|
|||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::is_directory(p))
|
||||
return FSResult::AlreadyExists;
|
||||
return Result::FS::AlreadyExists;
|
||||
if (fs::is_regular_file(p)) {
|
||||
Helpers::panic("File path passed to SaveData::CreateDirectory");
|
||||
}
|
||||
|
||||
bool success = fs::create_directory(p);
|
||||
return success ? FSResult::Success : FSResult::UnexpectedFileOrDir;
|
||||
return success ? Result::Success : Result::FS::UnexpectedFileOrDir;
|
||||
} else {
|
||||
Helpers::panic("Unimplemented SaveData::CreateDirectory");
|
||||
}
|
||||
}
|
||||
|
||||
FSResult SaveDataArchive::deleteFile(const FSPath& path) {
|
||||
HorizonResult SaveDataArchive::deleteFile(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in SaveData::DeleteFile");
|
||||
|
@ -68,7 +68,7 @@ FSResult SaveDataArchive::deleteFile(const FSPath& path) {
|
|||
}
|
||||
|
||||
if (!fs::is_regular_file(p)) {
|
||||
return FSResult::FileNotFound;
|
||||
return Result::FS::FileNotFoundAlt;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
|
@ -80,11 +80,11 @@ FSResult SaveDataArchive::deleteFile(const FSPath& path) {
|
|||
Helpers::warn("SaveData::DeleteFile: fs::remove failed\n");
|
||||
}
|
||||
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
Helpers::panic("SaveDataArchive::DeleteFile: Unknown path type");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -121,7 +121,7 @@ FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& pe
|
|||
return FileError;
|
||||
}
|
||||
|
||||
Rust::Result<DirectorySession, FSResult> SaveDataArchive::openDirectory(const FSPath& path) {
|
||||
Rust::Result<DirectorySession, HorizonResult> SaveDataArchive::openDirectory(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in SaveData::OpenDirectory");
|
||||
|
@ -131,34 +131,34 @@ Rust::Result<DirectorySession, FSResult> SaveDataArchive::openDirectory(const FS
|
|||
|
||||
if (fs::is_regular_file(p)) {
|
||||
printf("SaveData: OpenDirectory used with a file path");
|
||||
return Err(FSResult::UnexpectedFileOrDir);
|
||||
return Err(Result::FS::UnexpectedFileOrDir);
|
||||
}
|
||||
|
||||
if (fs::is_directory(p)) {
|
||||
return Ok(DirectorySession(this, p));
|
||||
} else {
|
||||
return Err(FSResult::FileNotFound);
|
||||
return Err(Result::FS::FileNotFoundAlt);
|
||||
}
|
||||
}
|
||||
|
||||
Helpers::panic("SaveDataArchive::OpenDirectory: Unimplemented path type");
|
||||
return Err(FSResult::Success);
|
||||
return Err(Result::Success);
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase::FormatInfo, FSResult> SaveDataArchive::getFormatInfo(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase::FormatInfo, HorizonResult> SaveDataArchive::getFormatInfo(const FSPath& path) {
|
||||
const fs::path formatInfoPath = getFormatInfoPath();
|
||||
IOFile file(formatInfoPath, "rb");
|
||||
|
||||
// If the file failed to open somehow, we return that the archive is not formatted
|
||||
if (!file.isOpen()) {
|
||||
return Err(FSResult::NotFormatted);
|
||||
return Err(Result::FS::NotFormatted);
|
||||
}
|
||||
|
||||
FormatInfo ret;
|
||||
auto [success, bytesRead] = file.readBytes(&ret, sizeof(FormatInfo));
|
||||
if (!success || bytesRead != sizeof(FormatInfo)) {
|
||||
Helpers::warn("SaveData::GetFormatInfo: Format file exists but was not properly read into the FormatInfo struct");
|
||||
return Err(FSResult::NotFormatted);
|
||||
return Err(Result::FS::NotFormatted);
|
||||
}
|
||||
|
||||
return Ok(ret);
|
||||
|
@ -168,7 +168,7 @@ void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo&
|
|||
const fs::path saveDataPath = IOFile::getAppData() / "SaveData";
|
||||
const fs::path formatInfoPath = getFormatInfoPath();
|
||||
|
||||
// Delete all contents by deleting the directory then recreating it
|
||||
// Delete all contents by deleting the directory then recreating it
|
||||
fs::remove_all(saveDataPath);
|
||||
fs::create_directories(saveDataPath);
|
||||
|
||||
|
@ -177,16 +177,16 @@ void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo&
|
|||
file.writeBytes(&info, sizeof(info));
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase*, HorizonResult> SaveDataArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Empty) {
|
||||
Helpers::panic("Unimplemented path type for SaveData archive: %d\n", path.type);
|
||||
return Err(FSResult::NotFoundInvalid);
|
||||
return Err(Result::FS::NotFoundInvalid);
|
||||
}
|
||||
|
||||
const fs::path formatInfoPath = getFormatInfoPath();
|
||||
// Format info not found so the archive is not formatted
|
||||
if (!fs::is_regular_file(formatInfoPath)) {
|
||||
return Err(FSResult::NotFormatted);
|
||||
return Err(Result::FS::NotFormatted);
|
||||
}
|
||||
|
||||
return Ok((ArchiveBase*)this);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "fs/archive_sdmc.hpp"
|
||||
#include <memory>
|
||||
|
||||
FSResult SDMCArchive::createFile(const FSPath& path, u64 size) {
|
||||
HorizonResult SDMCArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SDMC] CreateFile not yet supported");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FSResult SDMCArchive::deleteFile(const FSPath& path) {
|
||||
HorizonResult SDMCArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[SDMC] Unimplemented DeleteFile");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -16,9 +16,9 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms)
|
|||
return FileError;
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> SDMCArchive::openArchive(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase*, HorizonResult> SDMCArchive::openArchive(const FSPath& path) {
|
||||
printf("SDMCArchive::OpenArchive: Failed\n");
|
||||
return Err(FSResult::NotFormatted);
|
||||
return Err(Result::FS::NotFormatted);
|
||||
}
|
||||
|
||||
std::optional<u32> SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace PathType {
|
|||
};
|
||||
};
|
||||
|
||||
FSResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
HorizonResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SelfNCCH] CreateFile not yet supported");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FSResult SelfNCCHArchive::deleteFile(const FSPath& path) {
|
||||
HorizonResult SelfNCCHArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[SelfNCCH] Unimplemented DeleteFile");
|
||||
return FSResult::Success;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -40,10 +40,10 @@ FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& pe
|
|||
return NoFile; // No file descriptor needed for RomFS
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> SelfNCCHArchive::openArchive(const FSPath& path) {
|
||||
Rust::Result<ArchiveBase*, HorizonResult> SelfNCCHArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Empty) {
|
||||
Helpers::panic("Invalid path type for SelfNCCH archive: %d\n", path.type);
|
||||
return Err(FSResult::NotFoundInvalid);
|
||||
return Err(Result::FS::NotFoundInvalid);
|
||||
}
|
||||
|
||||
return Ok((ArchiveBase*)this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue