MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / _AndroidLoadFile

Function _AndroidLoadFile

engine/source/platformAndroid/T2DActivity.cpp:584–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

582}
583
584char* _AndroidLoadFile(const char* fn, U32 *size) {
585
586 char fileName[255];
587
588 //Check for .. in path and remove them so apk reading code doesnt choke on it
589 std::string filepath = fn;
590 //first remove any cases of /./
591 std::string find = "/./";
592 size_t start_pos = filepath.find(find);
593 while (start_pos != std::string::npos)
594 {
595 filepath.replace(start_pos+1, find.length()-1, "");
596 start_pos = filepath.find(find);
597 }
598
599 find = "/../";
600 start_pos = filepath.find(find);
601 while (start_pos != std::string::npos)
602 {
603 size_t begin_pos = filepath.rfind("/", start_pos-1);
604 filepath.replace(begin_pos, (start_pos - begin_pos - 1) + find.length(), "");
605 start_pos = filepath.find(find);
606
607 }
608 if (filepath.find("/") == 0)
609 {
610 strcpy(fileName, filepath.substr(1).c_str());
611 fileName[filepath.size()-1] = '\0';
612 }
613 else
614 {
615 strcpy(fileName, filepath.c_str());
616 fileName[filepath.size()] = '\0';
617 }
618
619 AAsset *asset;
620 uint8_t buf[1024];
621 char* buffer = NULL;
622 *size = 0;
623 asset = AAssetManager_open(platState.engine->app->activity->assetManager, fileName, AASSET_MODE_UNKNOWN);
624 if(asset != NULL){
625 *size = AAsset_getLength(asset);
626 if (*size <= 0)
627 return NULL;
628 buffer = new char[*size + 1];
629 int count = 0;
630 while(true)
631 {
632 int read = AAsset_read(asset, buf, 1024);
633 if (read <= 0)
634 break;
635
636 memcpy(buffer+count,buf, read);
637 count += read;
638
639 }
640 buffer[*size] = '\0';
641

Callers 1

openMethod · 0.85

Calls 4

c_strMethod · 0.80
findMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected