mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
[FS] Integrate Result<T, E> to codebase
This commit is contained in:
parent
38eb4d8088
commit
4f2d59ccbe
15 changed files with 122 additions and 114 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
CreateFileResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
FSResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
if (size == 0)
|
||||
Helpers::panic("ExtSaveData file does not support size == 0");
|
||||
|
||||
|
@ -15,22 +15,22 @@ CreateFileResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) {
|
|||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::exists(p))
|
||||
return CreateFileResult::AlreadyExists;
|
||||
return FSResult::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 CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
return CreateFileResult::FileTooLarge;
|
||||
return FSResult::FileTooLarge;
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::OpenFile: Failed");
|
||||
return CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
DeleteFileResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
||||
FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in ExtSaveData::DeleteFile");
|
||||
|
@ -40,11 +40,11 @@ DeleteFileResult ExtSaveDataArchive::deleteFile(const FSPath& path) {
|
|||
|
||||
std::error_code ec;
|
||||
bool success = fs::remove(p, ec);
|
||||
return success ? DeleteFileResult::Success : DeleteFileResult::FileNotFound;
|
||||
return success ? FSResult::Success : FSResult::FileNotFound;
|
||||
}
|
||||
|
||||
Helpers::panic("ExtSaveDataArchive::DeleteFile: Failed");
|
||||
return DeleteFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
|
|
@ -21,14 +21,14 @@ namespace MediaType {
|
|||
};
|
||||
};
|
||||
|
||||
CreateFileResult NCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
FSResult NCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[NCCH] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
DeleteFileResult NCCHArchive::deleteFile(const FSPath& path) {
|
||||
FSResult NCCHArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[NCCH] Unimplemented DeleteFile");
|
||||
return DeleteFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
CreateFileResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SaveData] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
DeleteFileResult SaveDataArchive::deleteFile(const FSPath& path) {
|
||||
FSResult SaveDataArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[SaveData] Unimplemented DeleteFile");
|
||||
return DeleteFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
@ -53,10 +53,10 @@ FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& pe
|
|||
return FileError;
|
||||
}
|
||||
|
||||
std::optional<DirectorySession> SaveDataArchive::openDirectory(const FSPath& path) {
|
||||
Rust::Result<DirectorySession, FSResult> SaveDataArchive::openDirectory(const FSPath& path) {
|
||||
if (!cartHasSaveData()) {
|
||||
printf("Tried to open SaveData directory without save data\n");
|
||||
return std::nullopt;
|
||||
return Err(FSResult::Success);
|
||||
}
|
||||
|
||||
if (path.type == PathType::UTF16) {
|
||||
|
@ -66,15 +66,18 @@ std::optional<DirectorySession> SaveDataArchive::openDirectory(const FSPath& pat
|
|||
fs::path p = IOFile::getAppData() / "SaveData";
|
||||
p += fs::path(path.utf16_string).make_preferred();
|
||||
|
||||
if (fs::is_regular_file(p))
|
||||
Helpers::panic("OpenDirectory: Tried to open directory but it's actually a file");
|
||||
|
||||
if (fs::is_directory(p)) {
|
||||
return DirectorySession(this, p);
|
||||
return Ok(DirectorySession(this, p));
|
||||
} else {
|
||||
Helpers::panic("Directory not found in SaveData::OpenDirectory");
|
||||
return Err(FSResult::FileNotFound);
|
||||
}
|
||||
}
|
||||
|
||||
Helpers::panic("SaveDataArchive::OpenDirectory: Unimplemented path type");
|
||||
return std::nullopt;
|
||||
return Err(FSResult::Success);
|
||||
}
|
||||
|
||||
ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "fs/archive_sdmc.hpp"
|
||||
#include <memory>
|
||||
|
||||
CreateFileResult SDMCArchive::createFile(const FSPath& path, u64 size) {
|
||||
FSResult SDMCArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SDMC] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
DeleteFileResult SDMCArchive::deleteFile(const FSPath& path) {
|
||||
FSResult SDMCArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[SDMC] Unimplemented DeleteFile");
|
||||
return DeleteFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace PathType {
|
|||
};
|
||||
};
|
||||
|
||||
CreateFileResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
FSResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) {
|
||||
Helpers::panic("[SelfNCCH] CreateFile not yet supported");
|
||||
return CreateFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
DeleteFileResult SelfNCCHArchive::deleteFile(const FSPath& path) {
|
||||
FSResult SelfNCCHArchive::deleteFile(const FSPath& path) {
|
||||
Helpers::panic("[SelfNCCH] Unimplemented DeleteFile");
|
||||
return DeleteFileResult::Success;
|
||||
return FSResult::Success;
|
||||
}
|
||||
|
||||
FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue