bool CFileDialog::ReadDir(const std::string &dir) { struct dirent *dirstruct; struct stat filestat; DIR *dp; bool isrootdir = ((dir[0] == '/') && (dir.length()==1)); ClearDirList(); dp = opendir (dir.c_str()); if (dp == 0) return false; while ((dirstruct = readdir (dp)) != 0) { if (lstat(dirstruct->d_name, &filestat) != 0) continue; if (mode2Filetype(filestat.st_mode) != 'd') continue; // Has to be a directory... if (!strcmp(dirstruct->d_name, ".")) continue; if ((!strcmp(dirstruct->d_name, "..")) && isrootdir) continue; m_DirItems.push_back(strdup(dirstruct->d_name)); } closedir (dp); return true; }
/* * This is a callback to the scrolling list which displays information * about the current file. (and the whole directory as well) */ static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* Declare local variables. */ CDKENTRY *entry = (CDKENTRY *)object; CDKFSELECT *fselect = (CDKFSELECT *)clientData; CDKLABEL *infoLabel; struct stat fileStat; struct passwd *pwEnt; struct group *grEnt; char *filename; char *filetype; char *mesg[10]; char temp[100]; char stringMode[15]; int len; int intMode; /* Get the file name. */ filename = fselect->entryField->info; /* Get specific information about the files. */ lstat (filename, &fileStat); /* Determine the file type. */ switch (mode2Filetype(fileStat.st_mode)) { case 'l': filetype = "Symbolic Link"; break; case '@': filetype = "Socket"; break; case '-': filetype = "Regular File"; break; case 'd': filetype = "Directory"; break; case 'c': filetype = "Character Device"; break; case 'b': filetype = "Block Device"; break; case '&': filetype = "FIFO Device"; break; default: filetype = "Unknown"; break; } /* Get the user name and group name. */ pwEnt = getpwuid (fileStat.st_uid); grEnt = getgrgid (fileStat.st_gid); /* Convert the mode_t type to both string and int. */ intMode = mode2Char (stringMode, fileStat.st_mode); /* Create the message. */ sprintf (temp, "Directory : </U>%s", fselect->pwd); mesg[0] = copyChar (temp); sprintf (temp, "Filename : </U>%s", filename); mesg[1] = copyChar (temp); sprintf (temp, "Owner : </U>%s<!U> (%d)", pwEnt->pw_name, (int)fileStat.st_uid); mesg[2] = copyChar (temp); sprintf (temp, "Group : </U>%s<!U> (%d)", grEnt->gr_name, (int)fileStat.st_gid); mesg[3] = copyChar (temp); sprintf (temp, "Permissions: </U>%s<!U> (%o)", stringMode, intMode); mesg[4] = copyChar (temp); sprintf (temp, "Size : </U>%ld<!U> bytes", (long) fileStat.st_size); mesg[5] = copyChar (temp); sprintf (temp, "Last Access: </U>%s", ctime (&fileStat.st_atime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[6] = copyChar (temp); sprintf (temp, "Last Change: </U>%s", ctime (&fileStat.st_ctime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[7] = copyChar (temp); sprintf (temp, "File Type : </U>%s", filetype); mesg[8] = copyChar (temp); /* Create the pop up label. */ infoLabel = newCDKLabel (entry->obj.screen, CENTER, CENTER, mesg, 9, TRUE, FALSE); drawCDKLabel (infoLabel, TRUE); wgetch (infoLabel->win); /* Clean up some memory. */ destroyCDKLabel (infoLabel); freeCharList (mesg, 9); /* Redraw the file selector. */ drawCDKFselect (fselect, ObjOf(fselect)->box); return (TRUE); }
/* * This creates a list of the files in the current directory. */ int setCDKFselectDirContents (CDKFSELECT *fselect) { /* Declare local variables. */ struct stat fileStat; char **dirList = 0; char temp[200], mode; int fileCount; int x = 0; /* Get the directory contents. */ fileCount = CDKgetDirectoryContents (fselect->pwd, &dirList); if (fileCount == -1) { /* We couldn't read the directory. Return. */ return 0; } /* Clean out the old directory list. */ freeCharList (fselect->dirContents, fselect->fileCounter); fselect->fileCounter = fileCount; /* Set the properties of the files. */ for (x=0; x < fselect->fileCounter; x++) { /* Stat the file. */ lstat (dirList[x], &fileStat); /* Check the mode. */ mode = ' '; if (((fileStat.st_mode & S_IXUSR) != 0) || ((fileStat.st_mode & S_IXGRP) != 0) || ((fileStat.st_mode & S_IXOTH) != 0)) { mode = '*'; } /* Create the filename. */ switch (mode2Filetype(fileStat.st_mode)) { case 'l': sprintf (temp, "%s%s@", fselect->linkAttribute, dirList[x]); break; case '@': sprintf (temp, "%s%s&", fselect->sockAttribute, dirList[x]); break; case '-': sprintf (temp, "%s%s%c", fselect->fileAttribute, dirList[x], mode); break; case 'd': sprintf (temp, "%s%s/", fselect->dirAttribute, dirList[x]); break; default: sprintf (temp, "%s%c", dirList[x], mode); break; } fselect->dirContents[x] = copyChar (temp); /* Free up this piece of memory. */ } CDKfreeStrings (dirList); return 1; }