mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-11 00:25:41 +12:00
Merge pull request #20 from Wunkolo/savedata-create
Implement `SaveDataArchive::createFile`
This commit is contained in:
commit
f2b67a2757
1 changed files with 27 additions and 2 deletions
|
@ -5,7 +5,32 @@
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||||
Helpers::panic("[SaveData] CreateFile not yet supported");
|
if (path.type == PathType::UTF16) {
|
||||||
|
if (!isPathSafe<PathType::UTF16>(path))
|
||||||
|
Helpers::panic("Unsafe path in SaveData::CreateFile");
|
||||||
|
|
||||||
|
fs::path p = IOFile::getAppData() / "SaveData";
|
||||||
|
p += fs::path(path.utf16_string).make_preferred();
|
||||||
|
|
||||||
|
if (fs::exists(p))
|
||||||
|
return FSResult::AlreadyExists;
|
||||||
|
|
||||||
|
IOFile file(p.string().c_str(), "wb");
|
||||||
|
|
||||||
|
// If the size is 0, leave the file empty and return success
|
||||||
|
if (size == 0) {
|
||||||
|
return FSResult::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it is not empty, seek to size - 1 and write a 0 to create a file of size "size"
|
||||||
|
else if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) {
|
||||||
|
return FSResult::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FSResult::FileTooLarge;
|
||||||
|
}
|
||||||
|
|
||||||
|
Helpers::panic("SaveDataArchive::OpenFile: Failed");
|
||||||
return FSResult::Success;
|
return FSResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,4 +195,4 @@ Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath&
|
||||||
std::optional<u32> SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
std::optional<u32> SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||||
Helpers::panic("Unimplemented SaveData::ReadFile");
|
Helpers::panic("Unimplemented SaveData::ReadFile");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue