mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
[FS] Better GetFormatInfo
This commit is contained in:
parent
01d16fdfd1
commit
4767a2053b
4 changed files with 34 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -419,13 +419,20 @@ void FSService::getFormatInfo(u32 messagePointer) {
|
|||
Helpers::panic("OpenArchive: Tried to open unknown archive %d.", archiveID);
|
||||
}
|
||||
|
||||
ArchiveBase::FormatInfo info = archive->getFormatInfo(path);
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x845, 5, 0));
|
||||
mem.write32(messagePointer + 4, ResultCode::Success);
|
||||
mem.write32(messagePointer + 8, info.size);
|
||||
mem.write32(messagePointer + 12, info.numOfDirectories);
|
||||
mem.write32(messagePointer + 16, info.numOfFiles);
|
||||
mem.write8(messagePointer + 20, info.duplicateData ? 1 : 0);
|
||||
Rust::Result<ArchiveBase::FormatInfo, FSResult> res = archive->getFormatInfo(path);
|
||||
|
||||
// If the FormatInfo was returned, write them to the output buffer. Otherwise, write an error code.
|
||||
if (res.isOk()) {
|
||||
ArchiveBase::FormatInfo info = res.unwrap();
|
||||
mem.write32(messagePointer + 4, ResultCode::Success);
|
||||
mem.write32(messagePointer + 8, info.size);
|
||||
mem.write32(messagePointer + 12, info.numOfDirectories);
|
||||
mem.write32(messagePointer + 16, info.numOfFiles);
|
||||
mem.write8(messagePointer + 20, info.duplicateData ? 1 : 0);
|
||||
} else {
|
||||
mem.write32(messagePointer + 4, static_cast<u32>(res.unwrapErr()));
|
||||
}
|
||||
}
|
||||
|
||||
void FSService::formatSaveData(u32 messagePointer) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue