101 free(iFileName) ; |
88 free(iFileName) ; |
102 if(iWideName) |
89 if(iWideName) |
103 delete iWideName; |
90 delete iWideName; |
104 if(iPCSideName) |
91 if(iPCSideName) |
105 free(iPCSideName); |
92 free(iPCSideName); |
106 } |
|
107 |
|
108 TFSNode* TFSNode::CreateFromFolder(const char* aPath,TFSNode* aParent) { |
|
109 |
|
110 int len = strlen(aPath); |
|
111 #ifdef __LINUX__ |
|
112 DIR* dir = opendir(aPath); |
|
113 if(dir == NULL) { |
|
114 cout << aPath << " does not contain any subfolder/file.\n"; |
|
115 return aParent; |
|
116 } |
|
117 if(!aParent) |
|
118 aParent = new TFSNode(NULL,"/",ATTR_DIRECTORY); |
|
119 dirent* entry; |
|
120 struct stat statbuf ; |
|
121 char* fileName = new(nothrow) char[len + 200]; |
|
122 if(!fileName) return NULL ; |
|
123 memcpy(fileName,aPath,len); |
|
124 fileName[len] = SPLIT_CHAR; |
|
125 while ((entry = readdir(dir)) != NULL) { |
|
126 if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0) |
|
127 continue ; |
|
128 strcpy(&fileName[len+1],entry->d_name); |
|
129 stat(fileName , &statbuf); |
|
130 TFSNode* pNewItem = new TFSNode(aParent,fileName,S_ISDIR(statbuf.st_mode) ? ATTR_DIRECTORY : 0); |
|
131 pNewItem->Init(statbuf.st_ctime,statbuf.st_atime,statbuf.st_mtime,statbuf.st_size); |
|
132 if(S_ISDIR(statbuf.st_mode)){ |
|
133 CreateFromFolder(fileName,pNewItem); |
|
134 } |
|
135 } |
|
136 delete []fileName ; |
|
137 closedir(dir); |
|
138 #else |
|
139 struct _finddata_t data ; |
|
140 memset(&data, 0, sizeof(data)); |
|
141 char* fileName = new(nothrow) char[len + 200]; |
|
142 if(!fileName) return NULL ; |
|
143 memcpy(fileName,aPath,len); |
|
144 fileName[len] = SPLIT_CHAR; |
|
145 fileName[len+1] = '*'; |
|
146 fileName[len+2] = 0; |
|
147 intptr_t hFind = _findfirst(fileName,&data); |
|
148 |
|
149 if(hFind == (intptr_t)-1 ) { |
|
150 cout << aPath << " does not contain any subfolder/file.\n"; |
|
151 delete []fileName; |
|
152 return aParent; |
|
153 } |
|
154 if(!aParent) |
|
155 aParent = new TFSNode(NULL,"/",ATTR_DIRECTORY); |
|
156 |
|
157 do { |
|
158 if(strcmp(data.name,".") == 0 || strcmp(data.name,"..") == 0) |
|
159 continue ; |
|
160 |
|
161 strcpy(&fileName[len+1],data.name); |
|
162 TUint8 attr = 0; |
|
163 if(data.attrib & _A_SUBDIR) |
|
164 attr |= ATTR_DIRECTORY; |
|
165 if(data.attrib & _A_RDONLY) |
|
166 attr |= ATTR_READ_ONLY ; |
|
167 if(data.attrib & _A_HIDDEN) |
|
168 attr |= ATTR_HIDDEN ; |
|
169 if(data.attrib & _A_SYSTEM) |
|
170 attr |= ATTR_SYSTEM ; |
|
171 if(data.attrib & _A_ARCH) |
|
172 attr |= ATTR_ARCHIVE; |
|
173 TFSNode* pNewItem = new TFSNode(aParent,data.name,attr,fileName); |
|
174 pNewItem->Init(data.time_create,data.time_access,data.time_write,data.size); |
|
175 if(data.attrib & _A_SUBDIR){ |
|
176 CreateFromFolder(fileName,pNewItem); |
|
177 } |
|
178 |
|
179 } while(-1 != _findnext(hFind, &data)); |
|
180 delete []fileName ; |
|
181 _findclose(hFind); |
|
182 #endif |
|
183 |
|
184 return aParent; |
|
185 } |
93 } |
186 |
94 |
187 /** GenerateBasicName : Generate the short name according to long name |
95 /** GenerateBasicName : Generate the short name according to long name |
188 * |
96 * |
189 * algorithm : |
97 * algorithm : |