mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-19 20:19:13 +12:00
[FS] Formatting archives v1
This commit is contained in:
parent
2f5bb45d58
commit
4dc04be350
6 changed files with 67 additions and 4 deletions
|
@ -70,11 +70,28 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
|
|||
return FileError;
|
||||
}
|
||||
|
||||
std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) {
|
||||
// TODO: Remove punning here
|
||||
const u32 mediaType = *(u32*)&path.binary[0];
|
||||
const u32 saveLow = *(u32*)&path.binary[4];
|
||||
const u32 saveHigh = *(u32*)&path.binary[8];
|
||||
|
||||
// TODO: Should the media type be used here
|
||||
return backingFolder + std::to_string(saveLow) + std::to_string(saveHigh);
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> ExtSaveDataArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Binary || path.binary.size() != 12) {
|
||||
Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
|
||||
}
|
||||
|
||||
// Create a format info path in the style of AppData/FormatInfo/Cartridge10390390194.format
|
||||
fs::path formatInfopath = IOFile::getAppData() / "FormatInfo" / (getExtSaveDataPathFromBinary(path) + ".format");
|
||||
// Format info not found so the archive is not formatted
|
||||
if (!fs::is_regular_file(formatInfopath)) {
|
||||
return isShared ? Err(FSResult::NotFormatted) : Err(FSResult::NotFoundInvalid);
|
||||
}
|
||||
|
||||
return Ok((ArchiveBase*)this);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,8 +94,20 @@ Rust::Result<DirectorySession, FSResult> SaveDataArchive::openDirectory(const FS
|
|||
}
|
||||
|
||||
ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
|
||||
//Helpers::panic("Unimplemented SaveData::GetFormatInfo");
|
||||
return FormatInfo{ .size = 0, .numOfDirectories = 255, .numOfFiles = 255, .duplicateData = false };
|
||||
Helpers::panic("Unimplemented SaveData::GetFormatInfo");
|
||||
}
|
||||
|
||||
void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo& info) {
|
||||
const fs::path saveDataPath = IOFile::getAppData() / "SaveData";
|
||||
const fs::path formatInfoPath = getFormatInfoPath();
|
||||
|
||||
// Delete all contents by deleting the directory then recreating it
|
||||
fs::remove_all(saveDataPath);
|
||||
fs::create_directories(saveDataPath);
|
||||
|
||||
// Write format info on disk
|
||||
IOFile file(formatInfoPath, "wb");
|
||||
file.writeBytes(&info, sizeof(info));
|
||||
}
|
||||
|
||||
Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath& path) {
|
||||
|
@ -104,6 +116,12 @@ Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath&
|
|||
return Err(FSResult::NotFoundInvalid);
|
||||
}
|
||||
|
||||
const fs::path formatInfoPath = getFormatInfoPath();
|
||||
// Format info not found so the archive is not formatted
|
||||
if (!fs::is_regular_file(formatInfoPath)) {
|
||||
return Err(FSResult::NotFormatted);
|
||||
}
|
||||
|
||||
return Ok((ArchiveBase*)this);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ void FSService::initializeFilesystem() {
|
|||
const auto nandPath = IOFile::getAppData() / "NAND"; // Create NAND
|
||||
const auto cartPath = IOFile::getAppData() / "CartSave"; // Create cartridge save folder for use with ExtSaveData
|
||||
const auto savePath = IOFile::getAppData() / "SaveData"; // Create SaveData
|
||||
const auto formatPath = IOFile::getAppData() / "FormatInfo"; // Create folder for storing archive formatting info
|
||||
namespace fs = std::filesystem;
|
||||
// TODO: SDMC, etc
|
||||
|
||||
|
@ -62,6 +63,10 @@ void FSService::initializeFilesystem() {
|
|||
if (!fs::is_directory(savePath)) {
|
||||
fs::create_directories(savePath);
|
||||
}
|
||||
|
||||
if (!fs::is_directory(formatPath)) {
|
||||
fs::create_directories(formatPath);
|
||||
}
|
||||
}
|
||||
|
||||
ArchiveBase* FSService::getArchiveFromID(u32 id, const FSPath& archivePath) {
|
||||
|
@ -440,9 +445,18 @@ void FSService::formatSaveData(u32 messagePointer) {
|
|||
const u32 fileNum = mem.read32(messagePointer + 24); // Max number of files
|
||||
const u32 directoryBucketNum = mem.read32(messagePointer + 28); // Not sure what a directory bucket is...?
|
||||
const u32 fileBucketNum = mem.read32(messagePointer + 32); // Same here
|
||||
const bool duplicateData = mem.read8(messagePointer + 36) != 0;
|
||||
const bool duplicateData = mem.read8(messagePointer + 36) != 0;
|
||||
|
||||
ArchiveBase::FormatInfo info {
|
||||
.size = blockSize * 0x200,
|
||||
.numOfDirectories = directoryNum,
|
||||
.numOfFiles = fileNum,
|
||||
.duplicateData = duplicateData
|
||||
};
|
||||
|
||||
printf("Stubbed FS::FormatSaveData. File num: %d, directory num: %d\n", fileNum, directoryNum);
|
||||
saveData.format(path, info);
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x84C, 1, 0));
|
||||
mem.write32(messagePointer + 4, ResultCode::Success);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue