175 bool dirs, Ogre::StringVector* simpleList, Ogre::FileInfoList* detailList)
const
177 intptr_t lHandle, res;
178 struct _finddata_t tagData;
181 size_t pos1 = pattern.rfind(
'/');
182 size_t pos2 = pattern.rfind(
'\\');
183 if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2)))
185 Ogre::String directory;
186 if (pos1 != pattern.npos)
187 directory = pattern.substr(0, pos1 + 1);
191 lHandle = _findfirst(full_pattern.generic_string().c_str(), &tagData);
193 while (lHandle != -1 && res != -1)
195 if ((dirs == ((tagData.attrib & _A_SUBDIR) != 0)) &&
201 simpleList->push_back(directory + tagData.name);
207 fi.filename = directory + tagData.name;
208 fi.basename = tagData.name;
210 fi.compressedSize = tagData.size;
211 fi.uncompressedSize = tagData.size;
212 detailList->push_back(fi);
215 res = _findnext(lHandle, &tagData);
224 boost::filesystem::path base_dir = mName;
225 if (!directory.empty())
232 Ogre::String mask(
"/");
233 if (pos1 != pattern.npos)
234 mask.append(pattern.substr(pos1 + 1));
236 mask.append(pattern);
238 lHandle = _findfirst(base_dir.generic_string().c_str(), &tagData);
240 while (lHandle != -1 && res != -1)
242 if ((tagData.attrib & _A_SUBDIR) &&
247 base_dir = directory;
248 base_dir /= tagData.name;
249 base_dir.append(mask);
251 findFiles(base_dir.generic_string(), recursive, dirs, simpleList, detailList);
253 res = _findnext(lHandle, &tagData);
286 MMechostr(MSKDEBUG,
">>> Open archive : %s\n", filename.c_str());
290 Ogre::String fname = filename;
292 if ((fname.compare(0, 4,
"apk/") == 0) || (fname.compare(0, 4,
"APK/") == 0))
293 fname = fname.substr(4);
297 Ogre::DataStreamPtr stream;
298 AAsset* asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_BUFFER);
302 Ogre::StringUtil::toLowerCase(fname);
303 asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
308 off_t length = AAsset_getLength(asset);
309 void* membuf = OGRE_MALLOC(length, Ogre::MEMCATEGORY_GENERAL);
310 memcpy(membuf, AAsset_getBuffer(asset), length);
313 stream = Ogre::DataStreamPtr(
new Ogre::MemoryDataStream(membuf, length,
true,
true));
322 if (!boost::filesystem::exists(full_path))
327 Ogre::String lfilename = filename;
328 Ogre::StringUtil::toLowerCase(lfilename);
330 if (!boost::filesystem::exists(full_path))
332 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
333 "Cannot open file: " + filename,
334 "SO3ScolFileSystemArchive::open");
339 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
340 "Cannot open file: " + filename,
341 "SO3ScolFileSystemArchive::open");
345 catch (std::exception &)
347 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
348 "Cannot open file: " + filename,
349 "SO3ScolFileSystemArchive::open");
355 int ret = stat(full_path.generic_string().c_str(), &tagStat);
356 assert(ret == 0 &&
"Problem getting file size");
361 std::ios::openmode mode = std::ios::in | std::ios::binary;
362 std::istream* baseStream = 0;
363 std::ifstream* roStream = 0;
364 std::fstream* rwStream = 0;
366 if (!readOnly && isReadOnly())
368 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
369 "Cannot open a file in read-write mode in a read-only archive",
370 "SO3ScolFileSystemArchive::open");
375 mode |= std::ios::out;
376 rwStream = OGRE_NEW_T(std::fstream, Ogre::MEMCATEGORY_GENERAL)();
377 rwStream->open(full_path.c_str(), mode);
378 baseStream = rwStream;
382 roStream = OGRE_NEW_T(std::ifstream, Ogre::MEMCATEGORY_GENERAL)();
383 roStream->open(full_path.c_str(), mode);
384 baseStream = roStream;
389 if (baseStream->fail())
391 OGRE_DELETE_T(roStream, basic_ifstream, Ogre::MEMCATEGORY_GENERAL);
392 OGRE_DELETE_T(rwStream, basic_fstream, Ogre::MEMCATEGORY_GENERAL);
393 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
394 "Cannot open file: " + filename,
395 "SO3ScolFileSystemArchive::open");
399 Ogre::FileStreamDataStream* stream = 0;
403 stream = OGRE_NEW Ogre::FileStreamDataStream(filename,
404 rwStream, (
size_t)tagStat.st_size,
true);
409 stream = OGRE_NEW Ogre::FileStreamDataStream(filename,
410 roStream, (
size_t)tagStat.st_size,
true);
412 return Ogre::DataStreamPtr(stream);
420 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
421 "Cannot create a file in a read-only archive",
422 "SO3ScolFileSystemArchive::remove");
429 std::ios::openmode mode = std::ios::out | std::ios::binary;
430 std::fstream* rwStream = OGRE_NEW_T(std::fstream, Ogre::MEMCATEGORY_GENERAL)();
431 rwStream->open(full_path.c_str(), mode);
434 if (rwStream->fail())
436 OGRE_DELETE_T(rwStream, basic_fstream, Ogre::MEMCATEGORY_GENERAL);
437 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
438 "Cannot open file: " + filename,
439 "SO3ScolFileSystemArchive::create");
443 Ogre::FileStreamDataStream* stream = OGRE_NEW Ogre::FileStreamDataStream(filename,
446 return Ogre::DataStreamPtr(stream);
454 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
455 "Cannot remove a file from a read-only archive",
456 "SO3ScolFileSystemArchive::remove");
462 if (!boost::filesystem::exists(full_path))
467 Ogre::String lfilename = filename;
468 Ogre::StringUtil::toLowerCase(lfilename);
470 if (!boost::filesystem::exists(full_path))
472 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
473 "Cannot open file: " + filename,
474 "SO3ScolFileSystemArchive::remove");
479 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
480 "Cannot open file: " + filename,
481 "SO3ScolFileSystemArchive::remove");
485 catch (std::exception&)
487 OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
488 "Cannot open file: " + filename,
489 "SO3ScolFileSystemArchive::remove");
492 ::remove(full_path.generic_string().c_str());
501 if (!IsFolderParsed(mName))
504 Ogre::StringVectorPtr files(
new Ogre::StringVector);
505 boost::filesystem::path filedir(mName);
506 if (filedir.has_filename())
507 filedir = filedir.parent_path();
510 Ogre::String fdir(filedir.generic_string().c_str());
511 Ogre::StringUtil::toLowerCase(fdir);
513 std::map<Ogre::String, std::vector< Ogre::String > >::iterator iter = mApkFiles.find(fdir);
514 std::vector< Ogre::String > fileList = iter->second;
515 for (
size_t i = 0; i < fileList.size(); i++)
517 files->push_back(fileList[i]);
524 auto ret = std::make_shared<Ogre::StringVector>();
525 findFiles(
"*", recursive, dirs, ret.get(), 0);
536 if (!IsFolderParsed(mName))
539 Ogre::FileInfoListPtr files(
new Ogre::FileInfoList);
540 boost::filesystem::path filedir(mName);
541 if (filedir.has_filename())
542 filedir = filedir.parent_path();
545 Ogre::String fdir(filedir.generic_string().c_str());
546 Ogre::StringUtil::toLowerCase(fdir);
548 std::map<Ogre::String, std::vector< Ogre::String > >::iterator iter = mApkFiles.find(fdir);
549 std::vector< Ogre::String > fileList = iter->second;
550 for (
size_t i = 0; i < fileList.size(); i++)
557 Ogre::String lowername =
mPathPreFix + fileList[i];
558 Ogre::StringUtil::toLowerCase(lowername);
559 asset = AAssetManager_open(
mAssetManager, lowername.c_str(), AASSET_MODE_UNKNOWN);
566 info.filename = fileList[i];
568 info.basename = fileList[i];
569 info.compressedSize = AAsset_getLength(asset);
570 info.uncompressedSize = info.compressedSize;
571 files->push_back(info);
579 auto ret = std::make_shared<Ogre::FileInfoList>();
580 findFiles(
"*", recursive, dirs, 0, ret.get());
591 auto ret = std::make_shared<Ogre::StringVector>();
592 Ogre::String fname = pattern;
594 if ((fname.compare(0, 4,
"apk/") == 0) || (fname.compare(0, 4,
"APK/") == 0))
595 fname = fname.substr(4);
599 AAsset* asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
603 Ogre::StringUtil::toLowerCase(fname);
604 asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
608 ret->push_back(pattern);
613 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"[WARNING] ::find Could not find the files in APK with pattern : " + pattern);
618 auto ret = std::make_shared<Ogre::StringVector>();
619 findFiles(pattern, recursive, dirs, ret.get(), 0);
624 Ogre::String lpattern = pattern;
625 Ogre::StringUtil::toLowerCase(lpattern);
626 findFiles(lpattern, recursive, dirs, ret.get(), 0);
637 auto ret = std::make_shared<Ogre::FileInfoList>();
638 Ogre::String fname = pattern;
640 if ((fname.compare(0, 4,
"apk/") == 0) || (fname.compare(0, 4,
"APK/") == 0))
641 fname = fname.substr(4);
645 AAsset* asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
649 Ogre::StringUtil::toLowerCase(fname);
650 asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
656 info.filename = pattern;
658 info.basename = pattern;
659 info.compressedSize = AAsset_getLength(asset);
660 info.uncompressedSize = info.compressedSize;
661 ret->push_back(info);
666 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(
"[WARNING] ::findFileInfo Could not find the files in APK with pattern : " + pattern);
671 auto ret = std::make_shared<Ogre::FileInfoList>();
672 findFiles(pattern, recursive, dirs, 0, ret.get());
677 Ogre::String lpattern = pattern;
678 Ogre::StringUtil::toLowerCase(lpattern);
679 findFiles(lpattern, recursive, dirs, 0, ret.get());
690 Ogre::String fname = filename;
692 if ((fname.compare(0, 4,
"apk/") == 0) || (fname.compare(0, 4,
"APK/") == 0))
693 fname = fname.substr(4);
697 AAsset* asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
701 Ogre::StringUtil::toLowerCase(fname);
702 asset = AAssetManager_open(
mAssetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
717 if (boost::filesystem::exists(full_path))
726 Ogre::String lfilename = filename;
727 Ogre::StringUtil::toLowerCase(lfilename);
729 if (boost::filesystem::exists(full_path))
738 catch (std::exception&)