[FS] Better GetFormatInfo

This commit is contained in:
wheremyfoodat 2023-05-20 15:39:31 +03:00
parent 01d16fdfd1
commit 4767a2053b
4 changed files with 34 additions and 11 deletions

View file

@ -120,8 +120,23 @@ Rust::Result<DirectorySession, FSResult> SaveDataArchive::openDirectory(const FS
return Err(FSResult::Success);
}
ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
Helpers::panic("Unimplemented SaveData::GetFormatInfo");
Rust::Result<ArchiveBase::FormatInfo, FSResult> SaveDataArchive::getFormatInfo(const FSPath& path) {
const fs::path formatInfoPath = getFormatInfoPath();
IOFile file(formatInfoPath, "rb");
// If the file failed to open somehow, we return that the archive is not formatted
if (!file.isOpen()) {
return Err(FSResult::NotFormatted);
}
FormatInfo ret;
auto [success, bytesRead] = file.readBytes(&ret, sizeof(FormatInfo));
if (!success || bytesRead != sizeof(FormatInfo)) {
Helpers::warn("SaveData::GetFormatInfo: Format file exists but was not properly read into the FormatInfo struct");
return Err(FSResult::NotFormatted);
}
return Ok(ret);
}
void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo& info) {