Go to the documentation of this file.00001 #ifndef __DIRECTORY_UTILITIES_CPP__
00002 #define __DIRECTORY_UTILITIES_CPP__
00003
00004 #include <utilities/directory_utilities.h>
00005 #include <utilities/exception.h>
00006 #include <utilities/string_utilities.h>
00007
00008 namespace nitro
00009 {
00010 void Directory::ForceCreateDirectory( const char * DirPath )
00011 {
00012 try
00013 {
00014 char * SafePath;
00015 SafePath = new char[ strlen( DirPath ) + 1 ];
00016
00017 nitro::FSPath::DeleteEndSlash( DirPath , SafePath );
00018
00019
00020
00021 if( DirectoryExists( ( const char * )SafePath ) )
00022 {
00023
00024
00025
00026 return;
00027 }
00028
00029
00030 char SubSafePath[ 4096 ];
00031 if( std::string( nitro::FSPath::ExtractFilePath( SafePath , SubSafePath ) ) == SafePath )
00032 {
00033
00034 throw( nitro::exception( std::string( "An error occured while extracting file path from " ) + SafePath , 0 ) );
00035 }
00036 else
00037 {
00038 ForceCreateDirectory( ( const char * )SubSafePath );
00039
00040 DirectoryAbstraction::CreateDirectory( ( const char * )SafePath );
00041
00042
00043 }
00044
00045 delete [] SafePath;
00046 }
00047 catch( nitro::exception e )
00048 {
00049 throw( nitro::exception( std::string( "/* static */ void Directory::ForceCreateDirectory( const char * DirPath )::" ) + e.what() , e.code() ) );
00050 }
00051 catch( ... )
00052 {
00053 throw( nitro::exception( std::string( "/* static */ void Directory::ForceCreateDirectory( const char * DirPath )::An error occured" ) , 0 ) );
00054 }
00055 }
00056
00057 void Directory::ForceCreateDirectory( const std::string & DirPath )
00058 {
00059 try
00060 {
00061 ForceCreateDirectory( DirPath.c_str() );
00062 }
00063 catch( nitro::exception e )
00064 {
00065 throw( nitro::exception( std::string( "Directory::ForceCreateDirectory( const std::string & DirPath )::" ) + e.what() , e.code() ) );
00066 }
00067 catch( ... )
00068 {
00069 throw( nitro::exception( std::string( "Directory::ForceCreateDirectory( const std::string & DirPath )::An error occured" ) , 0 ) );
00070 }
00071 }
00072
00073 bool Directory::DirectoryExists( const char * DirPath )
00074 {
00075 try
00076 {
00077 nitro::DirectoryAbstraction Directory;
00078 std::string TmpDirectoryPath( nitro::FSPath::AddEndSlash( std::string( DirPath ) ) );
00079
00080 if( Directory.FindFirst( TmpDirectoryPath.c_str() ) )
00081 {
00082 return( false );
00083 }
00084
00085 return( true );
00086 }
00087 catch( nitro::exception e )
00088 {
00089 return( false );
00090 }
00091 catch( ... )
00092 {
00093 throw( nitro::exception( std::string( "bool Directory::DirectoryExists( const char * DirPath )::An error occured" ) , 0 ) );
00094 }
00095 }
00096
00097 bool Directory::DirectoryExists( const std::string & DirPath )
00098 {
00099 try
00100 {
00101 return( DirectoryExists( DirPath.c_str() ) );
00102 }
00103 catch( nitro::exception e )
00104 {
00105 throw( nitro::exception( std::string( "Directory::DirectoryExists( const std::string & DirPath )::" ) + e.what() , e.code() ) );
00106 }
00107 catch( ... )
00108 {
00109 throw( nitro::exception( std::string( "Directory::DirectoryExists( const std::string & DirPath )::An error occured" ) , 0 ) );
00110 }
00111 }
00112
00113 Directory::~Directory()
00114 {
00115 try
00116 {
00117 }
00118 catch( ... )
00119 {
00120 }
00121 }
00122
00123
00124
00125
00126 BEGIN_TESTING_SECTION()
00127
00128 ENABLE_CLASS_TESTING( Directory )
00129
00130 FUNCTION_TESTING_1( aliasDirectoryExists , tstDirectoryExists , const char * , bool , bool )
00131 FUNCTION_TESTING_1( aliasForceCreateDirectory , tstForceCreateDirectory , const char * , void , NO_RET )
00132
00133 END_TESTING_SECTION()
00134 }
00135
00136 #endif