From e9ec8365040264e4493538dc5bbf5ac9fc81172c Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:41:31 +0300 Subject: [PATCH] Add SystemSaveData::CreateDirectory --- include/fs/archive_system_save_data.hpp | 2 +- src/core/fs/archive_system_save_data.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/fs/archive_system_save_data.hpp b/include/fs/archive_system_save_data.hpp index 9548e1903..c4526becd 100644 --- a/include/fs/archive_system_save_data.hpp +++ b/include/fs/archive_system_save_data.hpp @@ -12,7 +12,7 @@ class SystemSaveDataArchive : public ArchiveBase { std::string name() override { return "SystemSaveData"; } - //HorizonResult createDirectory(const FSPath& path) override; + HorizonResult createDirectory(const FSPath& path) override; HorizonResult createFile(const FSPath& path, u64 size) override; HorizonResult deleteFile(const FSPath& path) override; diff --git a/src/core/fs/archive_system_save_data.cpp b/src/core/fs/archive_system_save_data.cpp index f8e4ad4ec..eb572d908 100644 --- a/src/core/fs/archive_system_save_data.cpp +++ b/src/core/fs/archive_system_save_data.cpp @@ -84,6 +84,30 @@ HorizonResult SystemSaveDataArchive::createFile(const FSPath& path, u64 size) { return Result::Success; } +HorizonResult SystemSaveDataArchive::createDirectory(const FSPath& path) { + if (path.type == PathType::UTF16) { + if (!isPathSafe(path)) { + Helpers::panic("Unsafe path in SystemSaveData::OpenFile"); + } + + fs::path p = IOFile::getAppData() / ".." / "SharedFiles" / "SystemSaveData"; + p += fs::path(path.utf16_string).make_preferred(); + + if (fs::is_directory(p)) { + return Result::FS::AlreadyExists; + } + + if (fs::is_regular_file(p)) { + Helpers::panic("File path passed to SystemSaveData::CreateDirectory"); + } + + bool success = fs::create_directory(p); + return success ? Result::Success : Result::FS::UnexpectedFileOrDir; + } else { + Helpers::panic("Unimplemented SystemSaveData::CreateDirectory"); + } +} + HorizonResult SystemSaveDataArchive::deleteFile(const FSPath& path) { if (path.type == PathType::UTF16) {