[FS] Formatting archives v1

This commit is contained in:
wheremyfoodat 2023-05-16 23:37:52 +03:00
parent 2f5bb45d58
commit 4dc04be350
6 changed files with 67 additions and 4 deletions

View file

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