From 207179669602bb0ec0d624f59abea08867be280c Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Mon, 29 Jun 2020 18:30:27 +0100 Subject: [PATCH] Implement basic filesystem support in VFS This mirrors Horizon's IFileSystem, it will be used by the nsp and nca loaders to read their content. https://switchbrew.org/wiki/Filesystem_services#IFileSystem --- app/src/main/cpp/skyline/vfs/filesystem.h | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/src/main/cpp/skyline/vfs/filesystem.h diff --git a/app/src/main/cpp/skyline/vfs/filesystem.h b/app/src/main/cpp/skyline/vfs/filesystem.h new file mode 100644 index 00000000..b7240d5d --- /dev/null +++ b/app/src/main/cpp/skyline/vfs/filesystem.h @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include "backing.h" +#include "directory.h" + +namespace skyline::vfs { + /** + * @brief The FileSystem class represents an abstract filesystem with child files and folders + */ + class FileSystem { + public: + FileSystem() = default; + + /* Delete the move constructor to prevent multiple instances of the same filesystem */ + FileSystem(const FileSystem &) = delete; + + FileSystem &operator=(const FileSystem &) = delete; + + virtual ~FileSystem() = default; + + /** + * @brief Opens a file from the specified path in the filesystem + * @param path The path to the file + * @param mode The mode to open the file with + * @return A shared pointer to a Backing object of the file + */ + virtual std::shared_ptr OpenFile(std::string path, Backing::Mode mode = {true, false, false}) = 0; + + /** + * @brief Checks if a given file exists in a filesystem + * @param path The path to the file + * @return A boolean containing whether the file exists + */ + virtual bool FileExists(std::string path) = 0; + + /** + * @brief Opens a directory from the specified path in the filesystem + * @param path The path to the directory + * @param listMode The list mode for the directory + * @return A shared pointer to a Directory object of the directory + */ + virtual std::shared_ptr OpenDirectory(std::string path, Directory::ListMode listMode) = 0; + }; +}