cAudio  2.3.0
3d Audio Engine
 All Classes Namespaces Functions Variables Enumerations Pages
cUtils.h
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #pragma once
6 
7 #include "cAudioPlatform.h"
8 #include "cSTLAllocator.h"
9 #include "cAudioString.h"
10 
11 #ifdef CAUDIO_PLATFORM_WIN
12 # include <direct.h>
13 # include <io.h>
14 #endif
15 
16 #ifdef CAUDIO_PLATFORM_LINUX
17 # include <dirent.h>
18 # include <stdio.h>
19 # include <cstring>
20 #endif
21 
22 namespace cAudio
23 {
24 
26 inline cAudioString getExt(const cAudioString& filename)
27 {
28  if(filename.find_last_of(_CTEXT(".")) == cAudioString::npos) return filename;
29  return filename.substr(filename.find_last_of(_CTEXT(".")) + 1, filename.length()-filename.find_last_of(_CTEXT("."))-1);
30 }
31 
34 {
36 #ifdef CAUDIO_PLATFORM_WIN
37  cAudioString search = path + _CTEXT("\\") + cAudioString(_CTEXT("*.*"));
38  WIN32_FIND_DATA info;
39  HANDLE h = FindFirstFile(search.c_str(), &info);
40  if (h != INVALID_HANDLE_VALUE)
41  {
42  do
43  {
44  if (!(cstrcmp(info.cFileName, _CTEXT(".")) == 0 || cstrcmp(info.cFileName, _CTEXT("..")) == 0))
45  {
46  FileList.push_back(info.cFileName);
47  }
48  } while (FindNextFile(h, &info));
49  FindClose(h);
50  }
51 #endif
52 
53 #ifdef CAUDIO_PLATFORM_LINUX
54  DIR *d;
55  struct dirent *dir;
56  d = opendir(path.c_str());
57  if (d)
58  {
59  while ((dir = readdir(d)) != NULL)
60  {
61  if( strcmp( dir->d_name, "." ) == 0 || strcmp( dir->d_name, ".." ) == 0 ) { continue; }
62  if( dir->d_type == DT_DIR ) continue;
63  FileList.push_back(dir->d_name);
64  }
65 
66  closedir(d);
67  }
68 #endif
69 
70  return FileList;
71 }
72 
73 };
cAudioString getExt(const cAudioString &filename)
Grabs the current extention of a given string.
Definition: cUtils.h:26
cAudioVector< cAudioString >::Type getFilesInDirectory(cAudioString path)
Returns a list of files/directories in the supplied directory. Used internally for auto-installation ...
Definition: cUtils.h:33