| 342 | return _openFileStream(concatenate_path(mName, filename), mode, filename); |
| 343 | } |
| 344 | DataStreamPtr _openFileStream(const String& full_path, std::ios::openmode mode, const String& name) |
| 345 | { |
| 346 | // Use filesystem to determine size |
| 347 | // (quicker than streaming to the end and back) |
| 348 | #ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE |
| 349 | struct _stat64i32 tagStat; |
| 350 | int ret = _wstat(to_wpath(full_path).c_str(), &tagStat); |
| 351 | #else |
| 352 | struct stat tagStat; |
| 353 | int ret = stat(full_path.c_str(), &tagStat); |
| 354 | #endif |
| 355 | size_t st_size = ret == 0 ? tagStat.st_size : 0; |
| 356 | |
| 357 | std::istream* baseStream = 0; |
| 358 | std::ifstream* roStream = 0; |
| 359 | std::fstream* rwStream = 0; |
| 360 | |
| 361 | if (mode & std::ios::out) |
| 362 | { |
| 363 | rwStream = OGRE_NEW_T(std::fstream, MEMCATEGORY_GENERAL)(); |
| 364 | #ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE |
| 365 | rwStream->open(to_wpath(full_path).c_str(), mode); |
| 366 | #else |
| 367 | rwStream->open(full_path.c_str(), mode); |
| 368 | #endif |
| 369 | baseStream = rwStream; |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | roStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)(); |
| 374 | #ifdef _OGRE_FILESYSTEM_ARCHIVE_UNICODE |
| 375 | roStream->open(to_wpath(full_path).c_str(), mode); |
| 376 | #else |
| 377 | roStream->open(full_path.c_str(), mode); |
| 378 | #endif |
| 379 | baseStream = roStream; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | // Should check ensure open succeeded, in case fail for some reason. |
| 384 | if (baseStream->fail()) |
| 385 | { |
| 386 | OGRE_DELETE_T(roStream, basic_ifstream, MEMCATEGORY_GENERAL); |
| 387 | OGRE_DELETE_T(rwStream, basic_fstream, MEMCATEGORY_GENERAL); |
| 388 | OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Cannot open file: " + full_path); |
| 389 | } |
| 390 | |
| 391 | /// Construct return stream, tell it to delete on destroy |
| 392 | FileStreamDataStream* stream = 0; |
| 393 | const String& streamname = name.empty() ? full_path : name; |
| 394 | if (rwStream) |
| 395 | { |
| 396 | // use the writeable stream |
| 397 | stream = OGRE_NEW FileStreamDataStream(streamname, rwStream, st_size); |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | OgreAssertDbg(ret == 0, "Problem getting file size"); |
no test coverage detected