| | |
| | |
| |
|
| | #pragma once |
| |
|
| | #include <filesystem> |
| | #include <memory> |
| |
|
| | #include "common/fs/fs_types.h" |
| | #include "common/fs/fs_util.h" |
| |
|
| | namespace Common::FS { |
| |
|
| | class IOFile; |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool NewFile(const std::filesystem::path& path, u64 size = 0); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool NewFile(const Path& path, u64 size = 0) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return NewFile(ToU8String(path), size); |
| | } else { |
| | return NewFile(std::filesystem::path{path}, size); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RemoveFile(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | bool RemoveFile(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return RemoveFile(ToU8String(path)); |
| | } else { |
| | return RemoveFile(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool RenameFile(const std::filesystem::path& old_path, |
| | const std::filesystem::path& new_path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path1, typename Path2> |
| | [[nodiscard]] bool RenameFile(const Path1& old_path, const Path2& new_path) { |
| | using ValueType1 = typename Path1::value_type; |
| | using ValueType2 = typename Path2::value_type; |
| | if constexpr (IsChar<ValueType1> && IsChar<ValueType2>) { |
| | return RenameFile(ToU8String(old_path), ToU8String(new_path)); |
| | } else if constexpr (IsChar<ValueType1> && !IsChar<ValueType2>) { |
| | return RenameFile(ToU8String(old_path), new_path); |
| | } else if constexpr (!IsChar<ValueType1> && IsChar<ValueType2>) { |
| | return RenameFile(old_path, ToU8String(new_path)); |
| | } else { |
| | return RenameFile(std::filesystem::path{old_path}, std::filesystem::path{new_path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] std::shared_ptr<IOFile> FileOpen(const std::filesystem::path& path, |
| | FileAccessMode mode, |
| | FileType type = FileType::BinaryFile, |
| | FileShareFlag flag = FileShareFlag::ShareReadOnly); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] std::shared_ptr<IOFile> FileOpen(const Path& path, FileAccessMode mode, |
| | FileType type = FileType::BinaryFile, |
| | FileShareFlag flag = FileShareFlag::ShareReadOnly) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return FileOpen(ToU8String(path), mode, type, flag); |
| | } else { |
| | return FileOpen(std::filesystem::path{path}, mode, type, flag); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool CreateDir(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool CreateDir(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return CreateDir(ToU8String(path)); |
| | } else { |
| | return CreateDir(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool CreateDirs(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool CreateDirs(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return CreateDirs(ToU8String(path)); |
| | } else { |
| | return CreateDirs(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool CreateParentDir(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool CreateParentDir(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return CreateParentDir(ToU8String(path)); |
| | } else { |
| | return CreateParentDir(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool CreateParentDirs(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool CreateParentDirs(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return CreateParentDirs(ToU8String(path)); |
| | } else { |
| | return CreateParentDirs(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RemoveDir(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | bool RemoveDir(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return RemoveDir(ToU8String(path)); |
| | } else { |
| | return RemoveDir(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RemoveDirRecursively(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | bool RemoveDirRecursively(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return RemoveDirRecursively(ToU8String(path)); |
| | } else { |
| | return RemoveDirRecursively(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RemoveDirContentsRecursively(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | bool RemoveDirContentsRecursively(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return RemoveDirContentsRecursively(ToU8String(path)); |
| | } else { |
| | return RemoveDirContentsRecursively(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool RenameDir(const std::filesystem::path& old_path, |
| | const std::filesystem::path& new_path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path1, typename Path2> |
| | [[nodiscard]] bool RenameDir(const Path1& old_path, const Path2& new_path) { |
| | using ValueType1 = typename Path1::value_type; |
| | using ValueType2 = typename Path2::value_type; |
| | if constexpr (IsChar<ValueType1> && IsChar<ValueType2>) { |
| | return RenameDir(ToU8String(old_path), ToU8String(new_path)); |
| | } else if constexpr (IsChar<ValueType1> && !IsChar<ValueType2>) { |
| | return RenameDir(ToU8String(old_path), new_path); |
| | } else if constexpr (!IsChar<ValueType1> && IsChar<ValueType2>) { |
| | return RenameDir(old_path, ToU8String(new_path)); |
| | } else { |
| | return RenameDir(std::filesystem::path{old_path}, std::filesystem::path{new_path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void IterateDirEntries(const std::filesystem::path& path, const DirEntryCallable& callback, |
| | DirEntryFilter filter = DirEntryFilter::All); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | void IterateDirEntries(const Path& path, const DirEntryCallable& callback, |
| | DirEntryFilter filter = DirEntryFilter::All) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | IterateDirEntries(ToU8String(path), callback, filter); |
| | } else { |
| | IterateDirEntries(std::filesystem::path{path}, callback, filter); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void IterateDirEntriesRecursively(const std::filesystem::path& path, |
| | const DirEntryCallable& callback, |
| | DirEntryFilter filter = DirEntryFilter::All); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | void IterateDirEntriesRecursively(const Path& path, const DirEntryCallable& callback, |
| | DirEntryFilter filter = DirEntryFilter::All) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | IterateDirEntriesRecursively(ToU8String(path), callback, filter); |
| | } else { |
| | IterateDirEntriesRecursively(std::filesystem::path{path}, callback, filter); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool Exists(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool Exists(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return Exists(ToU8String(path)); |
| | } else { |
| | return Exists(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool IsFile(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool IsFile(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return IsFile(ToU8String(path)); |
| | } else { |
| | return IsFile(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool IsDir(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool IsDir(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return IsDir(ToU8String(path)); |
| | } else { |
| | return IsDir(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] std::filesystem::path GetCurrentDir(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] bool SetCurrentDir(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] bool SetCurrentDir(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return SetCurrentDir(ToU8String(path)); |
| | } else { |
| | return SetCurrentDir(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] std::filesystem::file_type GetEntryType(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] std::filesystem::file_type GetEntryType(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return GetEntryType(ToU8String(path)); |
| | } else { |
| | return GetEntryType(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] u64 GetSize(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] u64 GetSize(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return GetSize(ToU8String(path)); |
| | } else { |
| | return GetSize(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] u64 GetFreeSpaceSize(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] u64 GetFreeSpaceSize(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return GetFreeSpaceSize(ToU8String(path)); |
| | } else { |
| | return GetFreeSpaceSize(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [[nodiscard]] u64 GetTotalSpaceSize(const std::filesystem::path& path); |
| |
|
| | #ifdef _WIN32 |
| | template <typename Path> |
| | [[nodiscard]] u64 GetTotalSpaceSize(const Path& path) { |
| | if constexpr (IsChar<typename Path::value_type>) { |
| | return GetTotalSpaceSize(ToU8String(path)); |
| | } else { |
| | return GetTotalSpaceSize(std::filesystem::path{path}); |
| | } |
| | } |
| | #endif |
| |
|
| | } |
| |
|