ExtSaveData work

This commit is contained in:
wheremyfoodat 2023-01-22 14:23:28 +02:00
parent 902b877c40
commit 995dfb81df
12 changed files with 68 additions and 28 deletions

View file

@ -3,18 +3,27 @@
namespace fs = std::filesystem;
bool ExtSaveDataArchive::openFile(const FSPath& path) {
FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path))
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
if (perms.create())
Helpers::panic("[ExtSaveData] CAn't open file with create flag");
fs::path p = IOFile::getAppData() / "NAND";
p += fs::path(path.utf16_string).make_preferred();
return false;
if (fs::exists(p)) { // Return file descriptor if the file exists
IOFile file(p.string().c_str(), "r+b"); // According to Citra, this ignores the OpenFile flags and always opens as r+b? TODO: Check
return file.isOpen() ? file.getHandle() : FileError;
} else {
return FileError;
}
}
Helpers::panic("ExtSaveDataArchive::OpenFile: Failed");
return false;
return FileError;
}
ArchiveBase* ExtSaveDataArchive::openArchive(const FSPath& path) {
@ -22,6 +31,8 @@ ArchiveBase* ExtSaveDataArchive::openArchive(const FSPath& path) {
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
}
if (path.binary[0] != 0) Helpers::panic("ExtSaveData: Tried to access something other than NAND");
return this;
}

View file

@ -1,15 +1,15 @@
#include "fs/archive_ncch.hpp"
#include <memory>
bool SelfNCCHArchive::openFile(const FSPath& path) {
FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& perms) {
if (!hasRomFS()) {
printf("Tried to open a SelfNCCH file without a RomFS\n");
return false;
return FileError;
}
if (path.type != PathType::Binary || path.binary.size() != 12) {
printf("Invalid SelfNCCH path type\n");
return false;
return FileError;
}
// Where to read the file from. (https://www.3dbrew.org/wiki/Filesystem_services#SelfNCCH_File_Path_Data_Format)
@ -19,7 +19,7 @@ bool SelfNCCHArchive::openFile(const FSPath& path) {
Helpers::panic("Read from NCCH's non-RomFS section!");
}
return true;
return NoFile; // No file descriptor needed for RomFS
}
ArchiveBase* SelfNCCHArchive::openArchive(const FSPath& path) {

View file

@ -2,23 +2,23 @@
#include <algorithm>
#include <memory>
bool SaveDataArchive::openFile(const FSPath& path) {
FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) {
if (!cartHasSaveData()) {
printf("Tried to read SaveData FS without save data\n");
return false;
return FileError;
}
if (path.type == PathType::UTF16 /* && path.utf16_string == u"/game_header" */) {
printf("Opened file from the SaveData archive \n");
return true;
return NoFile;
}
if (path.type != PathType::Binary) {
printf("Unimplemented SaveData path type: %d\n", path.type);
return false;
return FileError;
}
return true;
return NoFile;
}
ArchiveBase* SaveDataArchive::openArchive(const FSPath& path) {

View file

@ -1,9 +1,9 @@
#include "fs/archive_sdmc.hpp"
#include <memory>
bool SDMCArchive::openFile(const FSPath& path) {
FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) {
printf("SDMCArchive::OpenFile: Failed");
return false;
return FileError;
}
ArchiveBase* SDMCArchive::openArchive(const FSPath& path) {