wxString FileData::GetEntry( fileListFieldType num ) const { wxString s; switch ( num ) { case FileList_Name: s = m_fileName; break; case FileList_Size: if (!IsDir() && !IsLink() && !IsDrive()) s.Printf(wxT("%ld"), m_size); break; case FileList_Type: s = GetFileType(); break; case FileList_Time: if (!IsDrive()) s = GetModificationTime(); break; #if defined(__UNIX__) || defined(__WIN32__) case FileList_Perm: s = m_permissions; break; #endif // defined(__UNIX__) || defined(__WIN32__) default: wxFAIL_MSG( wxT("unexpected field in FileData::GetEntry()") ); } return s; }
wxString FileData::GetHint() const { wxString s = m_filePath; s += wxT(" "); if (IsDir()) s += _("<DIR>"); else if (IsLink()) s += _("<LINK>"); else if (IsDrive()) s += _("<DRIVE>"); else // plain file s += wxString::Format( _("%ld bytes"), m_size ); s += wxT(' '); if ( !IsDrive() ) { s << GetModificationTime() << wxT(" ") << m_permissions; } return s; };
wxString wxFileData::GetHint() const { wxString s = m_filePath; s += wxT(" "); if (IsDir()) s += _("<DIR>"); else if (IsLink()) s += _("<LINK>"); else if (IsDrive()) s += _("<DRIVE>"); else // plain file s += wxString::Format(wxPLURAL("%ld byte", "%ld bytes", m_size), wxLongLong(m_size).ToString().c_str()); s += wxT(' '); if ( !IsDrive() ) { s << GetModificationTime() << wxT(" ") << m_permissions; } return s; }
static void WildLexCD(struct cd_parse_s *cps, ASCII * match) { struct parsedname pn; LEVEL_DEBUG("FTP Wildcard patern matching: Path=%s, Pattern=%s, rest=%s", SAFESTRING(cps->buffer), SAFESTRING(match), SAFESTRING(cps->rest)); /* Check potential length */ if (strlen(cps->buffer) + OW_FULLNAME_MAX + 2 > PATH_MAX) { cps->ret = -ENAMETOOLONG; return; } if ( FS_ParsedName(cps->buffer, &pn) != 0 ) { cps->ret = -ENOENT; return; } if (!IsDir(&pn)) { cps->ret = -ENOTDIR; } else { struct wildlexcd wlcd = { NULL, match, cps, }; int root = (cps->buffer[1] == '\0'); wlcd.end = &cps->buffer[strlen(cps->buffer)]; if (root) { --wlcd.end; } wlcd.end[0] = '/'; FS_dir(WildLexCDCallback, &wlcd, &pn); if (root) { ++wlcd.end; } wlcd.end[0] = '\0'; // restore cps->buffer } FS_ParsedName_destroy(&pn); }
IFXRESULT IFXOSFileIterator::GetPlugins( IFXString *subPath ) { IFXRESULT result = IFX_OK; WIN32_FIND_DATA data; BOOL res = FALSE; HANDLE hdl; IFXString tempPath; // find and store all files in this dir ProcessDir( subPath ); // now process subdirs IFXString localPath( m_pluginLocation ); localPath.Concatenate( subPath ); localPath.Concatenate( IFXOSFI_EXTALL ); hdl = FindFirstFile( localPath.Raw(), &data ); // if there are no any file/directory then skip next block if( INVALID_HANDLE_VALUE != hdl ) { // keep searching while there are any files/directories do { // create full path to the found object tempPath.Assign( &m_pluginLocation ); tempPath.Concatenate( subPath ); tempPath.Concatenate( data.cFileName ); // we already found and stored all files we wanted, so check if found object is // a) a directory, // b) its nesting doesn't exceed the limitation (IFXOSFI_MAXDEPTH), // c) its name isn't a "." or ".." if( IsDir( &tempPath ) > 0 && m_depth < IFXOSFI_MAXDEPTH && wcscmp( data.cFileName, IFXOSFI_CURRDIR ) && wcscmp( data.cFileName, IFXOSFI_UPPRDIR ) ) { // we have found a directory and we want to look in it, so // create its relative path: tempPath.Assign( subPath ); tempPath.Concatenate( data.cFileName ); tempPath.Concatenate( L"\\" ); // increment the depth (nesting) m_depth++; // step inside GetPlugins( &tempPath ); // decrement the depth (nesting) m_depth--; } // find next file/directory res = FindNextFile( hdl, &data ); } while( res ); // close handle FindClose( hdl ); } return result; }
void GetDirs(const char* dir, bool recursively, TValueArray<std::string>* result) { FileEnumerator fe(dir, recursively); result->Clear(); while (fe.MoveNext()) if (IsDir(fe.CurrentPath())) result->Add(std::string(fe.CurrentPath())); }
Stroka StripFileComponent(const Stroka& fileName) { Stroka dir = IsDir(fileName) ? fileName : GetDirName(fileName); if (!dir.empty() && dir.back() != GetDirectorySeparator()) { dir.append(GetDirectorySeparator()); } return dir; }
int wxTarEntry::GetMode() const { if (m_IsModeSet || !IsDir()) return m_Mode; else return m_Mode | 0111; }
wxDirName wxDirName::Combine(const wxDirName &right) const { pxAssertMsg(IsDir() && right.IsDir(), L"Warning: Malformed directory name detected during wDirName concatenation."); wxDirName result(right); result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath()); return result; }
bool CreateDirRecursive(LPCTSTR path) { bool ret = IsDir(path) || CreateDirectory(path, nullptr); if (!ret) { ret = CreateDirRecursive(DirName(path)) && CreateDirectory(path, nullptr); } return ret; }
bool CFileInfoW::IsDots() const { if (!IsDir() || Name.IsEmpty()) return false; if (Name[0] != kDot) return false; return Name.Len() == 1 || (Name[1] == kDot && Name.Len() == 2); }
__declspec(dllexport) bool LoadImage(const char *file, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info) { if (!file || !info) return false; if (IsDir(file)) return false; // load the image DWORD dwImageType = GetImageType(file); CxImage *image = new CxImage(dwImageType); if (!image) return false; int actualwidth = maxwidth; int actualheight = maxheight; try { if (!image->Load(file, dwImageType, actualwidth, actualheight) || !image->IsValid()) { #if !defined(_LINUX) && !defined(__APPLE__) int nErr = GetLastError(); #else int nErr = errno; #endif printf("PICTURE::LoadImage: Unable to open image: %s Error:%s (%d)\n", file, image->GetLastError(),nErr); delete image; return false; } } catch (...) { printf("PICTURE::LoadImage: Unable to open image: %s\n", file); delete image; return false; } // ok, now resample the image down if necessary if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0) { printf("PICTURE::LoadImage: Unable to resample picture: %s\n", file); delete image; return false; } // make sure our image is 24bit minimum image->IncreaseBpp(24); // fill in our struct info->width = image->GetWidth(); info->height = image->GetHeight(); info->originalwidth = actualwidth; info->originalheight = actualheight; memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO)); // create our texture info->context = image; info->texture = image->GetBits(); info->alpha = image->AlphaGetBits(); return (info->texture != NULL); };
/* Get a directory, returning a copy of the contents in *buffer (which must be free-ed elsewhere) return length of string, or <0 for error *buffer will be returned as NULL on error */ static void getdircallback( void * v, const struct parsedname * const pn_entry ) { struct charblob * cb = v ; const char * buf = FS_DirName(pn_entry) ; CharblobAdd( buf, strlen(buf), cb ) ; if ( IsDir(pn_entry) ) { CharblobAddChar( '/', cb ) ; } }
void CCoreApplication< APPLICATION, SETTINGS >::CheckRunMode() { LOG_TRACE( "Operating mode check..." ); assert__( !mOperatingInDisplayMode ); QStringList args = arguments(); args.removeFirst(); QString wkspc_dir; mOperatingInDisplayMode = !args.empty() && !IsDir( args[ 0 ] ); //no workspace, but there are command line arguments: let the old BratDisplay ghost take the command }
int EnumDir(char* pchDir) { int i; char buf[256]; char* path; int dirlen = strlen(pchDir) + 1; int pathlen = 0; char** dirlist = NULL; int dircount = 0; for (i = ReadDir(pchDir, buf); !i; i = ReadDir(NULL, buf)) { int len; if (buf[0] == '.' && (buf[1] == 0 || (buf[1] == '.' && buf[2] == 0))) continue; len = dirlen + strlen(buf) + 1; if (len > pathlen) { if (pathlen) free(path); path = malloc(len); pathlen = len; } sprintf(path, "%s/%s", pchDir, buf); if (IsDir(path)) { if (!(dircount % PRE_ALLOC_UNIT)) { dirlist = realloc(dirlist, (dircount + PRE_ALLOC_UNIT) * sizeof(char*)); } dirlist[dircount++] = strdup(buf); } else { if (!(filecount % PRE_ALLOC_UNIT)) { filelist = realloc(filelist, (filecount + PRE_ALLOC_UNIT) * sizeof(char*)); } filelist[filecount++] = strdup(path + prefixlen); //printf("%s\n", path); } } for (i = 0; i < dircount; i++) { int len = dirlen + strlen(dirlist[i]) + 1; if (len > pathlen) { if (pathlen) free(path); path = malloc(len); pathlen = len; } sprintf(path, "%s/%s", pchDir, dirlist[i]); free(dirlist[i]); EnumDir(path); } free(dirlist); if (pathlen) free(path); return 0; }
void CommandData::ProcessCommand() { #ifndef SFX_MODULE const wchar *SingleCharCommands=L"FUADPXETK"; if (Command[0]!=0 && Command[1]!=0 && wcschr(SingleCharCommands,Command[0])!=NULL || *ArcName==0) OutHelp(*Command==0 ? RARX_SUCCESS:RARX_USERERROR); // Return 'success' for 'rar' without parameters. #ifdef _UNIX if (GetExt(ArcName)==NULL && (!FileExist(ArcName) || IsDir(GetFileAttr(ArcName)))) wcsncatz(ArcName,L".rar",ASIZE(ArcName)); #else if (GetExt(ArcName)==NULL) wcsncatz(ArcName,L".rar",ASIZE(ArcName)); #endif if (wcschr(L"AFUMD",*Command)==NULL) { if (GenerateArcName) GenerateArchiveName(ArcName,ASIZE(ArcName),GenerateMask,false); StringList ArcMasks; ArcMasks.AddString(ArcName); ScanTree Scan(&ArcMasks,Recurse,SaveSymLinks,SCAN_SKIPDIRS); FindData FindData; while (Scan.GetNext(&FindData)==SCAN_SUCCESS) AddArcName(FindData.Name); } else AddArcName(ArcName); #endif switch(Command[0]) { case 'P': case 'X': case 'E': case 'T': case 'I': { CmdExtract Extract(this); Extract.DoExtract(); } break; #ifndef SILENT case 'V': case 'L': ListArchive(this); break; default: OutHelp(RARX_USERERROR); #endif } if (!BareOutput) mprintf(L"\n"); }
int APIENTRY ZIPExtract(char* pstrToExt, char* pstrSaveAs) { if (g_uf) { CreateDir(pstrSaveAs); if (!IsDir(pstrSaveAs)) Extract(pstrToExt, pstrSaveAs, g_uf); } return 1; }
String PathUtil::GetLastDirName(const String &path) { String tempPath = path; if(!IsDir(tempPath)) return INVALID_PATH; tempPath = tempPath.substr(0, tempPath.length() - 1); return GetPureFilename(tempPath, true); }
bool CopyFiles(const vector<string>& from, const string& to) { // There are two cases. If there is more than one from file, then the // to argument must designate a directory. If there is exactly one from // file then the to may designate either the destination directory or // the new file name. if (from.size() > 1) { if (!IsDir(to)) return false; bool success = true; for (size_t i = 0; i < from.size(); i++) { string dirname; string basename; _SplitPath(from[i], dirname, basename); if (!CopyFile(from[i], to + "/" + basename)) success = false; } return success; } else if (from.size() == 1) { if (IsDir(to)) { string dirname; string basename; _SplitPath(from[0], dirname, basename); return CopyFile(from[0], to + "/" + basename); } else return CopyFile(from[0], to); } else return false; }
String PathUtil::GetParentPath(const String &fileOrPath) { String tempFile = fileOrPath; FormatPath(tempFile); if(IsDir(tempFile)) { tempFile = tempFile.substr(0, tempFile.length() - 1); } tempFile = GetFileDirPath(tempFile); return tempFile; }
CMemEntry::~CMemEntry() // // Destruct. // { if (iLink.iNext!=NULL) iLink.Deque(); delete iName; if (IsDir()) delete iDir; }
void CommandData::ProcessCommand() { #ifndef SFX_MODULE if (Command[1] && strchr("FUADPXETK",*Command)!=NULL || *ArcName==0) OutHelp(); #ifdef _UNIX if (GetExt(ArcName)==NULL && (!FileExist(ArcName) || IsDir(GetFileAttr(ArcName)))) strcat(ArcName,".rar"); #else if (GetExt(ArcName)==NULL) strcat(ArcName,".rar"); #endif if (strchr("AFUMD",*Command)==NULL) { StringList ArcMasks; ArcMasks.AddString(ArcName); ScanTree Scan(&ArcMasks,Recurse,SaveLinks,SCAN_SKIPDIRS); FindData FindData; while (Scan.GetNext(&FindData)==SCAN_SUCCESS) AddArcName(FindData.Name,FindData.NameW); } else AddArcName(ArcName,NULL); #endif switch(Command[0]) { case 'P': case 'X': case 'E': case 'T': case 'I': { CmdExtract Extract; Extract.DoExtract(this); } break; #if !defined(GUI) && !defined(SILENT) case 'V': case 'L': ListArchive(this); break; default: OutHelp(); #endif } #ifndef GUI if (!BareOutput) mprintf("\n"); #endif }
void CommandData::ProcessCommand() { #ifndef SFX_MODULE const char *SingleCharCommands="FUADPXETK"; if (Command[1] && strchr(SingleCharCommands,*Command)!=NULL || *ArcName==0) OutHelp(); //get filename *ArcName #ifdef _UNIX if (GetExt(ArcName)==NULL && (!FileExist(ArcName) || IsDir(GetFileAttr(ArcName)))) strcat(ArcName,".rar"); #endif //printf("test4 %c %s\n",*Command,ArcName); //找文件,将ArcName传到FindData.Name if (strchr("AFUMD",*Command)==NULL) { StringList ArcMasks; ArcMasks.AddString(ArcName); ScanTree Scan(&ArcMasks,Recurse,SaveLinks,SCAN_SKIPDIRS); FindData FindData; while (Scan.GetNext(&FindData)==SCAN_SUCCESS) AddArcName(FindData.Name,FindData.NameW); //FindData.Name "ere.rar" } #endif switch(Command[0]) { case 'P': case 'X': case 'E': case 'T': case 'I': { printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); CmdExtract Extract; Extract.DoExtract(this); printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); } break; #ifndef SILENT case 'V': case 'L': ListArchive(this); break; default: OutHelp(); #endif } if (!BareOutput) mprintf("\n"); }
wxString wxFileData::GetFileType() const { if (IsDir()) return _("<DIR>"); else if (IsLink()) return _("<LINK>"); else if (IsDrive()) return _("<DRIVE>"); else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND) return m_fileName.AfterLast(wxT('.')); return wxEmptyString; }
bool PathUtil::EnsureDir(const String &dir) { if(!IsDir(dir)) return false; if(!IsDirExist(dir)) { if(!CreateDir(dir)) return false; } return true; }
void PathFinder::AddPaths(const String & ipathlist, bool recursive, bool prepend) { char *work = new char[ipathlist.length()+1]; char *found, *save_ptr; String tmp; String subdirList = wxEmptyString; MOcheck(); wxStrcpy(work,ipathlist.c_str()); found = wxStrtok(work, PATHFINDER_DELIMITER, &save_ptr); while(found) { if(prepend) pathList.push_front(found); else pathList.push_back(found); if(recursive && IsDir(found)) // look for subdirectories { tmp = String(found) + ANYFILE; wxString nextfile = wxFindFirstFile(tmp.c_str(), wxDIR); while ( !nextfile.empty() ) { if(IsDir(nextfile)) { if(subdirList.length() > 0) subdirList += _T(":"); subdirList = subdirList + String(nextfile); } nextfile = wxFindNextFile(); } } found = wxStrtok(NULL, PATHFINDER_DELIMITER, &save_ptr); } delete[] work; if(subdirList.length() > 0) AddPaths(subdirList, recursive); }
wxFileName wxDirName::Combine(const wxFileName &right) const { pxAssertMsg(IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation."); if (right.IsAbsolute()) return right; // Append any directory parts from right, and then set the filename. // Except we can't do that because our m_members are private (argh!) and there is no API // for getting each component of the path. So instead let's use Normalize: wxFileName result(right); result.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath()); return result; }
U8 *DirFile(U8 *dirname,U8 *name=NULL,U8 *_extension=NULL) { /* Strips file from dirname, scans for file upward until found or returns default. ("/TempleOS/Kernel/Hash1a.CPP.Z",NULL,NULL) returns "D:/TempleOS/Kernel" ("/TempleOS/Kernel",NULL,"PRJ.Z") returns "D:/TempleOS/Kernel/Kernel.PRJ.Z" ("/TempleOS/Kernel/Dsk",NULL,"PRJ.Z") returns "D:/TempleOS/Kernel/Kernel.PRJ.Z" ("/TempleOS/Apps/MusicOrgan","Load","CPP.Z") returns "D:/TempleOS/Apps/MusicOrgan/Load.CPP.Z" */ U8 *st=DirNameAbs(dirname),*st2,*st3,*result,*dft=NULL,*ext; if (_extension && *_extension) { if (*_extension=='.') ext=StrNew(_extension); else ext=MSPrintF(".%s",_extension); } else ext=StrNew(""); while (StrOcc(st,'/')&&!IsDir(st)) StrLastRem(st,"/"); while (StrOcc(st,'/')) { st2=StrNew(st); st3=StrNew(st); StrLastRem(st2,"/",st3); if (name) result=MSPrintF("%s/%s%s",st,name,ext); else { if (*ext) result=MSPrintF("%s/%s%s",st,st3,ext); else result=StrNew(st); } if (!dft) dft=StrNew(result); if (!*ext&&(!name||!*name)||FileFind(result)) { Free(st3); Free(st2); Free(st); Free(dft); Free(ext); return result; } Free(st); st=st2; Free(st3); } Free(st); Free(ext); return dft; }
void MakeOptDest(const std::string &src, std::string &dest) { TSTLStrSize len = dest.length(); // Strip trailing /'s while (len && (dest[len-1] == '/')) { dest.erase(len-1, 1); len--; } if (IsDir(dest)) dest = JoinPath(dest, BaseName(src)); }
UInt32 CItem::GetWinAttributes() const { DWORD winAttributes = 0; switch(MadeByVersion.HostOS) { case NFileHeader::NHostOS::kFAT: case NFileHeader::NHostOS::kNTFS: if (FromCentral) winAttributes = ExternalAttributes; break; #ifdef FILE_ATTRIBUTE_UNIX_EXTENSION case NFileHeader::NHostOS::kUnix: case NFileHeader::NHostOS::kMac: case NFileHeader::NHostOS::kOSX: winAttributes = (ExternalAttributes & 0xFFFF0000) | FILE_ATTRIBUTE_UNIX_EXTENSION; if (winAttributes & (NFileHeader::NUnixAttribute::kIFDIR << 16)) winAttributes |= FILE_ATTRIBUTE_DIRECTORY; return winAttributes; #endif default: winAttributes = 0; // must be converted from unix value; } bool fileIsDir = IsDir(); #ifdef __APPLE_CC__ //FIX FOR OS X: It appears that certain archivers don't properly record //the file permissions. This is particularly annoying when the executable //permission is lost. An app bundle will fail to launch silently (only //logging a message in the console, that the user might not check). //The OS X Archiver Utility resolves this by unconditionally setting the //executable permission on each file if the host OS is not explicitly //specified as unix. Due to the lack of an elegant solution here, we //do the same thing below. if(MadeByVersion.HostOS!=NFileHeader::NHostOS::kUnix) { //The MySetFileAttributes function (FileDir.cpp) takes care of applying the umask for us. //It expects the unix mode to be in the upper word, hence the <<16. mode_t typeMask = fileIsDir?S_IFDIR:S_IFREG; winAttributes = (((typeMask | 0777))<<16) | FILE_ATTRIBUTE_UNIX_EXTENSION; } #endif if (fileIsDir) // test it; winAttributes |= FILE_ATTRIBUTE_DIRECTORY; return winAttributes; }