[FS] Cleanup, stub SDMC, start implementing SaveData

This commit is contained in:
wheremyfoodat 2022-10-12 17:29:36 +03:00
parent 8cf55162d0
commit b6a1da21a9
13 changed files with 135 additions and 15 deletions

View file

@ -56,6 +56,16 @@ struct FileSession {
}
};
struct ArchiveSession {
ArchiveBase* archive = nullptr;
FSPath path;
bool isOpen;
ArchiveSession(ArchiveBase* archive, const FSPath& filePath, bool isOpen = true) : archive(archive), isOpen(isOpen) {
path = filePath;
}
};
class ArchiveBase {
protected:
using Result = u32;
@ -67,7 +77,7 @@ public:
virtual u64 getFreeBytes() = 0;
virtual bool openFile(const FSPath& path) = 0;
virtual ArchiveBase* openArchive(FSPath& path) = 0;
virtual ArchiveBase* openArchive(const FSPath& path) = 0;
// Read size bytes from a file starting at offset "offset" into a certain buffer in memory
// Returns the number of bytes read, or nullopt if the read failed

View file

@ -1,3 +1,4 @@
#pragma once
#include "archive_base.hpp"
class SelfNCCHArchive : public ArchiveBase {
@ -9,6 +10,6 @@ public:
const char* name() override { return "SelfNCCH"; }
bool openFile(const FSPath& path) override;
ArchiveBase* openArchive(FSPath& path) override;
ArchiveBase* openArchive(const FSPath& path) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
};

View file

@ -0,0 +1,15 @@
#pragma once
#include "archive_base.hpp"
class SaveDataArchive : public ArchiveBase {
public:
SaveDataArchive(Memory& mem) : ArchiveBase(mem) {}
u64 getFreeBytes() override { return 0; }
const char* name() override { return "SaveData"; }
bool openFile(const FSPath& path) override;
ArchiveBase* openArchive(const FSPath& path) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
};

View file

@ -0,0 +1,15 @@
#pragma once
#include "archive_base.hpp"
class SDMCArchive : public ArchiveBase {
public:
SDMCArchive(Memory& mem) : ArchiveBase(mem) {}
u64 getFreeBytes() override { return 0; }
const char* name() override { return "SDMC"; }
bool openFile(const FSPath& path) override;
ArchiveBase* openArchive(const FSPath& path) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
};