#pragma once #include "IFilesystem.h" #include "fs/Error.h" #include "fs/Mode.h" #include "fs/Api.h" #include "tl/vector.h" namespace fs { class FS_API NativeFilesystem final : public IFilesystem, public tl::lendable_base { public: enum class CheckFlag : uint8_t { ValidatePathCase, //Win32 only, relatively slow, but makes the filesystem behave more like on posix (case-sensitive filenames) }; using CheckFlags = tl::flag_set2; NativeFilesystem() = default; explicit NativeFilesystem(CheckFlags checkFlags); OpenSourceResult openSource(const AbsPath& path, SourceFlags flags = SourceFlags()) const override; OpenStreamSourceResult openStreamSource(const AbsPath& path, SourceFlags flags = SourceFlags()) const override; OpenMapSourceResult openMapSource(const AbsPath& path, MapView mapView = MapView(), SourceFlags flags = SourceFlags()) const override; OpenSinkResult openSink(const AbsPath& path, Mode mode, SinkFlags flags = SinkFlags()) override; OpenStreamSinkResult openStreamSink(const AbsPath& path, Mode mode, SinkFlags flags = SinkFlags()) override; OpenMapSinkResult openMapSink(const AbsPath& path, Mode mode, size_t size, SinkFlags flags = SinkFlags()) override; ConvertToNativePathResult convertToNativePath(const AbsPath& path) const override; IsFileResult isFile(const AbsPath& path) const override; IsFolderResult isFolder(const AbsPath& path) const override; ExistsResult exists(const AbsPath& path) const override; MakeFolderResult makeFolder(const AbsPath& path) override; RenameResult rename(const AbsPath& path, const AbsPath& newPath) override; RemoveResult remove(const AbsPath& path) override; RemoveRecursivelyResult removeRecursively(const AbsPath& path) override; CopyResult copy(const AbsPath& path, const AbsPath& newPath) override; MakeHardLinkResult makeHardLink(const AbsPath& sourcePath, const AbsPath& linkPath) override; MakeSoftLinkResult makeSymLink(const AbsPath& sourcePath, const AbsPath& linkPath) override; SetWriteTimeResult setWriteTime(const AbsPath& path, time_t time) override; GetStatResult getStat(const AbsPath& path) const override; cppcoro::generator enumerate(const AbsPath& path) const override; cppcoro::generator enumerateRecursively(const AbsPath& path) const override; AbsPath getCurrentFolder() const; tl::result setCurrentFolder(const AbsPath& path); typedef tl::result, Error> EnumerateFilesResult; EnumerateFilesResult enumerateFiles(const AbsPath& fullPath) const; typedef tl::result, Error> EnumerateFoldersResult; EnumerateFoldersResult enumerateFolders(const AbsPath& fullPath) const; AbsPath makeAbsPath(const tl::string& string) const; private: CheckFlags m_checkFlags; }; //this FS will do various checks to make the platforms behave similarly //For example path case checks on Win32 to make its FS case-sensitive FS_API extern NativeFilesystem native; //this FS is RAW with no advanced (read: slow) checks //Use it where appropriate, where native is clearly slowing down something vital. //Normal use-case: tools //*** For game or library use, consult with the lead, and think 3 times. *** FS_API extern NativeFilesystem nativeRaw; }