From 69ee3cfc667830924b838dae5aa1f11f12d9a7f1 Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 29 Nov 2022 10:16:45 +0300 Subject: [PATCH] Stub DeleteDirectory Should allow deleting/rewriting saves in some games --- app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp | 7 +++++++ app/src/main/cpp/skyline/services/fssrv/IFileSystem.h | 6 ++++++ app/src/main/cpp/skyline/vfs/filesystem.h | 8 ++++++++ app/src/main/cpp/skyline/vfs/os_filesystem.cpp | 5 +++++ app/src/main/cpp/skyline/vfs/os_filesystem.h | 2 ++ 5 files changed, 28 insertions(+) diff --git a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp index a91509ea..3785bff9 100644 --- a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp +++ b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp @@ -60,6 +60,13 @@ namespace skyline::service::fssrv { return {}; } + Result IFileSystem::DeleteDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + std::string path(request.inputBuf.at(0).as_string(true)); + + backing->DeleteDirectory(path); + return {}; + } + Result IFileSystem::OpenDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { std::string path(request.inputBuf.at(0).as_string(true)); diff --git a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.h b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.h index 61805b4c..a9c4a536 100644 --- a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.h +++ b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.h @@ -33,6 +33,11 @@ namespace skyline::service::fssrv { */ Result CreateDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** + * @brief Deletes a directory at the specified path in the filesystem + */ + Result DeleteDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** * @brief Queries the DirectoryEntryType of the given path * @url https://switchbrew.org/wiki/Filesystem_services#GetEntryType @@ -60,6 +65,7 @@ namespace skyline::service::fssrv { SFUNC(0x0, IFileSystem, CreateFile), SFUNC(0x1, IFileSystem, DeleteFile), SFUNC(0x2, IFileSystem, CreateDirectory), + SFUNC(0x3, IFileSystem, DeleteDirectory), SFUNC(0x7, IFileSystem, GetEntryType), SFUNC(0x8, IFileSystem, OpenFile), SFUNC(0x9, IFileSystem, OpenDirectory), diff --git a/app/src/main/cpp/skyline/vfs/filesystem.h b/app/src/main/cpp/skyline/vfs/filesystem.h index 1418c8fe..919b6084 100644 --- a/app/src/main/cpp/skyline/vfs/filesystem.h +++ b/app/src/main/cpp/skyline/vfs/filesystem.h @@ -20,6 +20,10 @@ namespace skyline::vfs { throw exception("This filesystem does not support deleting files"); } + virtual void DeleteDirectoryImpl(const std::string &path) { + throw exception("This filesystem does not support deleting directories"); + } + virtual bool CreateDirectoryImpl(const std::string &path, bool parents) { throw exception("This filesystem does not support creating directories"); }; @@ -56,6 +60,10 @@ namespace skyline::vfs { DeleteFileImpl(path); } + void DeleteDirectory(const std::string &path) { + DeleteDirectoryImpl(path); + } + /** * @brief Creates a directory in the filesystem * @param path The path to where the directory should be created diff --git a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp index 0ce10d91..01d7c2bb 100644 --- a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp +++ b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp @@ -43,6 +43,11 @@ namespace skyline::vfs { remove(fullPath.c_str()); } + void OsFileSystem::DeleteDirectoryImpl(const std::string &path) { + auto fullPath{basePath + path}; + std::filesystem::remove_all(fullPath.c_str()); + } + bool OsFileSystem::CreateDirectoryImpl(const std::string &path, bool parents) { auto fullPath{basePath + path + "/"}; diff --git a/app/src/main/cpp/skyline/vfs/os_filesystem.h b/app/src/main/cpp/skyline/vfs/os_filesystem.h index 7e9df31e..ad032a17 100644 --- a/app/src/main/cpp/skyline/vfs/os_filesystem.h +++ b/app/src/main/cpp/skyline/vfs/os_filesystem.h @@ -18,6 +18,8 @@ namespace skyline::vfs { void DeleteFileImpl(const std::string &path) override; + void DeleteDirectoryImpl(const std::string &path) override; + bool CreateDirectoryImpl(const std::string &path, bool parents) override; std::shared_ptr OpenFileImpl(const std::string &path, Backing::Mode mode) override;