#ifndef UTIL_H #define UTIL_H #include #include #include #include #include #include enum class FileType { MUSIC, VIDEO, IMG, ERRORTYPE }; const std::array MusicFileExtensive = { "mp3" }; const std::array VideoFileExtensive = { "mp4" }; const std::array ImgFileExtensive = { "jpeg", "jpg", "png", }; using namespace std::filesystem; class Util { private: static std::string_view GetFileExtensive(const path& filepath) { static std::string ext = filepath.extension().string(); ext.erase(std::ranges::remove_if(ext, [](char c) {return c == '.'; }).begin(), ext.end()); return std::string_view{ ext.c_str() }; } static bool IsMusic(const path& filepath) { const auto ext = GetFileExtensive(filepath); for (const auto& it : MusicFileExtensive) { if (it == ext) return true; } return false; } static bool IsVideo(const path& filepath) { const auto ext = GetFileExtensive(filepath); for (const auto& it : VideoFileExtensive) { if (it == ext) return true; } return false; } static bool IsImg(const path& filepath) { const auto ext = GetFileExtensive(filepath); for (const auto& it : ImgFileExtensive) { if (it == ext) return true; } return false; } public: static FileType GetFileType(const path& filepath) { if (IsMusic(filepath)) return FileType::MUSIC; if (IsVideo(filepath)) return FileType::VIDEO; if (IsImg(filepath)) return FileType::IMG; return FileType::ERRORTYPE; } }; #endif