40 #ifndef _resourceutilities_cpp
41 #define _resourceutilities_cpp
43 #include "Resource/resourceutilities.h"
46 #include "stringtool.h"
58 #include <CoreServices/CoreServices.h>
62 #include <sys/types.h>
64 #include <mach-o/dyld.h>
69 #include <sys/types.h>
77 #ifdef CreateDirectory
78 #undef CreateDirectory
81 #ifdef RemoveDirectory
82 #undef RemoveDirectory
124 if( ::CreateDirectoryA(DirectoryPath.c_str(),NULL) < 0 ) {
125 if( ERROR_ALREADY_EXISTS == ::GetLastError() ) {
129 ExceptionStream <<
"Unable to create directory. Error follows:" << std::endl;
130 if( ERROR_PATH_NOT_FOUND == ::GetLastError() ) {
131 ExceptionStream <<
"Path to requested directory does not exist.";
133 ExceptionStream <<
"Error Unknown. :(";
139 if( ::mkdir(DirectoryPath.c_str(),0777) < 0 ) {
140 if( EEXIST == errno ) {
144 ExceptionStream <<
"Unable to create directory. Error follows:" << std::endl;
145 ExceptionStream << std::strerror(errno);
157 size_t StartIndex = 0;
162 if( FolderVec.at(0).find(
':') != String::npos ) {
163 PathAttempt.append( FolderVec.at(0) );
164 PathAttempt.append( 1, SysSlash );
168 PathAttempt.append( 1, SysSlash );
170 for(
size_t VecIndex = StartIndex ; VecIndex < FolderVec.size() ; ++VecIndex )
172 PathAttempt.append( FolderVec.at(VecIndex) );
173 PathAttempt.append( 1, SysSlash );
182 if( stat(DirectoryPath.c_str(),&st) == 0 ) {
183 return S_ISDIR(st.st_mode);
193 if( !rmdir(DirectoryPath.c_str()) ) {
204 struct dirent *DirEntry;
205 if( ( Directory = opendir( Dir.c_str() ) ) ) {
206 while( ( DirEntry = readdir(Directory) ) )
208 Results.push_back( DirEntry->d_name );
224 Whole Last(FileName.find_last_of(
"\\/"));
225 if(FileName.npos == Last) {
228 if( Last<FileName.size() ) {
229 return FileName.substr(0,Last+1);
231 return FileName.substr(0,Last+1);
238 Whole Last(FileName.find_last_of(
"\\/"));
239 if(FileName.npos == Last) {
242 if(Last<FileName.size()) {
243 return FileName.substr(Last+1,FileName.npos);
270 String FullPath = FilePath;
273 FullPath.append(Separator);
275 FullPath.append(FileName);
288 for( String::const_iterator Current = PATH.begin() ; PATH.end()!=Current ; ++Current )
291 Results.push_back(OneEntry);
294 OneEntry += *Current;
304 for( StringVector::const_iterator Iter = PATH.begin() ; Iter!=PATH.end() ; ++Iter )
307 if( std::find(Entries.begin(),Entries.end(),ExecutableName) != Entries.end() ) {
334 char Results[FILENAME_MAX];
336 MaxInt Length = ::readlink(
"/proc/self/exe", Results,
sizeof(Results)-1);
338 Results[Length] =
'\0';
345 GetModuleFileName( NULL, Results, FILENAME_MAX );
349 uint32_t size =
sizeof(Results);
350 if( _NSGetExecutablePath(Results, &size) == 0 ) {
396 if(_chdir(ChangeTo.c_str()))
398 if(chdir(ChangeTo.c_str()))
405 char cCurrentPath[FILENAME_MAX];
408 String Results (_getcwd(cCurrentPath,
sizeof(cCurrentPath)));
410 String Results (getcwd(cCurrentPath,
sizeof(cCurrentPath)));
420 String LowerVar = PathVar;
435 TCHAR path_local_appdata[MAX_PATH];
436 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path_local_appdata))) {
437 return path_local_appdata;
440 struct passwd* pw = getpwuid(getuid());
442 return String(pw->pw_dir);
462 TCHAR path_appdata[MAX_PATH];
463 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path_appdata))) {
467 struct passwd* pw = getpwuid(getuid());
469 return String(pw->pw_dir);
480 TCHAR path_personal[MAX_PATH];
481 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, path_personal))) {
482 return path_personal;
485 struct passwd* pw = getpwuid(getuid());
487 return String(pw->pw_dir);
498 TCHAR path_common_personal[MAX_PATH];
499 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS|CSIDL_FLAG_CREATE, NULL, 0, path_common_personal))) {
500 return path_common_personal;
503 struct passwd* pw = getpwuid(getuid());
505 return String(pw->pw_dir);
StringVector GetSystemPATH(const String &PATH)
Get the $PATH or PATH% split and order for easy checking of how the OS does it.
char ** ArgV
ArgC as it was passed into Main.
std::vector< String > StringVector
This is a simple datatype for a vector container of strings.
int ArgC
ArgC as it was passed into Main.
bool Boole
Generally acts a single bit, true or false.
String ToString(const T &Datum)
Converts whatever to a String as long as a streaming operator is available for it.
String ResolveDataPathFromString(const String &PathVar)
Resolves a string describing one of the platform data paths to the actual path it is...
String GetExecutableDir()
Get the Path to the current executable, in a fast way if possible.
Char8 GetPathSeparator()
Get the character used to separate entries in the system PATH.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Boole CreateDirectoryPath(const String &DirectoryPath)
Creates all directories that do not exist in the provided path.
String CombinePathAndFileName(const String &FilePath, const String &FileName)
Convenience method to verify the necessary system separator is present when concatenating.
String GetExecutableDirFromArg()
Uses the main parameters stored using "CacheMainArgs" to attempt determine executable directory...
String GetLocalAppDataDir()
Gets the path to the directory intended for game and engine config data that is not meant to be share...
This implements the exception hiearchy for Mezzanine.
String GetShareableAppDataDir()
Gets the path to the directory intended for game and engine config data that is allowed to be shared...
std::stringstream StringStream
A Datatype used for streaming operations with strings.
StringVector GetDirContents(const String &Dir)
Get a Listing of the files and subdirectories in a directory.
void ChangeWorkingDirectory(const String &ChangeTo)
Change directory, to the directory indicated.
char Char8
A datatype to represent one character.
String DirName(const String &FileName)
Get the directory portion of a string.
String Which(const String &ExecutableName)
Search the system path the same way most systems do to find an executable.
String GetWorkingDirectory()
Get the working directory as a Mezzanine::String.
String GetCommonUserDataDir()
Gets the path to the directory intended for game saves and user profile data for all users...
String GetExecutableDirFromSystem()
Used a system call to get the curent Directory the executable is in. This make an external system cal...
Boole CreateDirectory(const String &DirectoryPath)
Creates a single new directory.
Thrown when the available information should have worked but failed for unknown reasons.
Char8 GetDirectorySeparator()
Get the character used to separate directories.
String BaseName(const String &FileName)
Get the filename portion of a string.
Thrown when parameters are checked at runtime and found invalid.
long long MaxInt
A large integer type suitable for compile time math and long term microsecond time keeping...
void RemoveDirectory(const String &DirectoryPath)
Remove an empty directory. Error this might throw a Mezzanine::IOException with details about why it ...
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
void CacheMainArgs(int ArgCount, char **ArgVars)
Store the Main arguments for later use.
std::string String
A datatype used to a series of characters.
Boole DoesDirectoryExist(const String &DirectoryPath)
Checks to see if the given path exists and if it is a folder. Error this might throw a Mezzanine::IOE...
String GetCurrentUserDataDir()
Gets the path to the directory intended for game saves and user profile data for the current user...
Thrown when a directory was expected to be there, but was not.