mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 14:45:41 +12:00
[SaveData] Handle size == 0 in CreateFile
This commit is contained in:
parent
8a852d2cab
commit
5fa4e9e178
1 changed files with 10 additions and 7 deletions
|
@ -5,9 +5,6 @@
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
||||
if (size == 0)
|
||||
Helpers::panic("SaveData file does not support size == 0");
|
||||
|
||||
if (path.type == PathType::UTF16) {
|
||||
if (!isPathSafe<PathType::UTF16>(path))
|
||||
Helpers::panic("Unsafe path in SaveData::CreateFile");
|
||||
|
@ -17,10 +14,16 @@ FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) {
|
|||
|
||||
if (fs::exists(p))
|
||||
return FSResult::AlreadyExists;
|
||||
|
||||
// Create a file of size "size" by creating an empty one, seeking to size - 1 and just writing a 0 there
|
||||
|
||||
IOFile file(p.string().c_str(), "wb");
|
||||
if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -192,4 +195,4 @@ Rust::Result<ArchiveBase*, FSResult> SaveDataArchive::openArchive(const FSPath&
|
|||
std::optional<u32> SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||
Helpers::panic("Unimplemented SaveData::ReadFile");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue