diff --git a/src/core/fs/archive_save_data.cpp b/src/core/fs/archive_save_data.cpp index 758c1312..572d22e0 100644 --- a/src/core/fs/archive_save_data.cpp +++ b/src/core/fs/archive_save_data.cpp @@ -5,7 +5,32 @@ namespace fs = std::filesystem; FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) { - Helpers::panic("[SaveData] CreateFile not yet supported"); + if (path.type == PathType::UTF16) { + if (!isPathSafe(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; } @@ -170,4 +195,4 @@ Rust::Result SaveDataArchive::openArchive(const FSPath& std::optional SaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) { Helpers::panic("Unimplemented SaveData::ReadFile"); return 0; -} \ No newline at end of file +}