/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "Math/ByteSize.hpp" #include namespace OpenVulkano { struct FsCount { size_t fileCount = 0, dirCount = 0; [[maybe_unused]] [[nodiscard]] size_t GetTotalEntryCount() const { return fileCount + dirCount; } FsCount& operator +=(const FsCount& other) { fileCount += other.fileCount; dirCount += other.dirCount; return *this; } FsCount operator +(FsCount other) { return other += *this; } FsCount& operator -=(const FsCount& other) { fileCount -= other.fileCount; dirCount -= other.dirCount; return *this; } FsCount operator -(FsCount other) { return other -= *this; } }; struct FsUtils { static bool DeleteEmptyFilesAndDirs(const std::filesystem::path& dir, bool recursive = true); static bool DeleteEmptyDirs(const std::filesystem::path& dir, bool recursive = true); static bool DeleteEmptySubTrees(const std::filesystem::path& dir); static bool IsTreeEmpty(const std::filesystem::path& dir); static size_t DeleteFilesSmallerThan(const std::filesystem::path& dir, size_t minSize, bool recursive = false); [[nodiscard]] static ByteSize GetDirSize(const std::filesystem::path& dir); [[nodiscard]] static FsCount GetDirFileAndDirCount(const std::filesystem::path& dir); [[nodiscard]] static std::string ToValidFileName(std::string filename); [[maybe_unused]] [[nodiscard]] static std::vector FilesWithExtension(const std::filesystem::path& dir, std::string ext); [[nodiscard]] static std::string EnsureExtension(const std::string& filename, const std::string_view& extension); [[nodiscard]] static bool FileContains(const std::filesystem::path& path, const std::string_view& searchString); }; }