#ifndef UTIL_H #define UTIL_H #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 const char* GetFileExtensive(path filepath){ std::string ext = filepath.extension().string(); ext.erase(std::remove_if(ext.begin(), ext.end(), [](char c){return c=='.';}), ext.end()); return ext.c_str(); } static bool IsMusic(path filepath){ const auto ext = GetFileExtensive(filepath); for(const auto& it : MusicFileExtensive){ if(std::strcmp(it, ext) == 0) return true; } return false; } static bool IsVideo(path filepath){ const auto ext = GetFileExtensive(filepath); for(const auto& it : VideoFileExtensive){ if(std::strcmp(it, ext) == 0) return true; } return false; } static bool IsImg(path filepath){ const auto ext = GetFileExtensive(filepath); for(const auto& it : ImgFileExtensive){ if(std::strcmp(it, ext) == 0) return true; } return false; } public: static FileType GetFileType(path filepath){ if(IsMusic(filepath)) return FileType::MUSIC; if(IsVideo(filepath)) return FileType::VIDEO; if(IsImg(filepath)) return FileType::IMG; return FileType::ERRORTYPE; } }; #endif