/* * Agrega todos los directorios y imagenes al arbol imgTree * Agrega agrega todas las imagenes al imgFile */ tVecStr ImageManager::AddDirectory(const char* dirPath) { tVecStr ans; tVecStr fileList=FileSystem::GetFiles(dirPath,All); if(fileList.size()==0) throw eNotExist(EMPTY); string strdir(dirPath); StrToken::FormatPath(strdir); string dirPathStr = strdir; KeyStr kDirDir(strdir); //Si el directorio existe no lo agrego. if (!dirTree.empty()) if (dirTree.exists(kDirDir)) throw eNotExist(WRONG_MSG_ADD_DIRECTORY); ans.push_back(strdir); strdir=strdir+END_DIRECTORY; KeyStr kDir(strdir); ValueInt vDir(0); ValueNull vNull; dirTree.insert(kDirDir,vNull); imgTree.insert(kDir,vDir); std::cout << std::endl; for(size_t i=0; i<fileList.size();i++) { string fullPath= dirPathStr + fileList[i]; std::cout << ADDING_FILE << fullPath << std::endl; AddImage(fullPath.c_str()); } tVecStr dirList=FileSystem::GetFiles(dirPath,Dir); for(size_t j=0; j<dirList.size();j++) { string strDir= dirPathStr + dirList[j]; string strNewSubDir = strDir; strDir= strDir+"/"; KeyStr kSubDirTreeDir(strDir); strDir= strDir+END_DIRECTORY; KeyStr kSubDir(strDir); ValueInt vSubDir(0); if(!imgTree.exists(kSubDir)) { imgTree.insert(kSubDir,vSubDir); } if(!dirTree.exists(kSubDirTreeDir)) { ans.push_back(strNewSubDir); ValueNull vNull; dirTree.insert(kSubDirTreeDir,vNull); } } return ans; }
status_t TGenericDirentParser::AddEntries(const char *strDirList, const char *option) { status_t status = B_OK; uint32 st = 1; BList list; BString strdir(strDirList), curdir; strdir.ReplaceAll("\r\n", "\n"); strdir.ReplaceAll("\r", "\n"); // ftpd から得た NLST 文字列 strDirList を各行に分割して list にポインタを記憶する char *p = (char *)strdir.String(); while (*p != 0) { list.AddItem(p); p = strchr(p, '\n'); if (p == NULL) break; *p = 0; p++; } // 解析 for(int32 i = 0; i < list.CountItems(); i++) { p = (char *)list.ItemAt(i); // 空白行は無視。但し、次行はディレクトリ名と仮定(再帰モード時) if (strlen(p) == 0) { st = 0; continue; } if (st == 0) { st = 1; if (strcmp(option, "R") == 0) { curdir.SetTo(p); if (curdir.String()[curdir.Length() - 1] == ':') curdir.ReplaceLast(":", ""); i++; // ディレクトリ名の次は total または空行なので無視 continue; } } // 先頭文字(即ち permission のファイル属性) が "-", "d", "l", "c" でなければ無視する。 if (strchr("-dlc", *p) == NULL) continue; uint32 itemCount; char *dlist[10], *permission, *num, *owner, *group, *cparam, *size, *month, *day, *houryear, *name; memset(dlist, 0, sizeof(dlist)); if (*p == 'c') { itemCount = 10; strparse(p, dlist, &itemCount); if (itemCount != 10) continue; permission = dlist[0]; num = dlist[1]; owner = dlist[2]; group = dlist[3]; cparam = dlist[4]; size = dlist[5]; month = dlist[6]; day = dlist[7]; houryear = dlist[8]; name = dlist[9]; } else { itemCount = 9; strparse(p, dlist, &itemCount); if (itemCount != 9) continue; permission = dlist[0]; num = dlist[1]; owner = dlist[2]; group = dlist[3]; size = dlist[4]; month = dlist[5]; day = dlist[6]; houryear = dlist[7]; name = dlist[8]; } // 日付・時間を変換 BString strdate, strtime; if (atoi(houryear) < 1900) { char stryear[5]; time_t timer; struct tm *date; time(&timer); date = localtime(&timer); strftime(stryear, sizeof(stryear), "%Y", date); strdate << stryear; strtime << " " << houryear; } else { strdate << houryear; } strdate << "/"; if (strcasecmp("Jan", month) == 0) strdate << "01"; else if (strcasecmp("Feb", month) == 0) strdate << "02"; else if (strcasecmp("Mar", month) == 0) strdate << "03"; else if (strcasecmp("Apr", month) == 0) strdate << "04"; else if (strcasecmp("May", month) == 0) strdate << "05"; else if (strcasecmp("Jun", month) == 0) strdate << "06"; else if (strcasecmp("Jul", month) == 0) strdate << "07"; else if (strcasecmp("Aug", month) == 0) strdate << "08"; else if (strcasecmp("Sep", month) == 0) strdate << "09"; else if (strcasecmp("Oct", month) == 0) strdate << "10"; else if (strcasecmp("Nov", month) == 0) strdate << "11"; else if (strcasecmp("Dec", month) == 0) strdate << "12"; else strdate << month; char strday[3]; sprintf(strday, "%2.2d", atoi(day)); strdate << "/" << strday << strtime; // リストに追加 status = this->AddEntry(curdir.String(), name, atoi(size), strdate.String(), permission, owner, group); if (status != B_OK) break; } return status; }