void EDirectory::RescanList() { char Dir[256]; char Name[256]; int DirCount = 0; unsigned long SizeCount = 0; FileFind *ff; FileInfo *fi; int rc; if (Files) FreeList(); Count = 0; FCount = 0; if (JustDirectory(Path, Dir, sizeof(Dir)) != 0) return; JustFileName(Path, Name, sizeof(Name)); // we don't want any special information about symbolic links, just to browse files ff = new FileFind(Dir, "*", ffDIRECTORY | ffHIDDEN | ffLINK); if (ff == 0) return ; rc = ff->FindFirst(&fi); while (rc == 0) { assert(fi != 0); if (strcmp(fi->Name(), ".") != 0) { Files = (FileInfo **)realloc((void *)Files, ((FCount | 255) + 1) * sizeof(FileInfo *)); if (Files == 0) { delete fi; delete ff; return; } Files[FCount] = fi; SizeCount += Files[FCount]->Size(); if (fi->Type() == fiDIRECTORY && (strcmp(fi->Name(), "..") != 0)) DirCount++; Count++; FCount++; } else delete fi; rc = ff->FindNext(&fi); } delete ff; { char CTitle[256]; sprintf(CTitle, "%d files%c%d dirs%c%lu bytes%c%-200.200s", FCount, ConGetDrawChar(DCH_V), DirCount, ConGetDrawChar(DCH_V), SizeCount, ConGetDrawChar(DCH_V), Dir); SetTitle(CTitle); } qsort(Files, FCount, sizeof(FileInfo *), FileNameCmp); NeedsRedraw = 1; }
int MultiFileLoad(int createFlags, const char *FileName, const char *Mode, EView *View) { char fX[MAXPATH]; int count = 0; char FPath[MAXPATH]; char FName[MAXPATH]; FileFind *ff; FileInfo *fi; int rc; assert(View != 0); JustDirectory(FileName, fX, sizeof (fX)); if (fX[0] == 0) strcpy(fX, "."); JustFileName(FileName, FName, sizeof(FName)); if (ExpandPath(fX, FPath, sizeof(FPath)) == -1) return 0; Slash(FPath, 1); ff = new FileFind(FPath, FName, ffHIDDEN | ffFULLPATH); if (ff == 0) return 0; rc = ff->FindFirst(&fi); while (rc == 0) { count++; if (FileLoad(createFlags, fi->Name(), Mode, View) == 0) { delete fi; delete ff; return 0; } delete fi; rc = ff->FindNext(&fi); } delete ff; if (count == 0) return FileLoad(createFlags, FileName, Mode, View); return 1; }
int CompletePath(const char *Base, char *Match, int Count) { char Name[MAXPATH]; const char *dirp; char *namep; int len, count = 0; char cname[MAXPATH]; int hascname = 0; RxMatchRes RM; FileFind *ff; FileInfo *fi; int rc; if (strcmp(Base, "") == 0) { if (ExpandPath(".", Name, sizeof(Name)) != 0) return -1; } else { if (ExpandPath(Base, Name, sizeof(Name)) != 0) return -1; } // SlashDir(Name); dirp = Name; namep = SepRChr(Name); if (namep == Name) { dirp = SSLASH; namep = Name + 1; } else if (namep == NULL) { namep = Name; dirp = SDOT; } else { *namep = 0; namep++; } len = strlen(namep); strcpy(Match, dirp); SlashDir(Match); cname[0] = 0; ff = new FileFind(dirp, "*", ffDIRECTORY | ffHIDDEN #if defined(USE_DIRENT) | ffFAST // for SPEED #endif ); if (ff == 0) return 0; rc = ff->FindFirst(&fi); while (rc == 0) { const char *dname = fi->Name(); // filter out unwanted files if ((strcmp(dname, ".") != 0) && (strcmp(dname, "..") != 0) && (!CompletionFilter || RxExec(CompletionFilter, dname, strlen(dname), dname, &RM) != 1)) { if (( #if defined(UNIX) strncmp #else // os2, nt, ... strnicmp #endif (namep, dname, len) == 0) && (dname[0] != '.' || namep[0] == '.')) { count++; if (Count == count) { Slash(Match, 1); strcat(Match, dname); if ( #if defined(USE_DIRENT) // for SPEED IsDirectory(Match) #else fi->Type() == fiDIRECTORY #endif ) Slash(Match, 1); } else if (Count == -1) { if (!hascname) { strcpy(cname, dname); hascname = 1; } else { int o = 0; #ifdef UNIX while (cname[o] && dname[o] && (cname[o] == dname[o])) o++; #endif #if defined(OS2) || defined(NT) while (cname[o] && dname[o] && (toupper(cname[o]) == toupper(dname[o]))) o++; #endif cname[o] = 0; } } } } delete fi; rc = ff->FindNext(&fi); } delete ff; if (Count == -1) { Slash(Match, 1); strcat(Match, cname); if (count == 1) SlashDir(Match); } return count; }