// ----------------------------------------------------------------------------- // CbsUtils::ExistsL // Returns ETrue, if the file aFile exists. // (other items were commented in a header). // ----------------------------------------------------------------------------- // TBool CbsUtils::ExistsL( const RFs& aFs, const TDesC& aFile ) { TParse filename; aFs.Parse( aFile, filename ); TBool returnCode( EFalse ); TUint attributes; TInt result( aFs.Att( filename.FullName(), attributes ) ); if ( result == KErrNone ) { returnCode = ETrue; } else if ( result == KErrNotFound ) { returnCode = EFalse; } else { User::Leave( result ); } return returnCode; }
LOCAL_C void doExampleL() { // Create a session to the server RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TParse filename; User::LeaveIfError(fs.Parse(KTxtFilename, filename)); callParseFile(fs, filename.FullName()); CleanupStack::PopAndDestroy(); }
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToFileNameL(const TDesC& aFileName) { delete iMatchReqData; iMatchReqData = NULL; iMatchDataType = EMatchAny; // Extract the extension from the data passed in // Parse the path and extract the extension _LIT( KDot, "." ) ; _LIT8( KDot8, "." ); // If there is no dot "." in aFileName then assume that we have been passed the extension only (if KMaxExtLen or less) if ( (aFileName.Length() <= KMaxExtLen) && (aFileName.Find( KDot ) == KErrNotFound) ) { RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(aFileName.Length()+1); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName)); temp.Insert(0,KDot8); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } else if ( aFileName.Find( KDot ) == 0 ) // the first character is dot so assume extension only { RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(aFileName.Length()); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName)); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } else // We have been given the whole filename. Use TParse to extract the extension. { TParse parser ; parser.Set( aFileName, NULL, NULL ) ; if ( !( parser.NamePresent() ) ) User::Leave( KErrBadName ) ; if ( !( parser.PathPresent() ) ) { RFs fsSession ; User::LeaveIfError(fsSession.Connect()); TInt error = fsSession.Parse(aFileName, parser); fsSession.Close(); User::LeaveIfError(error); } // Parser should now have the full filename and path TPtrC extension = parser.Ext(); RBuf8 temp; CleanupClosePushL(temp); temp.CreateL(extension.Length()); User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, extension)); iMatchReqData = CMatchData::CreateL(); iMatchReqData->SetMatchDataL(temp); CleanupStack::PopAndDestroy(&temp); } // If we're here, we must now have the file extension iMatchDataType = EMatchFileExtension; }
bool LongStream::freeSpace( const QString &path, int min) { unsigned long long boundary = minFree; if (min >= 0) boundary = min; QString partitionPath = tempDir() + "/."; if (!path.isEmpty()) partitionPath = path; #if defined(Q_OS_SYMBIAN) bool result(false); RFs fsSession; TInt rv; if ((rv = fsSession.Connect()) != KErrNone) { qDebug() << "Unable to connect to FS:" << rv; } else { TParse parse; TPtrC name(path.utf16(), path.length()); if ((rv = fsSession.Parse(name, parse)) != KErrNone) { qDebug() << "Unable to parse:" << path << rv; } else { TInt drive; if ((rv = fsSession.CharToDrive(parse.Drive()[0], drive)) != KErrNone) { qDebug() << "Unable to convert:" << QString::fromUtf16(parse.Drive().Ptr(), parse.Drive().Length()) << rv; } else { TVolumeInfo info; if ((rv = fsSession.Volume(info, drive)) != KErrNone) { qDebug() << "Unable to volume:" << drive << rv; } else { result = (info.iFree > boundary); } } } fsSession.Close(); } return result; #elif !defined(Q_OS_WIN) struct statfs stats; statfs(partitionPath.toLocal8Bit(), &stats); unsigned long long bavail = ((unsigned long long)stats.f_bavail); unsigned long long bsize = ((unsigned long long)stats.f_bsize); return ((bavail * bsize) > boundary); #else // MS recommend the use of GetDiskFreeSpaceEx, but this is not available on early versions // of windows 95. GetDiskFreeSpace is unable to report free space larger than 2GB, but we're // only concerned with much smaller amounts of free space, so this is not a hindrance. DWORD bytesPerSector(0); DWORD sectorsPerCluster(0); DWORD freeClusters(0); DWORD totalClusters(0); if (::GetDiskFreeSpace(partitionPath.utf16(), &bytesPerSector, §orsPerCluster, &freeClusters, &totalClusters) == FALSE) { qWarning() << "Unable to get free disk space:" << partitionPath; } return ((bytesPerSector * sectorsPerCluster * freeClusters) > boundary); #endif }
GLDEF_C TInt GetFullPath(TParse& aParse, const TText16* upath, RFs& aSession, TDes* aFileName) // // Parse a path of the form "[C:][\]AAA\..\.\BBB\xxx" where: // . indicates the current directory // .. indicates move to the parent directory // An optional "\" at the start of the path indicates the path is not relative to the current path, // and is implied if the drive specifier is present // If aFileName is non-NULL then the final component is a filename and should be copied into // the aFileName descriptor. // { TInt r; TBuf<3> drive; TFileName nextBit; TText16 c=*upath; if (c && upath[1]==KDriveDelimiter) { // drive name specified if (c==L'?') drive.Zero(); // use "?:" to mean scan across drives else { drive.Copy(TPtrC16(upath, 2)); drive.UpperCase(); } upath+=2; drive.Append(TChar(KPathDelimiter)); // enforce absoluteness } else { // no leading drive specifier drive.Zero(); if (c==KPathDelimiter||c==L'/') { upath+=1; drive.Append(TChar(KPathDelimiter)); } } r = aSession.Parse(drive, aParse); // upath now looks like a relative pathname, to be added onto // aParse a directory at a time. Note that '/' is not allowed in // EPOC32 file or directory names, so treat it as an alternative separator c=*upath; while (c && (r==KErrNone)) { const TText16* ustart=upath; do c=*upath++; while (c && c!=KPathDelimiter && c!=L'/'); TInt len=(upath-ustart)-1; // excludes delimiter if (len==0) continue; if (ustart[0]==L'.') { if (len==1) continue; // directory . ignored if (len==2 && ustart[1]==L'.') { // directory .. (void) aParse.PopDir(); // just stick at root dir, no errors continue; } } if (len>=KMaxFileName) return ENAMETOOLONG; if (c==L'\0' && aFileName!=NULL) { // it's the trailing filename aFileName->Copy(TPtrC16(ustart, len)); break; } else { // it's a component of the accumulating path nextBit.Copy(TPtrC16(ustart, len)); r = aParse.AddDir(nextBit); } } return(r); }
void CWebServerEnv::ParseConfigLineL(const RFs& aFs, const TDesC& aLine) // Function which parse the config file and set the configuration { TLex lex(aLine); TPtrC value; TParse parse; lex.SkipSpaceAndMark(); // SkipCharacters until we find a '=' while ((!lex.Eos()) && (lex.Peek() != '=')) lex.Inc(); TPtrC variable = lex.MarkedToken(); if (!lex.Eos()) { //Skip the '=' character. lex.Inc(); lex.SkipSpaceAndMark(); lex.SkipCharacters(); value.Set(lex.MarkedToken()); } else value.Set(_L("")); if (variable.Compare(_L("SERVER_PATH")) == 0) { User::LeaveIfError(parse.Set(value,NULL,NULL)); User::LeaveIfError(aFs.Parse(value,parse)); delete iServerPath; iServerPath = value.AllocL(); } else if (variable.Compare(_L("CGI_PATH")) == 0) { User::LeaveIfError(parse.Set(value,NULL,NULL)); User::LeaveIfError(aFs.Parse(value,parse)); delete iCgiPath; iCgiPath = value.AllocL(); } else if (variable.Compare(_L("ERROR_PATH")) == 0) { User::LeaveIfError(parse.Set(value,NULL,NULL)); User::LeaveIfError(aFs.Parse(value,parse)); delete iErrorPath; iErrorPath = value.AllocL(); } else if (variable.Compare(_L("BACKUP_PATH")) == 0) { User::LeaveIfError(parse.Set(value,NULL,NULL)); User::LeaveIfError(aFs.Parse(value,parse)); delete iBackupPath; iBackupPath = value.AllocL(); } else if (variable.Compare(_L("DEFAULT_RESOURCE")) == 0) { delete iDefaultResource; iDefaultResource = value.AllocL(); } else if (variable.Compare(_L("PORT")) == 0) { lex.UnGetToMark(); User::LeaveIfError(lex.Val(iPort)); } else if (variable.Compare(_L("DELETE_METHOD")) == 0) { if (value.CompareF(_L("Yes")) == 0) iDeleteMethod = TRUE; else iDeleteMethod = FALSE; } else if (variable.Compare(_L("PUT_METHOD")) == 0) { if (value.CompareF(_L("Yes")) == 0) iPutMethod = TRUE; else iPutMethod = FALSE; } else if (variable.Compare(_L("HTTP_REQ")) == 0) { if (value.CompareF(_L("Yes")) == 0) iHttpReq = TRUE; else iHttpReq= FALSE; } else if (variable.Compare(_L("HTTP_RESP")) == 0) { if (value.CompareF(_L("Yes")) == 0) iHttpResp = TRUE; else iHttpResp= FALSE; } else if (variable.Compare(_L("MISC_DATA")) == 0) { if (value.CompareF(_L("Yes")) == 0) iMiscData = TRUE; else iMiscData = FALSE; } else { User::Leave(KErrCorrupt); } }