MCPcopy Create free account
hub / github.com/OGRECave/ogre-next / open

Method open

OgreMain/src/OgreFileSystem.cpp:300–374  ·  view source on GitHub ↗

-----------------------------------------------------------------------

Source from the content-addressed store, hash-verified

298 }
299 //-----------------------------------------------------------------------
300 DataStreamPtr FileSystemArchive::open( const String &filename, bool readOnly )
301 {
302 String full_path = concatenate_path( mName, filename );
303
304 // Use filesystem to determine size
305 // (quicker than streaming to the end and back)
306#ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE
307 struct _stat64i32 tagStat;
308 int ret = _wstat( to_wpath( full_path ).c_str(), &tagStat );
309#else
310 struct stat tagStat;
311 int ret = stat( full_path.c_str(), &tagStat );
312#endif
313 assert( ret == 0 && "Problem getting file size" );
314 (void)ret; // Silence warning
315
316 // Always open in binary mode
317 // Also, always include reading
318 std::ios::openmode mode = std::ios::in | std::ios::binary;
319 std::istream *baseStream = 0;
320 std::ifstream *roStream = 0;
321 std::fstream *rwStream = 0;
322
323 if( !readOnly && isReadOnly() )
324 {
325 OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
326 "Cannot open a file in read-write mode in a read-only archive",
327 "FileSystemArchive::open" );
328 }
329
330 if( !readOnly )
331 {
332 mode |= std::ios::out;
333 rwStream = OGRE_NEW_T( std::fstream, MEMCATEGORY_GENERAL )();
334#ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE
335 rwStream->open( to_wpath( full_path ).c_str(), mode );
336#else
337 rwStream->open( full_path.c_str(), mode );
338#endif
339 baseStream = rwStream;
340 }
341 else
342 {
343 roStream = OGRE_NEW_T( std::ifstream, MEMCATEGORY_GENERAL )();
344#ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE
345 roStream->open( to_wpath( full_path ).c_str(), mode );
346#else
347 roStream->open( full_path.c_str(), mode );
348#endif
349 baseStream = roStream;
350 }
351
352 // Should check ensure open succeeded, in case fail for some reason.
353 if( baseStream->fail() )
354 {
355 OGRE_DELETE_T( roStream, basic_ifstream, MEMCATEGORY_GENERAL );
356 OGRE_DELETE_T( rwStream, basic_fstream, MEMCATEGORY_GENERAL );
357 OGRE_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot open file: " + filename,

Callers 1

createMethod · 0.45

Calls 5

concatenate_pathFunction · 0.85
to_wpathFunction · 0.85
isReadOnlyFunction · 0.85
statClass · 0.70
c_strMethod · 0.45

Tested by

no test coverage detected