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

@ -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
}
};