Deprecated FileSystemAdapter::getHomeFolder().

This commit is contained in:
Patrick 2025-03-28 11:44:15 +01:00
parent e35f5a35f8
commit d7f968db3a
3 changed files with 15 additions and 4 deletions

View File

@ -35,6 +35,7 @@ namespace mijin
struct FileInfo struct FileInfo
{ {
fs::path path; fs::path path;
/// either file size in bytes, or number of entries if folder
std::size_t size = 0; std::size_t size = 0;
bool exists : 1 = false; bool exists : 1 = false;
bool isFolder : 1 = false; bool isFolder : 1 = false;
@ -79,7 +80,8 @@ class FileSystemAdapter
public: public:
virtual ~FileSystemAdapter() = default; virtual ~FileSystemAdapter() = default;
[[nodiscard]] virtual fs::path getHomeFolder() = 0; [[deprecated("Will be removed ASAP")]]
[[nodiscard]] virtual fs::path getHomeFolder() { return {}; } // TODO: get rid of this ...
[[nodiscard]] virtual std::vector<FileInfo> listFiles(const fs::path& folder) = 0; [[nodiscard]] virtual std::vector<FileInfo> listFiles(const fs::path& folder) = 0;
[[nodiscard]] virtual FileInfo getFileInfo(const fs::path& file) = 0; [[nodiscard]] virtual FileInfo getFileInfo(const fs::path& file) = 0;
[[nodiscard]] virtual Optional<fs::path> getNativePath(const fs::path& /* file */) { return NULL_OPTIONAL; } [[nodiscard]] virtual Optional<fs::path> getNativePath(const fs::path& /* file */) { return NULL_OPTIONAL; }

View File

@ -2,6 +2,7 @@
#include "./stacked.hpp" #include "./stacked.hpp"
#include <algorithm> #include <algorithm>
#include "../detect.hpp"
namespace mijin namespace mijin
{ {
@ -35,7 +36,14 @@ fs::path StackedFileSystemAdapter::getHomeFolder()
if (adapters_.empty()) { if (adapters_.empty()) {
return fs::path(); return fs::path();
} }
#if MIJIN_COMPILER == MIJIN_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable : 4996) // yeah, we're using a deprecated function here, in order to implement another deprecated function ¯\_(ツ)_/¯
#endif
return adapters_.front()->getHomeFolder(); return adapters_.front()->getHomeFolder();
#if MIJIN_COMPILER == MIJIN_COMPILER_MSVC
#pragma warning(pop)
#endif
} }
std::vector<FileInfo> StackedFileSystemAdapter::listFiles(const fs::path& folder) std::vector<FileInfo> StackedFileSystemAdapter::listFiles(const fs::path& folder)

View File

@ -36,12 +36,13 @@ public:
void getAllPaths(const fs::path &path, std::vector<PathReference> &outPaths) override; void getAllPaths(const fs::path &path, std::vector<PathReference> &outPaths) override;
using FileSystemAdapter::getAllPaths; using FileSystemAdapter::getAllPaths;
inline void addAdapter(std::unique_ptr<FileSystemAdapter>&& adapter) { inline FileSystemAdapter* addAdapter(std::unique_ptr<FileSystemAdapter>&& adapter) {
adapters_.push_back(std::move(adapter)); adapters_.push_back(std::move(adapter));
return adapters_.back().get();
} }
template<typename TAdapter, typename... TArgs> template<typename TAdapter, typename... TArgs>
inline void emplaceAdapter(TArgs&&... args) { inline TAdapter* emplaceAdapter(TArgs&&... args) {
addAdapter(std::make_unique<TAdapter>(std::forward<TArgs>(args)...)); return static_cast<TAdapter*>(addAdapter(std::make_unique<TAdapter>(std::forward<TArgs>(args)...)));
} }
}; };