Initial UserSaveData impl

This commit is contained in:
wheremyfoodat 2023-08-24 17:58:16 +03:00
parent bd169f9274
commit 46ce2c14cd
6 changed files with 256 additions and 16 deletions

View file

@ -25,17 +25,22 @@ namespace PathType {
}
namespace ArchiveID {
enum : u32 {
SelfNCCH = 3,
SaveData = 4,
ExtSaveData = 6,
SharedExtSaveData = 7,
SystemSaveData = 8,
SDMC = 9,
SDMCWriteOnly = 0xA,
enum : u32 {
SelfNCCH = 3,
SaveData = 4,
ExtSaveData = 6,
SharedExtSaveData = 7,
SystemSaveData = 8,
SDMC = 9,
SDMCWriteOnly = 0xA,
SavedataAndNcch = 0x2345678A
};
SavedataAndNcch = 0x2345678A,
// 3DBrew: This is the same as the regular SaveData archive, except with this the savedata ID and mediatype is loaded from the input archive
// lowpath.
UserSaveData1 = 0x567890B2,
// 3DBrew: Similar to 0x567890B2 but can only access Accessible Save specified in exheader?
UserSaveData2 = 0x567890B4,
};
static std::string toString(u32 id) {
switch (id) {

View file

@ -0,0 +1,31 @@
#pragma once
#include "archive_base.hpp"
class UserSaveDataArchive : public ArchiveBase {
u32 archiveID;
public:
UserSaveDataArchive(Memory& mem, u32 archiveID) : ArchiveBase(mem), archiveID(archiveID) {}
u64 getFreeBytes() override { return 32_MB; }
std::string name() override { return "UserSaveData"; }
HorizonResult createDirectory(const FSPath& path) override;
HorizonResult createFile(const FSPath& path, u64 size) override;
HorizonResult deleteFile(const FSPath& path) override;
Rust::Result<ArchiveBase*, HorizonResult> openArchive(const FSPath& path) override;
Rust::Result<DirectorySession, HorizonResult> openDirectory(const FSPath& path) override;
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
void format(const FSPath& path, const FormatInfo& info) override;
Rust::Result<FormatInfo, HorizonResult> getFormatInfo(const FSPath& path) override;
std::filesystem::path getFormatInfoPath() { return IOFile::getAppData() / "FormatInfo" / "SaveData.format"; }
// Returns whether the cart has save data or not
bool cartHasSaveData() {
auto cxi = mem.getCXI();
return (cxi != nullptr && cxi->hasSaveData()); // We need to have a CXI file with more than 0 bytes of save data
}
};

View file

@ -4,6 +4,7 @@
#include "fs/archive_save_data.hpp"
#include "fs/archive_sdmc.hpp"
#include "fs/archive_self_ncch.hpp"
#include "fs/archive_user_save_data.hpp"
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
@ -26,6 +27,10 @@ class FSService {
SDMCArchive sdmc;
NCCHArchive ncch;
// UserSaveData archives
UserSaveDataArchive userSaveData1;
UserSaveDataArchive userSaveData2;
ExtSaveDataArchive extSaveData_sdmc;
ExtSaveDataArchive sharedExtSaveData_nand;
@ -62,10 +67,9 @@ class FSService {
u32 priority;
public:
FSService(Memory& mem, Kernel& kernel) : mem(mem), saveData(mem),
sharedExtSaveData_nand(mem, "../SharedFiles/NAND", true), extSaveData_sdmc(mem, "SDMC"),
sdmc(mem), selfNcch(mem), ncch(mem), kernel(kernel)
{}
FSService(Memory& mem, Kernel& kernel)
: mem(mem), saveData(mem), sharedExtSaveData_nand(mem, "../SharedFiles/NAND", true), extSaveData_sdmc(mem, "SDMC"), sdmc(mem), selfNcch(mem),
ncch(mem), userSaveData1(mem, ArchiveID::UserSaveData1), userSaveData2(mem, ArchiveID::UserSaveData2), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);