add FiltType enum

This commit is contained in:
Jie 2024-02-20 15:59:21 +08:00
parent 0f1f3db3d5
commit fdd5467208

View File

@ -6,6 +6,14 @@
#include <string>
#include <array>
#include <cstring>
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