From fdd5467208c37e66767ea137c7ffcfef48b8f285 Mon Sep 17 00:00:00 2001 From: Jie Date: Tue, 20 Feb 2024 15:59:21 +0800 Subject: [PATCH] add FiltType enum --- include/util.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/util.h b/include/util.h index afe6f47..9048552 100644 --- a/include/util.h +++ b/include/util.h @@ -6,6 +6,14 @@ #include #include #include + +enum class FileType{ + MUSIC, + VIDEO, + IMG, + ERRORTYPE +}; + const std::array MusicFileExtensive = { "mp3" }; @@ -23,7 +31,7 @@ const std::array ImgFileExtensive = { using namespace std::filesystem; class Util{ -public: +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()); @@ -48,13 +56,20 @@ public: } static bool IsImg(path filepath){ - const auto ext = GetFileExtensive(filepath);[A + 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 \ No newline at end of file