cUtils.h
00001
00002
00003
00004
00005 #ifndef CUTILS_H_INCLUDED
00006 #define CUTILS_H_INCLUDED
00007 #include "../include/cAudioPlatform.h"
00008 #include <string>
00009 #include <vector>
00010
00011 #ifdef CAUDIO_PLATFORM_WIN
00012 # define WIN32_LEAN_AND_MEAN
00013 # include <windows.h>
00014 # include <direct.h>
00015 # include <io.h>
00016 #endif
00017
00018 #ifdef CAUDIO_PLATFORM_LINUX
00019 # include <dirent.h>
00020 # include <stdio.h>
00021 # include <cstring>
00022 #endif
00023
00025 static std::string getExt(const std::string& filename)
00026 {
00027 if(filename.find_last_of(".") == std::string::npos) return filename;
00028 return filename.substr(filename.find_last_of(".") + 1, filename.length()-filename.find_last_of(".")-1);
00029 }
00030
00032 static std::string safeCStr(const char* str)
00033 {
00034 if( str != NULL ) return std::string(str);
00035 else return std::string("");
00036 }
00037
00039 static std::vector<std::string> getFilesInDirectory(std::string path)
00040 {
00041 std::vector<std::string> FileList;
00042 #ifdef CAUDIO_PLATFORM_WIN
00043 std::string search = path + "\\" + std::string("*.*");
00044 WIN32_FIND_DATA info;
00045 HANDLE h = FindFirstFile(search.c_str(), &info);
00046 if (h != INVALID_HANDLE_VALUE)
00047 {
00048 do
00049 {
00050 if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0))
00051 {
00052 FileList.push_back(info.cFileName);
00053 }
00054 } while (FindNextFile(h, &info));
00055 FindClose(h);
00056 }
00057 #endif
00058
00059 #ifdef CAUDIO_PLATFORM_LINUX
00060 DIR *d;
00061 struct dirent *dir;
00062 d = opendir(path.c_str());
00063 if (d)
00064 {
00065 while ((dir = readdir(d)) != NULL)
00066 {
00067 if( strcmp( dir->d_name, "." ) == 0 || strcmp( dir->d_name, ".." ) == 0 ) { continue; }
00068 if( dir->d_type == DT_DIR ) continue;
00069 FileList.push_back(dir->d_name);
00070 }
00071
00072 closedir(d);
00073 }
00074 #endif
00075
00076 return FileList;
00077 }
00078
00079 #endif