2010-02-09 05:18:39 +01:00
|
|
|
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
|
|
|
|
// This file is part of the "cAudio Engine"
|
|
|
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
#ifndef CUTILS_H_INCLUDED
|
|
|
|
#define CUTILS_H_INCLUDED
|
2010-02-09 06:58:27 +01:00
|
|
|
#include "../include/cAudioPlatform.h"
|
2010-03-14 23:58:03 +01:00
|
|
|
#include "../Headers/cSTLAllocator.h"
|
2010-02-09 06:58:27 +01:00
|
|
|
|
|
|
|
#ifdef CAUDIO_PLATFORM_WIN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# include <windows.h>
|
|
|
|
# include <direct.h>
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CAUDIO_PLATFORM_LINUX
|
|
|
|
# include <dirent.h>
|
|
|
|
# include <stdio.h>
|
2010-02-20 04:03:30 +01:00
|
|
|
# include <cstring>
|
2010-02-09 06:58:27 +01:00
|
|
|
#endif
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2010-03-14 23:58:03 +01:00
|
|
|
namespace cAudio
|
|
|
|
{
|
|
|
|
|
2009-11-21 01:39:46 +01:00
|
|
|
//! Grabs the current extention of a given string.
|
2010-03-14 23:58:03 +01:00
|
|
|
static cAudioString getExt(const cAudioString& filename)
|
2009-08-08 07:51:32 +02:00
|
|
|
{
|
2010-03-14 23:58:03 +01:00
|
|
|
if(filename.find_last_of(".") == cAudioString::npos) return filename;
|
2009-06-21 05:24:30 +02:00
|
|
|
return filename.substr(filename.find_last_of(".") + 1, filename.length()-filename.find_last_of(".")-1);
|
|
|
|
}
|
|
|
|
|
2010-03-14 23:58:03 +01:00
|
|
|
//! Prevents a bug with NULL passed into cAudioString.
|
|
|
|
static cAudioString safeCStr(const char* str)
|
2009-11-20 04:39:56 +01:00
|
|
|
{
|
2010-03-14 23:58:03 +01:00
|
|
|
if( str != NULL ) return cAudioString(str);
|
|
|
|
else return cAudioString("");
|
2009-11-20 04:39:56 +01:00
|
|
|
}
|
|
|
|
|
2010-02-18 05:22:59 +01:00
|
|
|
//! Returns a list of files/directories in the supplied directory. Used internally for auto-installation of plugins.
|
2010-03-14 23:58:03 +01:00
|
|
|
static cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
|
2010-02-09 06:58:27 +01:00
|
|
|
{
|
2010-03-14 23:58:03 +01:00
|
|
|
cAudioVector<cAudioString>::Type FileList;
|
2010-02-09 06:58:27 +01:00
|
|
|
#ifdef CAUDIO_PLATFORM_WIN
|
2010-03-14 23:58:03 +01:00
|
|
|
cAudioString search = path + "\\" + cAudioString("*.*");
|
2010-02-09 06:58:27 +01:00
|
|
|
WIN32_FIND_DATA info;
|
|
|
|
HANDLE h = FindFirstFile(search.c_str(), &info);
|
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0))
|
|
|
|
{
|
|
|
|
FileList.push_back(info.cFileName);
|
|
|
|
}
|
|
|
|
} while (FindNextFile(h, &info));
|
|
|
|
FindClose(h);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CAUDIO_PLATFORM_LINUX
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *dir;
|
|
|
|
d = opendir(path.c_str());
|
|
|
|
if (d)
|
|
|
|
{
|
|
|
|
while ((dir = readdir(d)) != NULL)
|
|
|
|
{
|
|
|
|
if( strcmp( dir->d_name, "." ) == 0 || strcmp( dir->d_name, ".." ) == 0 ) { continue; }
|
|
|
|
if( dir->d_type == DT_DIR ) continue;
|
|
|
|
FileList.push_back(dir->d_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return FileList;
|
|
|
|
}
|
|
|
|
|
2010-03-14 23:58:03 +01:00
|
|
|
};
|
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
#endif //! CUTILS_H_INCLUDED
|