AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_PROFILE_UTIL_HPP_
2 #define _AV_TRANSCODER_PROFILE_UTIL_HPP_
3 
4 #if defined(__LINUX__)
5 
6 #define DIRLIST_SEP_CHARS ":;"
7 #define DIRSEP "/"
8 #include <dirent.h>
9 
10 #elif defined(__MACOS__)
11 
12 #define DIRLIST_SEP_CHARS ";:"
13 #define DIRSEP "/"
14 #include <dirent.h>
15 
16 #elif defined(__WINDOWS__)
17 
18 #define DIRLIST_SEP_CHARS ";"
19 #define DIRSEP "\\"
20 
21 // CINTERFACE needs to be declared if compiling with VC++
22 #include <shlobj.h>
23 #include <tchar.h>
24 #ifndef _MSC_VER
25 #define SHGFP_TYPE_CURRENT 0
26 #endif
27 
28 #endif
29 
30 #include <string>
31 #include <cstring>
32 #include <iostream>
33 
34 namespace avtranscoder
35 {
36 
37 void split(std::vector<std::string>& splitString, const std::string& inputString, const std::string& splitChars)
38 {
39  char* part = strtok(const_cast<char*>(inputString.c_str()), splitChars.c_str());
40  while(part != NULL)
41  {
42  splitString.push_back(std::string(part));
43  part = strtok(NULL, splitChars.c_str());
44  }
45 }
46 
47 int getFilesInDir(const std::string& dir, std::vector<std::string>& files)
48 {
49 #if defined(__WINDOWS__)
50  WIN32_FIND_DATA findData;
51  HANDLE findHandle;
52 
53  findHandle = FindFirstFile((dir + "\\*").c_str(), &findData);
54  if(findHandle == INVALID_HANDLE_VALUE)
55  {
56  return -1;
57  }
58  while(1)
59  {
60  const std::string filename(findData.cFileName);
61  bool isdir = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
62  if(!isdir && filename.find(".prf") != std::string::npos)
63  files.push_back(filename);
64 
65  int rval = FindNextFile(findHandle, &findData);
66  if(rval == 0)
67  break;
68  }
69 
70 #else
71  DIR* dp;
72  struct dirent* dirp;
73  if((dp = opendir(dir.c_str())) == NULL)
74  {
75  std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
76  return errno;
77  }
78 
79  while((dirp = readdir(dp)) != NULL)
80  {
81  const std::string filename(dirp->d_name);
82  if(filename == "." || filename == "..")
83  continue;
84  if(filename.find(".prf") != std::string::npos)
85  files.push_back(filename);
86  }
87  closedir(dp);
88 #endif
89 
90  return 0;
91 }
92 }
93 
94 #endif
int getFilesInDir(const std::string &dir, std::vector< std::string > &files)
Definition: util.hpp:47
void split(std::vector< std::string > &splitString, const std::string &inputString, const std::string &splitChars)
Definition: util.hpp:37