mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-09 15:45:40 +12:00
format
This commit is contained in:
parent
6e48c7fbdd
commit
47a01a8296
3 changed files with 35 additions and 44 deletions
|
@ -61,7 +61,7 @@ namespace MediaType {
|
|||
enum : u8 {
|
||||
NAND = 0,
|
||||
SD = 1,
|
||||
Gamecard = 2
|
||||
Gamecard = 2,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -230,26 +230,26 @@ public:
|
|||
virtual HorizonResult createFile(const FSPath& path, u64 size) = 0;
|
||||
virtual HorizonResult deleteFile(const FSPath& path) = 0;
|
||||
|
||||
virtual Rust::Result<FormatInfo, HorizonResult> getFormatInfo(const FSPath& path) {
|
||||
Helpers::panic("Unimplemented GetFormatInfo for %s archive", name().c_str());
|
||||
// Return a dummy struct just to avoid the UB of not returning anything, even if we panic
|
||||
return Ok(FormatInfo{ .size = 0, .numOfDirectories = 0, .numOfFiles = 0, .duplicateData = false });
|
||||
}
|
||||
virtual Rust::Result<FormatInfo, HorizonResult> getFormatInfo(const FSPath& path) {
|
||||
Helpers::panic("Unimplemented GetFormatInfo for %s archive", name().c_str());
|
||||
// Return a dummy struct just to avoid the UB of not returning anything, even if we panic
|
||||
return Ok(FormatInfo{.size = 0, .numOfDirectories = 0, .numOfFiles = 0, .duplicateData = false});
|
||||
}
|
||||
|
||||
virtual HorizonResult createDirectory(const FSPath& path) {
|
||||
Helpers::panic("Unimplemented CreateDirectory for %s archive", name().c_str());
|
||||
return Result::FS::AlreadyExists;
|
||||
}
|
||||
Helpers::panic("Unimplemented CreateDirectory for %s archive", name().c_str());
|
||||
return Result::FS::AlreadyExists;
|
||||
}
|
||||
|
||||
virtual HorizonResult deleteDirectory(const FSPath& path) {
|
||||
Helpers::warn("Stubbed DeleteDirectory for %s archive", name().c_str());
|
||||
return Result::Success;
|
||||
}
|
||||
Helpers::warn("Stubbed DeleteDirectory for %s archive", name().c_str());
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
virtual HorizonResult deleteDirectoryRecursively(const FSPath& path) {
|
||||
Helpers::warn("Stubbed DeleteDirectoryRecursively for %s archive", name().c_str());
|
||||
return Result::Success;
|
||||
}
|
||||
Helpers::warn("Stubbed DeleteDirectoryRecursively for %s archive", name().c_str());
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
// Returns nullopt if opening the file failed, otherwise returns a file descriptor to it (nullptr if none is needed)
|
||||
virtual FileDescriptor openFile(const FSPath& path, const FilePerms& perms) = 0;
|
||||
|
|
|
@ -208,7 +208,7 @@ void ExtSaveDataArchive::format(const FSPath& path, const FormatInfo& info) {
|
|||
fs::remove_all(saveDataPath);
|
||||
fs::create_directories(saveDataPath);
|
||||
|
||||
if(!isShared) {
|
||||
if (!isShared) {
|
||||
fs::create_directories(saveDataPath / "user");
|
||||
fs::create_directories(saveDataPath / "boss");
|
||||
// todo: save icon.
|
||||
|
@ -246,12 +246,13 @@ Rust::Result<std::vector<u8>, HorizonResult> ExtSaveDataArchive::loadIcon() cons
|
|||
const fs::path iconPath = IOFile::getAppData() / backingFolder / "icon";
|
||||
IOFile file(iconPath, "rb");
|
||||
const s32 size = static_cast<s32>(file.size().value_or(-1));
|
||||
if(size < 0) {
|
||||
if (size < 0) {
|
||||
return Err(Result::FS::NotFoundInvalid);
|
||||
}
|
||||
std::unique_ptr<u8[]> data(new u8[size]);
|
||||
file.readBytes(data.get(), size);
|
||||
return Ok(std::vector(data.get(), data.get() + size));
|
||||
|
||||
std::vector<u8> icon(size);
|
||||
file.readBytes(icon.data(), size);
|
||||
return Ok(icon);
|
||||
}
|
||||
|
||||
std::filesystem::path ExtSaveDataArchive::getFormatInfoPath(const FSPath& path) const {
|
||||
|
@ -260,7 +261,7 @@ std::filesystem::path ExtSaveDataArchive::getFormatInfoPath(const FSPath& path)
|
|||
|
||||
std::filesystem::path ExtSaveDataArchive::getUserDataPath() const {
|
||||
fs::path p = IOFile::getAppData() / backingFolder;
|
||||
if(!isShared) { // todo: "boss"?
|
||||
if (!isShared) { // todo: "boss"?
|
||||
p /= "user";
|
||||
}
|
||||
return p;
|
||||
|
@ -289,7 +290,7 @@ Rust::Result<ArchiveBase::FormatInfo, HorizonResult> ExtSaveDataArchive::getForm
|
|||
}
|
||||
|
||||
std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) const {
|
||||
if(path.type != PathType::Binary) {
|
||||
if (path.type != PathType::Binary) {
|
||||
Helpers::panic("GetExtSaveDataPathFromBinary called without a Binary FSPath!");
|
||||
}
|
||||
|
||||
|
|
|
@ -165,8 +165,9 @@ FSPath FSService::readPath(u32 type, u32 pointer, u32 size) {
|
|||
}
|
||||
|
||||
void FSService::writePointer(const u8* data, u32 pointer, u32 size) {
|
||||
for (u32 i = 0; i < size; i++)
|
||||
for (u32 i = 0; i < size; i++) {
|
||||
mem.write8(pointer + i, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void FSService::handleSyncRequest(u32 messagePointer) {
|
||||
|
@ -535,16 +536,10 @@ void FSService::deleteExtSaveData(u32 messagePointer) {
|
|||
/*
|
||||
FSPath path = readPath(PathType::Binary, messagePointer + 4, 8);
|
||||
|
||||
switch(mediaType) {
|
||||
case MediaType::NAND:
|
||||
sharedExtSaveData_nand.clear(path);
|
||||
break;
|
||||
case MediaType::SD:
|
||||
extSaveData_sdmc.clear(path);
|
||||
break;
|
||||
default:
|
||||
Helpers::warn("FS::DeleteExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast<s32>(mediaType));
|
||||
break;
|
||||
switch (mediaType) {
|
||||
case MediaType::NAND: sharedExtSaveData_nand.clear(path); break;
|
||||
case MediaType::SD: extSaveData_sdmc.clear(path); break;
|
||||
default: Helpers::warn("FS::DeleteExtSaveData: Unhandled ExtSaveData MediaType %d", static_cast<s32>(mediaType)); break;
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -575,20 +570,15 @@ void FSService::createExtSaveData(u32 messagePointer) {
|
|||
|
||||
ExtSaveDataArchive* selected = nullptr;
|
||||
switch(mediaType) {
|
||||
case MediaType::NAND:
|
||||
selected = &sharedExtSaveData_nand;
|
||||
break;
|
||||
case MediaType::SD:
|
||||
selected = &extSaveData_sdmc;
|
||||
break;
|
||||
default:
|
||||
Helpers::warn("FS::CreateExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast<s32>(mediaType));
|
||||
break;
|
||||
case MediaType::NAND: selected = &sharedExtSaveData_nand; break;
|
||||
case MediaType::SD: selected = &extSaveData_sdmc; break;
|
||||
default: Helpers::warn("FS::CreateExtSaveData - Unhandled ExtSaveData MediaType %d", static_cast<s32>(mediaType)); break;
|
||||
}
|
||||
|
||||
if (selected != nullptr) {
|
||||
selected->format(path, info);
|
||||
if(smdhSize > 0) {
|
||||
|
||||
if (smdhSize > 0) {
|
||||
const FSPath smdh = readPath(PathType::Binary, smdhPointer, smdhSize);
|
||||
selected->saveIcon(smdh.binary);
|
||||
}
|
||||
|
@ -621,7 +611,7 @@ void FSService::readExtSaveDataIcon(u32 messagePointer) {
|
|||
mem.write32(messagePointer, IPC::responseHeader(0x0851, 1, 0));
|
||||
|
||||
Rust::Result<std::vector<u8>, HorizonResult> data = selected == nullptr ? Err(Result::FS::NotFoundInvalid) : selected->loadIcon();
|
||||
if(data.isErr()) {
|
||||
if (data.isErr()) {
|
||||
mem.write32(messagePointer + 4, data.unwrapErr());;
|
||||
mem.write32(messagePointer + 8, 0);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue