From e2bd50a1fdbcbe60c10ec3156fb8decdce7161b2 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Mon, 29 Jun 2020 18:28:01 +0100 Subject: [PATCH] Implement a simple directory system in VFS This mirrors Horizon's IDirectory: https://switchbrew.org/wiki/Filesystem_services#IDirectory --- app/src/main/cpp/skyline/vfs/directory.h | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/src/main/cpp/skyline/vfs/directory.h diff --git a/app/src/main/cpp/skyline/vfs/directory.h b/app/src/main/cpp/skyline/vfs/directory.h new file mode 100644 index 00000000..48943e75 --- /dev/null +++ b/app/src/main/cpp/skyline/vfs/directory.h @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include + +namespace skyline::vfs { + /** + * @brief The Directory class represents an abstract directory in a filesystem + */ + class Directory { + public: + /** + * @brief This enumerates the types of entry a directory can contain + */ + enum class EntryType : u32 { + Directory = 0x0, //!< The entry is a directory + File = 0x1, //!< The entry is a file + }; + + /** + * @brief This hold information about a single directory entry + */ + struct Entry { + std::string name; //!< The name of the entry + EntryType type; //!< The type of the entry + }; + + /** + * @brief This describes what will be returned when reading a directories contents + */ + union ListMode { + struct { + bool directory : 1; //!< The directory listing will contain subdirectories + bool file : 1; //!< The directory listing will contain files + }; + u32 raw; //!< The raw value of the listing mode + }; + static_assert(sizeof(ListMode) == 0x4); + + ListMode listMode; //!< This describes what this directory will return when it is Read + + Directory(ListMode listMode) : listMode(listMode) {} + + /* Delete the move constructor to prevent multiple instances of the same directory */ + Directory(const Directory &) = delete; + + Directory &operator=(const Directory &) = delete; + + virtual ~Directory() = default; + + /** + * @brief Reads the contents of a directory non-recursively + * @return A vector containing each entry + */ + virtual std::vector Read() = 0; + }; +}