summaryrefslogtreecommitdiff
path: root/external/collada2gltf/write-only-.dae-file-which-we-need.patch.0
blob: 68980e2bb15f929674b05cfea33eedaeb7a996cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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 <direct.h>
+#include <string.h>
 
 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");
+            unsigned 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