diff --git KMZ2Collada.cpp KMZ2Collada.cpp index d193784..3b5bdfc 100644 --- KMZ2Collada.cpp +++ KMZ2Collada.cpp @@ -2,7 +2,7 @@ #include "kmz/unzip.h" #include "kmz/ioapi.h" -#include +#include using namespace std; @@ -14,39 +14,19 @@ namespace GLTF{ } - void Kmz2Collada::setFileFolder(std::string& strSrc) { - std::string strFolderPath = ""; - char *pFolderName = new char[strSrc.size()]; - - for (unsigned int i = 0; i < strSrc.size(); i++) { - if (strSrc[i] == '\\' || strSrc[i] == '/') { - pFolderName[i] = '\0'; - strFolderPath = strKmzPath + pFolderName; - _mkdir(strFolderPath.c_str()); - } - pFolderName[i] = strSrc[i]; - } - strSrc = strKmzPath +strSrc; - - delete[] pFolderName; - } - void Kmz2Collada::getFilePath(std::string& strSrc) { + void Kmz2Collada::getFilePath(const std::string& strSrc) { char *pTemporaryContent = new char[strSrc.size()+1]; std::string strFilePath; for (unsigned int ipos = 0; ipos < strSrc.size(); ipos ++) { + pTemporaryContent[ipos] = strSrc[ipos]; if (strSrc[ipos] == '\\' || strSrc[ipos] == '/') { - pTemporaryContent[ipos] = '\0'; + pTemporaryContent[ipos+1] = '\0'; strFilePath = pTemporaryContent; - _mkdir(strFilePath.c_str()); } - pTemporaryContent[ipos] = strSrc[ipos]; } - if (strFilePath != "") - strFilePath += '\\'; - strSrc = strFilePath; - strKmzPath = strSrc; + strKmzPath = strFilePath; delete[] pTemporaryContent; } @@ -72,18 +52,24 @@ namespace GLTF{ return ""; } - for (int i = 0; i < zGlobalInfo.number_entry; i++) { + for (int i = 0; i < zGlobalInfo.number_entry; i++, unzGoToNextFile(zFile)) { if (UNZ_OK != unzGetCurrentFileInfo64(zFile, &zFileInfo, pFileName, num, NULL, 0, NULL, 0)) { printf("Read file error\n"); return ""; } - std::string strFilePath = pFileName; - setFileFolder(strFilePath); - if (strstr(strFilePath.c_str(), ".dae")) - strDaePath = strFilePath; + if (!strstr(pFileName, ".dae")) + continue; - FILE *fp = fopen(strFilePath.c_str(),"wb"); + int pos = strlen(pFileName) - 1; + while (pos >= 0) { + if (pFileName[pos] == '\\' || pFileName[pos] == '/') + break; + pos--; + } + strDaePath = strKmzPath + std::string(&pFileName[pos + 1]); + + FILE *fp = fopen(strDaePath.c_str(),"wb"); if (UNZ_OK != unzOpenCurrentFile(zFile)) { printf("Open current file error"); @@ -107,8 +93,6 @@ namespace GLTF{ fclose(fp); delete[] pFileData; pFileData = NULL; - - unzGoToNextFile(zFile); } unzCloseCurrentFile(zFile); @@ -118,4 +102,4 @@ namespace GLTF{ return strDaePath; } -} \ No newline at end of file +} diff --git KMZ2Collada.h KMZ2Collada.h index 5e8bdef..df7e92f 100644 --- KMZ2Collada.h +++ KMZ2Collada.h @@ -10,11 +10,8 @@ namespace GLTF{ Kmz2Collada(); ~Kmz2Collada(); - /** get the kmz file path and set folder.*/ - void setFileFolder(std::string& strSrc); - /** get kmz file path.*/ - void getFilePath(std::string& strSrc); + void getFilePath(const std::string& strSrc); /** copy function.*/ std::string operator()(std::string strInputFile); @@ -25,4 +22,4 @@ namespace GLTF{ }; } -#endif \ No newline at end of file +#endif