00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLEmbeddedDirectory.h"
00028
00029
00030 #include "OSDLEmbeddedFileSystemManager.h"
00031
00032
00033 #ifdef OSDL_USES_CONFIG_H
00034 #include "OSDLConfig.h"
00035 #endif // OSDL_USES_CONFIG_H
00036
00037
00038 #if OSDL_ARCH_NINTENDO_DS
00039 #include "OSDLConfigForNintendoDS.h"
00040 #endif // OSDL_ARCH_NINTENDO_DS
00041
00042
00043 #if OSDL_USES_PHYSICSFS
00044 #include "physfs.h"
00045 #endif // OSDL_USES_PHYSICSFS
00046
00047
00048 #include "Ceylan.h"
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 using std::string ;
00067 using std::list ;
00068
00069 using namespace Ceylan::System ;
00070
00071 using namespace OSDL ;
00072
00073
00074
00075
00076
00077
00078
00079 EmbeddedDirectory::~EmbeddedDirectory() throw()
00080 {
00081
00082
00083
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 bool EmbeddedDirectory::hasDirectory( const string & subdirectoryName ) const
00102 {
00103
00104 #if OSDL_USES_PHYSICSFS
00105
00106 FileSystemManager * fsManager ;
00107
00108 try
00109 {
00110
00111 fsManager = & getCorrespondingFileSystemManager() ;
00112
00113 }
00114 catch( const DirectoryDelegatingException & e )
00115 {
00116
00117 throw DirectoryLookupFailed(
00118 "EmbeddedDirectory::hasDirectory failed: " + e.toString() ) ;
00119
00120 }
00121
00122 string tmpPath = fsManager->joinPath( _path, subdirectoryName ) ;
00123
00124 return ( PHYSFS_isDirectory( tmpPath.c_str() ) != 0 ) ;
00125
00126 #else // OSDL_USES_PHYSICSFS
00127
00128 throw DirectoryLookupFailed( "EmbeddedDirectory::hasDirectory failed: "
00129 "no PhysicsFS support available." ) ;
00130
00131 #endif // OSDL_USES_PHYSICSFS
00132
00133 }
00134
00135
00136
00137 bool EmbeddedDirectory::hasFile( const string & fileName ) const
00138 {
00139
00140 #if OSDL_USES_PHYSICSFS
00141
00142 FileSystemManager * fsManager ;
00143
00144 try
00145 {
00146
00147 fsManager = & getCorrespondingFileSystemManager() ;
00148
00149 }
00150 catch( const DirectoryDelegatingException & e )
00151 {
00152
00153 throw DirectoryLookupFailed(
00154 "EmbeddedDirectory::hasFile failed: " + e.toString() ) ;
00155
00156 }
00157
00158
00159
00160 string tmpPath = fsManager->joinPath( _path, fileName ) ;
00161
00162 if ( PHYSFS_exists( tmpPath.c_str() ) == 0 )
00163 return false ;
00164
00165
00166 return ( PHYSFS_isDirectory( tmpPath.c_str() ) == 0 ) ;
00167
00168 #else // OSDL_USES_PHYSICSFS
00169
00170 throw DirectoryLookupFailed( "EmbeddedDirectory::hasFile failed: "
00171 "no PhysicsFS support available." ) ;
00172
00173 #endif // OSDL_USES_PHYSICSFS
00174
00175 }
00176
00177
00178
00179 bool EmbeddedDirectory::hasEntry( const string & entryName ) const
00180 {
00181
00182 #if OSDL_USES_PHYSICSFS
00183
00184 FileSystemManager * fsManager ;
00185
00186 try
00187 {
00188
00189 fsManager = & getCorrespondingFileSystemManager() ;
00190
00191 }
00192 catch( const DirectoryDelegatingException & e )
00193 {
00194
00195 throw DirectoryLookupFailed(
00196 "EmbeddedDirectory::hasEntry failed: " + e.toString() ) ;
00197
00198 }
00199
00200 string tmpPath = fsManager->joinPath( _path, entryName ) ;
00201
00202 return ( PHYSFS_exists( tmpPath.c_str() ) != 0 ) ;
00203
00204 #else // OSDL_USES_PHYSICSFS
00205
00206 throw DirectoryLookupFailed( "EmbeddedDirectory::hasEntry failed: "
00207 "no PhysicsFS support available." ) ;
00208
00209 #endif // OSDL_USES_PHYSICSFS
00210
00211 }
00212
00213
00214
00215
00216 void EmbeddedDirectory::getSubdirectories( list<string> & subDirectories ) const
00217 {
00218
00219
00220
00221
00222
00223
00224 throw DirectoryLookupFailed( " EmbeddedDirectory::getSubdirectories: "
00225 "no PhysicsFS support available." ) ;
00226
00227 }
00228
00229
00230
00231 void EmbeddedDirectory::getFiles( list<string> & files ) const
00232 {
00233
00234 #if OSDL_USES_PHYSICSFS
00235
00236 char **rc = PHYSFS_enumerateFiles( _path.c_str() ) ;
00237
00238 char **i ;
00239
00240 for ( i = rc; *i != 0; i++ )
00241 files.push_back( *i ) ;
00242
00243 PHYSFS_freeList( rc ) ;
00244
00245 #else // OSDL_USES_PHYSICSFS
00246
00247 throw Ceylan::System::DirectoryLookupFailed(
00248 "EmbeddedDirectory::getFiles failed: "
00249 "no PhysicsFS support available." ) ;
00250
00251 #endif // OSDL_USES_PHYSICSFS
00252
00253 }
00254
00255
00256
00257 void EmbeddedDirectory::getEntries( list<string> & entries ) const
00258 {
00259
00260 #if OSDL_USES_PHYSICSFS
00261
00262 char **rc = PHYSFS_enumerateFiles( _path.c_str() ) ;
00263
00264 char **i ;
00265
00266 for ( i = rc; *i != 0; i++ )
00267 entries.push_back( *i ) ;
00268
00269 PHYSFS_freeList( rc ) ;
00270
00271 #else // OSDL_USES_PHYSICSFS
00272
00273 throw Ceylan::System::DirectoryLookupFailed(
00274 "EmbeddedDirectory::getEntries failed: "
00275 "no PhysicsFS support available." ) ;
00276
00277 #endif // OSDL_USES_PHYSICSFS
00278
00279 }
00280
00281
00282
00283 void EmbeddedDirectory::getSortedEntries( list<string> & subDirectories,
00284 list<string> & files, list<string> & otherEntries ) const
00285 {
00286
00287
00288
00289
00290
00291
00292 throw DirectoryLookupFailed( "EmbeddedDirectory::getSortedEntries: "
00293 "no PhysicsFS support available." ) ;
00294
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304 const std::string EmbeddedDirectory::toString( Ceylan::VerbosityLevels level )
00305 const
00306 {
00307
00308 return "Embedded directory referring to user-specified path '"
00309 + Ceylan::encodeToROT13( _path )
00310 + "', corresponding to an actual path in archive '" + _path + "'" ;
00311
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321 EmbeddedDirectory & EmbeddedDirectory::Create( const string & newDirectoryName )
00322 {
00323
00324 return * new EmbeddedDirectory( newDirectoryName, true ) ;
00325
00326 }
00327
00328
00329
00330 EmbeddedDirectory & EmbeddedDirectory::Open( const string & directoryName )
00331 {
00332
00333 return * new EmbeddedDirectory( directoryName, false ) ;
00334
00335 }
00336
00337
00338
00339 EmbeddedDirectory::EmbeddedDirectory( const string & directoryName,
00340 bool create ) :
00341 Directory( Ceylan::encodeToROT13(directoryName) )
00342 {
00343
00344 #if OSDL_USES_PHYSICSFS
00345
00346 EmbeddedFileSystemManager::SecureEmbeddedFileSystemManager() ;
00347
00348 if ( create )
00349 {
00350
00351 if ( PHYSFS_mkdir( directoryName.c_str() ) == 0 )
00352 throw DirectoryCreationFailed(
00353 "EmbeddedDirectory constructor failed: "
00354 + EmbeddedFileSystemManager::GetBackendLastError() ) ;
00355
00356 }
00357
00358 #else // OSDL_USES_PHYSICSFS
00359
00360 throw DirectoryException( "EmbeddedDirectory constructor failed: "
00361 "no PhysicsFS support available." ) ;
00362
00363 #endif // OSDL_USES_PHYSICSFS
00364
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 FileSystemManager & EmbeddedDirectory::getCorrespondingFileSystemManager() const
00376 {
00377
00378 try
00379 {
00380
00381 return EmbeddedFileSystemManager::GetEmbeddedFileSystemManager() ;
00382
00383 }
00384 catch ( const EmbeddedFileSystemManagerException & e )
00385 {
00386
00387 throw DirectoryDelegatingException(
00388 "EmbeddedDirectory::getCorrespondingFileSystemManager failed: "
00389 + e.toString() ) ;
00390
00391 }
00392
00393 }