TInt CTmsTestStep::DebugLogPosL() { TInt pos = 0; TInt pos1 = 0; RFs fs; fs.Connect(); CleanupClosePushL(fs); if (BaflUtils::FolderExists(fs, KLogLocation)) { RFile file; if (!BaflUtils::FileExists( fs, KLogLocation )) { User::LeaveIfError( file.Create( fs, KLogLocation, EFileWrite|EFileShareAny)); } else { TInt err = file.Open( fs, KLogLocation, EFileWrite|EFileShareAny); if(err == KErrInUse) { CleanupStack::PopAndDestroy(); return KErrGeneral; } file.Seek(ESeekEnd, pos); file.Seek(ESeekCurrent, pos1); file.Close(); } } CleanupStack::PopAndDestroy(); return pos1; }
void CTmsTestStep::DebugLogL(const TDesC8& aTestCaseID, const TDesC8& aResult, TInt aPos = -1) { TInt pos = 0; RFs fs; fs.Connect(); CleanupClosePushL(fs); if (BaflUtils::FolderExists(fs, KLogLocation)) { RFile file; if (!BaflUtils::FileExists( fs, KLogLocation )) { User::LeaveIfError( file.Create( fs, KLogLocation, EFileWrite|EFileShareAny)); } else { TInt err = file.Open( fs, KLogLocation, EFileWrite|EFileShareAny); if(err == KErrInUse) { CleanupStack::PopAndDestroy(); return; } if (aPos == -1) file.Seek(ESeekEnd, pos); else file.Seek(ESeekCurrent, aPos); } file.Write(aTestCaseID); file.Write(aResult); file.Write(_L8("\r\n ")); file.Flush(); file.Close(); } CleanupStack::PopAndDestroy(); }
// ----------------------------------------------------------------------------- // CDownloadUtils::FindContentTypeFromFileL // ----------------------------------------------------------------------------- // void CDownloadUtils::FindContentTypeFromFileL( RHttpDownload& aDownload, TUint8*& aContentTypeString) { TDataRecognitionResult dataType; RApaLsSession apaSession; TInt ret; User::LeaveIfError(apaSession.Connect()); // Create a buffer to hold data from the file TInt bufferSize = 0; TInt seekPosition = 0; apaSession.GetMaxDataBufSize(bufferSize); HBufC8* buffer = HBufC8::NewLC(bufferSize); TPtr8 buf = buffer->Des(); RFile file; HBufC* fileName = HBufC::NewLC( KMaxPath ); TPtr fileNamePtr = fileName->Des(); User::LeaveIfError ( aDownload.GetStringAttribute( EDlAttrDestFilename, fileNamePtr ) ); RFs fs; User::LeaveIfError( fs.Connect() ); CleanupClosePushL( fs ); User::LeaveIfError( file.Open( fs, fileNamePtr, EFileShareAny | EFileRead ) ); // Find current file pointer position file.Seek(ESeekStart, seekPosition); // Read from file file.Read(buf); // return file pointer to original position file.Seek(ESeekStart, seekPosition); // Ask the application architecture to find the file type ret = apaSession.RecognizeData(fileNamePtr, buf, dataType); apaSession.Close(); CleanupStack::PopAndDestroy(3); //fs, fileName, buffer if (ret == KErrNone && (dataType.iConfidence == CApaDataRecognizerType::ECertain) || (dataType.iConfidence == CApaDataRecognizerType::EProbable)) { // If the file type was found, try to match it to a known file type TPtrC8 mimeTypePtr = dataType.iDataType.Des8(); TInt len = mimeTypePtr.Length() + 1; aContentTypeString = new(ELeave) TUint8 [len]; TPtr8 contentTypeStringPtr(aContentTypeString, len); contentTypeStringPtr.Copy(mimeTypePtr); contentTypeStringPtr.ZeroTerminate(); return; } }
TBool CSTPreferences::ReadSettingName(RFile& aFile, TDes8& aSettingName, TInt& aSettingLength) { aSettingName.SetLength(0); TBuf8<KMaxSettingNameLength + 10> buffer; if (aFile.Read(buffer) != KErrNone) return EFalse; TInt filePos = 0; if (aFile.Seek(ESeekCurrent, filePos) != KErrNone) return EFalse; TLex8 lex(buffer); lex.SkipSpaceAndMark(); while (lex.Peek()) { if (lex.Peek() == ':') { aSettingName = lex.MarkedToken(); LWRITELN(iLog, aSettingName); lex.Inc(); break; } lex.Inc(); } if (lex.Val(aSettingLength) != KErrNone) return EFalse; //iLog->WriteLineL(aSettingLength); while (lex.Peek()) { if (lex.Peek() == '=') break; lex.Inc(); } if (lex.Peek() != '=') return EFalse; lex.Inc(); TInt offset = filePos - (buffer.Length() - lex.Offset()); if (aFile.Seek(ESeekStart, offset) != KErrNone) return EFalse; return ETrue; }
// Very simple logging code. This will thrash the file server by // creating a new session to it for every line. Create the file // c:\logs\ct.txt to turn on logging. EXPORT_C void SLogger::Log(const TDesC& aLogFileName, const TDesC& aString, const TDesC8& aSourceFileName, TInt aLineNumber) { // Open the file server and file RFs fs; fs.Connect(); RFile file; TInt error = file.Open(fs, aLogFileName, EFileWrite|EFileShareAny); // If the file doesn't exist, exit if (error != KErrNone) { fs.Close(); return; } // Seek to the end of the file TInt tmp = 0; file.Seek(ESeekEnd, tmp); // And do some logging // Name of the file where the Log function was called file.Write(aSourceFileName); // Number of the line where the Log function was called _LIT8(KLineNumber, ",%d:"); TBuf8<80> buf; buf.Format(KLineNumber, aLineNumber); file.Write(buf); buf.Copy(aString); file.Write(buf); _LIT8(KEnd, "\r\n"); file.Write(KEnd()); // Close and tidy up file.Close(); fs.Close(); }
EXPORT_C void TcLog::Write( const TDesC8& aBuf ) { RFs fs; TInt status = fs.Connect(); if( status == KErrNone ) { // Check that the log folder exists TUint ignored; status = fs.Att( KLogDir, ignored ); if( status == KErrNone ) { RFile file; // If file exists, open it. Otherwise create a new file if( fs.Att( KLogFile, ignored ) == KErrNone ) { status = file.Open( fs, KLogFile, EFileWrite | EFileShareAny ); } else { status = file.Create( fs, KLogFile, EFileWrite | EFileShareAny ); } if( status == KErrNone ) { // Ignore errors from now on TInt pos( 0 ); file.Seek( ESeekEnd, pos ); file.Write( aBuf ); } file.Close(); } } fs.Close(); }
void CTLogger::LogL(const TDesC& aString) { // Open the file server and file RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); // Open the file or create it if doesn't exist, create it RFile file; TDriveUnit sysDrive (fs.GetSystemDrive()); TBuf<128> logFile (sysDrive.Name()); logFile.Append(KLogFilename); TInt error = file.Open(fs, logFile, EFileWrite|EFileShareAny); if (error == KErrNotFound) { error = file.Create(fs, logFile, EFileWrite|EFileShareAny); } User::LeaveIfError(error); CleanupClosePushL(file); // Seek to the end of the file TInt tmp = 0; file.Seek(ESeekEnd, tmp); // And do some logging TBuf8<MAX_LEN> buf; buf.Copy(aString); file.Write(buf); file.Write(KNewLine); // Close and tidy up CleanupStack::PopAndDestroy(2, &fs); }
// ----------------------------------------------------------------------------- // CBCTestLogger::WriteMainLogL // Appends given text to main log file (if exists). // ----------------------------------------------------------------------------- // void CBCTestLogger::WriteMainLogL(const TDesC& aLogText) { TBuf<KLogNameLength> mainLogFileName; // main log file mainLogFileName = KMainLog; RFile mainLogFile; // Open log file for writing. TInt err = mainLogFile.Open( iEikEnv->FsSession(), mainLogFileName, EFileWrite | EFileStreamText | EFileShareAny); if (err != KErrNone) { return; // log file couldn't be opened, do nothing } CleanupClosePushL( mainLogFile ); TInt Pos = 0; mainLogFile.Seek( ESeekEnd,Pos ); WriteToFileL( mainLogFile, aLogText ); mainLogFile.Flush(); mainLogFile.Close(); CleanupStack::PopAndDestroy( &mainLogFile ); }
void CCmdCustomCommand::WriteHandleToFileL(TInt aHandle) { const TChar sysDrive = RFs::GetSystemDriveChar(); RBuf filename; filename.CreateL(KNeverUnloadLibHandleFile().Length() + 1); filename.Append(sysDrive); filename.Append(KNeverUnloadLibHandleFile()); filename.CleanupClosePushL(); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); fs.MkDirAll(filename); // ignore any error RFile file; CleanupClosePushL(file); TInt err=KErrNone; TInt pos = 0; if(KErrNotFound == (err = file.Open(fs, filename, EFileShareExclusive|EFileStream|EFileWrite))) { User::LeaveIfError(file.Replace(fs, filename, EFileShareExclusive|EFileStream|EFileWrite)); } else { User::LeaveIfError(err); file.Seek(ESeekEnd, pos); } RFileWriteStream targetStream; targetStream.Attach(file, pos); // file gets closed by this call, but that's okay, we don't need it any more (targetStream has its own copy of this RFile object that it owns) CleanupClosePushL(targetStream); targetStream.WriteInt32L(aHandle); targetStream.CommitL(); CleanupStack::PopAndDestroy(4); }
// Write Logs TInt CTimerLogger::Log(const TDesC& aDes, TBool aIsLine) { RFile file; iFs.Connect(); TInt err = file.Open(iFs,iLogFile,EFileShareExclusive|EFileWrite); SAFETEST0(err == KErrNone || err == KErrNotFound || err == KErrPathNotFound); if (err != KErrNone) { err = iFs.MkDirAll(iLogFile); SAFETEST0(err == KErrNone || err == KErrAlreadyExists); err = file.Create(iFs,iLogFile,EFileShareExclusive|EFileWrite); SAFETEST0(err == KErrNone); } TBuf8<240> data; data.Copy(aDes); if (aIsLine) { data.Append(_L8("\r\n")); } TInt offset = 0; err = file.Seek(ESeekEnd, offset); SAFETEST0(err == KErrNone); err = file.Write(data); SAFETEST0(err == KErrNone); file.Close(); iFs.Close(); return err; }
TInt CTestStepFlogger::replaceFloggerIniL( const TDesC8& newConfig ) /** Replace the flogger.ini with a new one made up of the contents of newConfig @param newConfig string with all the config items to be set in flogger.ini @return KErrNone if no probs, otherwise an error code. */ { RFile outFile; RFs fileServer; User::LeaveIfError(fileServer.Connect()); HBufC8 * fileContentsHeap; TInt returnCode; // allocate the heap space for the string given size of // the items string. TInt newFileSize = newConfig.Length(); //just so we can see this during debugging fileContentsHeap = HBufC8::NewLC(newFileSize); TPtr8 newFileContents(fileContentsHeap->Des()); // add the config items newFileContents.Append(newConfig); // We must assume the flogger.ini is either there or not there, // If the flogger.ini is already there, and the flogger server is already running // and watching this file, we cannot do any of the following: //* Open and overwrite - if we overwrite a large file with a smaller one, it fails to overwrite the whole file //* Delete and create - after the delete but before the create flogger server will attempt to access //* use RFile::Replace - between the replace and the write flogger server will attempt access // so we must create a temporary file and then use the file system to overwrite the // current with our temp using "replace" which is an atomic operation as far as flogger server is concerned returnCode = outFile.Create(fileServer,KTempDuringCreationFloggerIniFile,EFileWrite); if (returnCode == KErrNone) { TInt pos = 0; outFile.Seek(ESeekStart,pos); outFile.Write(newFileContents); outFile.Close(); fileServer.Replace(KTempDuringCreationFloggerIniFile,KFloggerIniFile); } CleanupStack::PopAndDestroy(fileContentsHeap); fileServer.Close(); if (returnCode != KErrNone) { return returnCode; } else { return KErrNone; } }
void LogFilePrint(TRefByValue<const TDesC> aFormat, ...) { // Connect to file server. This wastes time and resources, but ensures // that the debug macros don't depend on anything else being initialized. RFs fs; PanicIfError(fs.Connect()); // Open file. Append to the end of the file if it exists, or create new // if it doesn't. RFile file; TInt err = file.Open(fs, KLogFileName, EFileWrite | EFileShareExclusive); if ( err == KErrNone ) { TInt pos = 0; PanicIfError(file.Seek(ESeekEnd, pos)); } else if ( err == KErrNotFound ) { PanicIfError(file.Create(fs, KLogFileName, EFileWrite | EFileShareExclusive)); } else { User::Panic(KPanic, err); } // Ugly: Buffer for the message. We don't know how much space is really // needed HBufC *buf = HBufC::New(KFormatBufferSize); if ( !buf ) { User::Panic(KPanic, 1); } TPtr ptr = buf->Des(); // Create a timestamp and write it first on the line TTime time; time.HomeTime(); TRAP(err, time.FormatL(ptr, KTimestampFormat)); PanicIfError(err); TPtrC8 ptr8((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); // Format the message, and write it VA_LIST args; VA_START(args, aFormat); ptr.FormatList(aFormat, args); VA_END(args); ptr8.Set((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); // End with a linefeed ptr = KCRLF; ptr8.Set((TUint8*)ptr.Ptr(), ptr.Size()); PanicIfError(file.Write(ptr8)); delete buf; file.Close(); fs.Close(); }
void CRefTestAgentImportFile::LogInputData(const TDesC8& aInput) { RFile inputDataFile; TInt pos = 0; TInt err = inputDataFile.Open(iFs, KInputDataLogFile(), EFileWrite | EFileStream); if(err == KErrNone) { inputDataFile.Seek(ESeekEnd, pos); inputDataFile.Write(aInput); inputDataFile.Close(); } }
TVerdict CTSISHelperStepController::doTestStepL() { SetTestStepResult(EFail); TPtrC sisFileName; GetStringFromConfig(ConfigSection(),_L("SIS"), sisFileName); Swi::TSisHelperStartParams params(sisFileName); User::LeaveIfError(startSisHelper(params)); Swi::RSisHelper server; User::LeaveIfError(server.Connect()); server.OpenDrmContentL(ContentAccess::EExecute); HBufC8* controller = server.SisControllerLC(); TPtrC expectedController; GetStringFromConfig(ConfigSection(),_L("ExpectedController"), expectedController); RFile file; User::LeaveIfError(file.Open(iFs, expectedController, EFileRead)); TInt pos=0; User::LeaveIfError(file.Seek(ESeekEnd,pos)); TInt expectedLength = pos; pos = 0; User::LeaveIfError(file.Seek(ESeekStart, pos)); if (expectedLength == controller->Des().Length()) { HBufC8* expectedBuffer = HBufC8::NewLC(expectedLength); TPtr8 expected(expectedBuffer->Des()); file.Read(expected); if (expected.Compare(controller->Des()) == 0) { SetTestStepResult(EPass); } CleanupStack::PopAndDestroy(expectedBuffer); } CleanupStack::PopAndDestroy(controller); file.Close(); server.Close(); return TestStepResult(); }
/** Processes a message which describes the detection of an infected file. Appends the relevant text at the end of the file to say that it has been "cleaned". This allows the virus test program to confirm that the test virus scanner is behaving as expected. @internalComponent @param aMessage The message to be processed. */ void CTestVirusHook::CleanFile(const TDesC& aName, TInt aOperation) { RFile infectedFile; TBool bChangedToRw=EFalse; TInt pos=0; TUint fileAtt; TInt r = iFs.Att(aName, fileAtt); if (r != KErrNone) { return; } if (fileAtt & KEntryAttReadOnly) { bChangedToRw = ETrue; r = iFs.SetAtt(aName, 0, KEntryAttReadOnly); } r = infectedFile.Open(iFs, aName, EFileShareAny | EFileWrite); if (r != KErrNone) { return; } //To show we've fixed the file, append "Infection deleted" to the end of it. infectedFile.Seek(ESeekEnd, pos); switch (aOperation) { case EFileOpen: infectedFile.Write(_L8("infection detected - file open\\n")); break; case EFileDelete: infectedFile.Write(_L8("infection detected - file delete\\n")); break; case EFileRename: infectedFile.Write(_L8("infection detected - file rename\\n")); break; case EFileClose: infectedFile.Write(_L8("infection detected - file close\\n")); break; } infectedFile.Close(); if (bChangedToRw) { iFs.SetAtt(aName, KEntryAttReadOnly,0); } }
/** @SYMTestCaseID SYSLIB-XML-CT-3736 @SYMTestCaseDesc Parsing an xml file with extended character.. @SYMTestPriority Medium @SYMTestActions Checks that the parser can deal with extended characters - locales outside of ascii. Parses doc_jp_utf.xml, reconstitutes it as xml, and compares with ref_doc_jp_utf.xml. @SYMTestExpectedResults The reconstructed document is the same as the original document. @SYMDEF DEF051379 */ LOCAL_C void DEF051379L() { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TInt pos = 0; //open a temporary results file RFile result; TFileName filename; User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); CleanupClosePushL(result); //reconstitutes the xml from parser callbacks TRebuildingContentHandler contentHandler(result); CParser* parser = CParser::NewLC(KParserDataType, contentHandler); //parse the file ParseL(*parser, fs, KEncodingTestFile()); test(contentHandler.iError==KErrNone); //open the reference file, and compare with results file RFile ref; User::LeaveIfError(ref.Open(fs, KEncodingRefFile, EFileRead)); CleanupClosePushL(ref); User::LeaveIfError(result.Seek(ESeekStart,pos)); TInt resultSize; User::LeaveIfError(result.Size(resultSize)); TInt refSize; User::LeaveIfError(ref.Size(refSize)); test(resultSize==refSize); TBuf8<256> refBuf; TBuf8<256> resultBuf; while(ref.Read(refBuf)==KErrNone && result.Read(resultBuf)==KErrNone && refBuf.Length()>0) test(refBuf==resultBuf); //check that RFile::Read has read the entire contents of each file, //so that length (from cursor position to end of file) == 0 test(refBuf.Length()==0 && resultBuf.Length()==0); CleanupStack::PopAndDestroy(&ref); CleanupStack::PopAndDestroy(parser); CleanupStack::PopAndDestroy(&result); fs.Delete(filename); CleanupStack::PopAndDestroy(&fs); }
// --------------------------------------------------------------------------- // Creates a checksum for the files. // --------------------------------------------------------------------------- // TUint64 CAknsSrvActiveBackupDataClient::CheckSumL(const RFile& aOpenFile) const { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::CheckSumL" ); // scoot through the database file building the checksum TInt seekPos = 0; // rewind first User::LeaveIfError( aOpenFile.Seek( ESeekStart, seekPos ) ); TUint64 total = 0; HBufC8* block = HBufC8::NewL( KCheckSumBlockSize ); CleanupStack::PushL( block ); TPtr8 ptr=block->Des(); while( ETrue ) { User::LeaveIfError( aOpenFile.Read( ptr ) ); TInt len = ptr.Length(); if( len == 0 ) { break; } // calculate the checksum for( TInt i = 0; i < len; ++i ) { TUint64 carry = total&(0x8000000000000000ULL); total<<=1; if( carry ) { total|=1; } TUint in = ptr[i]; total += in; } }; CleanupStack::PopAndDestroy( block ); // restore file position seekPos = 0; User::LeaveIfError( aOpenFile.Seek( ESeekStart, seekPos ) ); return total; }
EXPORT_C void CMsvTestUtils::WriteFileDataL(TMsvId aId, const TFileName& aFileName, const TFileName& aLogFilepath, TBool aReplace) { TParse dirPath; RFile attach; dirPath.Set(aFileName, NULL, NULL); TInt err = KErrNone; if (attach.Open(iFs, dirPath.FullName(), KEntryAttNormal) != KErrNone) return; // failed to find attachment TFileName filename(aLogFilepath); filename.Append(KFileNameFiles); RFile file; if (aReplace) err = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); else err = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); if(err==KErrNotFound) // file does not exist - create it err=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); TInt offset=0; __ASSERT_ALWAYS(file.Seek(ESeekEnd, offset)==KErrNone, Panic(KErrGeneral)); TBuf<100> buf; buf.Zero(); buf.AppendFormat(_L("\n*** %d *************** File Data ***************\n"), aId); buf.AppendFormat(_L("Filename >>> ")); WriteToFileL(file, buf); WriteToFileL(file, dirPath.NameAndExt()); WriteToFileL(file,_L("\n")); HBufC8* buffer8 = HBufC8::NewLC(1024); TPtr8 buf8 = buffer8->Des(); do { attach.Read(buf8); WriteToFileL(file, buf8); } while (buf8.Length()); buf.Zero(); buf.AppendFormat(_L("\n********************* end of File ***********************\n")); WriteToFileL(file, buf); CleanupStack::PopAndDestroy(); // buffer8 attach.Close(); file.Close(); }
// --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // TInt CNcdProviderUtils::UpdateShutdownFileL( const TDesC& aRootPath ) { DLTRACEIN(("")); RBuf path; AppendPathsLC( path, aRootPath, NcdProviderDefines::KNcdProviderShutdownFile ); BaflUtils::EnsurePathExistsL( FileSession(), aRootPath ); // Try to read the value from the file if it exists, otherwise create a // new file. RFile file; CleanupClosePushL( file ); TInt previousStartups = 0; TInt err = file.Open( FileSession(), path, EFileWrite ); if ( err == KErrNone ) { HBufC8* data = ReadFileL( file ); if ( data->Length() ) { previousStartups = Des8ToInt( *data ); DLTRACE(("Previous startups without good shutdown: %d", previousStartups )); } delete data; data = NULL; User::LeaveIfError( file.Seek( ESeekStart, err ) ); } else { DLTRACE(("No shutdown file, creating")); User::LeaveIfError( file.Replace( FileSession(), path, EFileWrite ) ); } // Update new count to the file previousStartups++; HBufC8* newData = IntToDes8LC( previousStartups ); User::LeaveIfError( file.Write( *newData ) ); CleanupStack::PopAndDestroy( 3, &path ); // newData, file, path DLTRACEOUT(("Wrote previousStartups as: %d", previousStartups)); return previousStartups; }
// -------------------------------------------------------------------------------- // void DumpToFileL( TPtrC8 aBuffer ) // -------------------------------------------------------------------------------- void DumpToFileL( TPtrC8 aBuffer ) { RFs fileSession; TInt pushed(0); if( fileSession.Connect() == KErrNone ) { CleanupClosePushL(fileSession); pushed++; RFile file; #ifdef __WINS__ if( file.Open(fileSession, KNSmlDebugOutputName(), EFileShareAny|EFileWrite) == KErrNone ) #else HBufC* outputName = HBufC::NewLC( KNSmlDebugOutputName().Length()+1 ); pushed++; TPtr namePtr = outputName->Des(); TDriveInfo driveInfo; for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) { fileSession.Drive( driveInfo, driveNumber ); if ( KDriveAttRemovable & driveInfo.iDriveAtt ) { // this is MMC namePtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 )); namePtr.Insert( 1, KNSmlDebugOutputName() ); break; } } if( file.Open(fileSession, *outputName, EFileShareAny|EFileWrite) == KErrNone ) #endif { CleanupClosePushL(file); TInt pos(0); file.Seek(ESeekEnd, pos); RMutex mutex; NSmlGrabMutexLC(mutex, KNSmlDebugMutexName()); TInt result = file.Write(aBuffer); TInt result2 = file.Flush(); mutex.Signal(); CleanupStack::PopAndDestroy(2); // file, mutex User::LeaveIfError(result); User::LeaveIfError(result2); } CleanupStack::PopAndDestroy( pushed ); // fileSession and (for target) outputName } }
EXPORT_C void CMsvTestUtils::WriteBodyDataL(TMsvId aId, const TFileName& aFilepath, CMsvStore& fileStore, TBool aReplace) { CParaFormatLayer* paraLayer = CParaFormatLayer::NewL(); CCharFormatLayer* charLayer = CCharFormatLayer::NewL(); CRichText* body = CRichText::NewL(paraLayer,charLayer); fileStore.RestoreBodyTextL(*body); HBufC* pBodyText = HBufC::NewLC(body->DocumentLength()+(body->DocumentLength()/70)+1); TPtr pBody = pBodyText->Des(); body->Extract(pBody, 0); RFile file; TFileName filename(aFilepath); filename.Append(KFileNameBodies); TInt err = KErrNone; if (aReplace) err = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); else err = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); if(err==KErrNotFound) // file does not exist - create it err=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite); TInt offset=0; iRTest(file.Seek(ESeekEnd, offset)==KErrNone); TBuf<100> buf; buf.Zero(); buf.AppendFormat(_L("*** %d *************** RichText Data ***************\n"), aId); buf.AppendFormat(_L("Size >>> %d\n"), body->DocumentLength()); WriteToFileL(file, buf); RemoveRichtextFormating(pBody); WriteToFileL(file, pBody); buf.Zero(); buf.AppendFormat(_L("\n********************* end of Body ***********************\n")); WriteToFileL(file, buf); CleanupStack::PopAndDestroy(); // pBodyText file.Close(); delete paraLayer; delete charLayer; delete body; }
void CFileOperator::DoManyChangesOnSingleFileL() { TFileName fileName; FileNameGen(fileName, 9999); RFile file; _LIT8(KData, "a"); for(TInt i = 0; i < iNumFiles; i++) { TInt offset = 0; file.Open(iFs, fileName, EFileWrite); file.Seek(ESeekEnd, offset); file.Write(KData); file.Flush(); file.Close(); } }
TUid CDeploymentComponentData::ParseUidFromSisFileL(RFile& aHandleToFile) { RDEBUG("CDeploymentComponentData::ParseUidFromSisFileL"); TUid appUid; TInt uidLen = sizeof(TInt32); TInt seekLen = sizeof(TInt32) + sizeof(TInt32); User::LeaveIfError(aHandleToFile.Seek(ESeekStart, seekLen)); TPckg<TInt32> uid1(appUid.iUid); User::LeaveIfError(aHandleToFile.Read(uid1, uidLen)); if (uid1.Length() != uidLen) { RDEBUG("**** ERROR - uid length inconsistency - underflow"); User::Leave(KErrUnderflow); } RDEBUG_2(" -> returning SIS UID: %d", appUid.iUid ); return appUid; }
// --------------------------------------------------------- // CPosTp148::TraceL // // (other items were commented in a header). // --------------------------------------------------------- // void CPosTp148::TraceL(const TDesC& msg) { _LIT8( KEnd, "\r\n" ); RFile file; TInt err = file.Open(iFileSession, KFileTrace, EFileWrite); if (err == KErrNotFound) { file.Create(iFileSession, KFileTrace, EFileWrite); } HBufC8* line8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( msg ); TInt pos( 0 ); file.Seek( ESeekEnd, pos ); file.Write( *line8 ); file.Write( KEnd ); file.Close(); delete line8; }
static void TestFileSeek() // // Benchmark file seek method // { ClearSessionDirectory(); test.Next(_L("RFile::Seek method")); TInt increment=1789; // random number > cluster size TInt count=0; TInt pos=0; // Create test file TBuf8<1024> testdata(1024); RFile f; TInt r=f.Create(TheFs,_L("SEEKTEST"),EFileStream); test_KErrNone(r); count=64; while (count--) f.Write(testdata); TInt fileSize=count*testdata.MaxLength(); pos=0; count=0; RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; timer.After(reqStat,10000000); // After 10 secs while(reqStat==KRequestPending) { TInt dum=(pos+=increment)%fileSize; f.Seek(ESeekStart,dum); count++; } test.Printf(_L("RFile::Seek operations in 10 secs == %d\n"),count); timer.Close(); f.Close(); TheFs.Delete(_L("SEEKTEST")); }
void CRuleManager::WriteToFile(CRule* aRule) { TFileName filename; GetAppPath(filename); filename.Append(KRuleFile); int pos = filename.LocateReverse('\\'); if (pos != KErrNotFound) { TPtrC dirName = filename.Left(pos + 1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err; if (BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), filename)) err = file.Open(CCoeEnv::Static()->FsSession(), filename, EFileWrite | EFileStreamText); else err = file.Replace(CCoeEnv::Static()->FsSession(), filename, EFileWrite); if (KErrNone != err) { return; } CleanupClosePushL(file); TInt end = 0; file.Seek(ESeekEnd, end); WriteToFile(file,aRule); CleanupStack::PopAndDestroy(); // file }
virtual bool SetPos(dword pos){ if(pos > GetFileSize()) return false; if(pos<GetCurrPos()){ if(pos >= curr_pos-(top-base)){ curr = top-(curr_pos-pos); }else{ //rewind and decompress if(arch_file) arch_file->Seek(data_offs); else{ #ifdef SYMBIAN_OPTIM file.Seek(ESeekStart, data_offs); #else ck.Seek(data_offs); #endif } inflateEnd(&d_stream); MemSet(&d_stream, 0, sizeof(d_stream)); inflateInit2(&d_stream, -MAX_WBITS); curr = top = base; curr_pos = 0; SetPos(pos); } }else if(pos > curr_pos){ //read from file until we've desired position in cache do{ curr_pos += ReadCache(); }while(pos > curr_pos); curr = base + (pos&(CACHE_SIZE-1)); }else curr = top + pos - curr_pos; return true; }
CMessageDigest* CTestUtilSessionSwi::CalculateFileHashLC(const TDesC& aFileName) { // This method provides only a SHA1 digest, but it could be extended // for future use to take a parameter specifying an algorithm. RFile file; User::LeaveIfError(file.Open(Server().FS(), aFileName, EFileRead)); CleanupClosePushL(file); HBufC8* buf = HBufC8::NewLC(1024); TPtr8 bufPtr(buf->Des()); TInt seekPos = 0; file.Seek(ESeekStart, seekPos); CMessageDigest* digest = CSHA1::NewL(); while (KErrNone == file.Read(bufPtr) && bufPtr.Length() != 0) { digest->Update(bufPtr); } CleanupStack::PopAndDestroy(2, &file); CleanupStack::PushL(digest); return digest; }
EXPORT_C TInt TEFparser::GetSectionData(TDesC& aScriptFilepath, TPtrC& aSectiontag, TDesC16 &aTocspTestFile, RFs& aFs) { TInt err = KErrNone; TInt pos = 0; RFile file; // open the .ini file if (BaflUtils::FolderExists(aFs, aScriptFilepath)) { if (BaflUtils::FileExists( aFs, aScriptFilepath )) { file.Open(aFs, aScriptFilepath, EFileRead | EFileShareAny); TFileText aLineReader; TBuf<256> iLine; TBuf<256> tempsectID; // create the section name to search for tempsectID.Copy(KOpenBrk); tempsectID.Append(aSectiontag); tempsectID.Append(KCloseBrk); // read the ini file a line at a time until you find the the section name aLineReader.Set(file); TInt foundTag = -1; while (err != KErrEof && foundTag != 0) { err = aLineReader.Read(iLine); if (err != KErrEof) foundTag = iLine.Find(tempsectID); } // create the next open bracket to search for TBuf<2> tempopenBrk; tempopenBrk.Copy(KOpenBrk); RFile testfile; err = KErrNone; foundTag = -1; // while not at the end of the file and not found the next open bracket while (err != KErrEof && foundTag != 0) { // get the next line of the .ini file err = aLineReader.Read(iLine); if (err != KErrEof) { // if the line of the file doesn't contain an open bracket, we are still in the section body foundTag = iLine.Find(tempopenBrk); if (BaflUtils::FolderExists(aFs, aTocspTestFile) && foundTag != 0) { // open the test file we are going to write all our section info into if (BaflUtils::FileExists( aFs, aTocspTestFile )) { testfile.Open(aFs, aTocspTestFile, EFileWrite|EFileShareAny); testfile.Seek(ESeekEnd, pos); } else { User::LeaveIfError(testfile.Create(aFs, aTocspTestFile, EFileWrite|EFileShareAny)); testfile.Open(aFs, aTocspTestFile, EFileWrite|EFileShareAny); } // append to line of the file end of line characters iLine.Append(_L("\r\n")); // write line of the code out to the test file in UNICODE format TPtrC8 tmpPoint((TText8*)iLine.Ptr(),iLine.Size()); testfile.Write(tmpPoint); testfile.Flush(); } testfile.Close(); } } } } return KErrNone; }
TVerdict CTSISHelperStepData::doTestStepL() { SetTestStepResult(EFail); // Start the SISHelper TPtrC sisFileName; GetStringFromConfig(ConfigSection(),_L("SIS"), sisFileName); Swi::TSisHelperStartParams params(sisFileName); User::LeaveIfError(startSisHelper(params)); Swi::RSisHelper server; User::LeaveIfError(server.Connect()); server.OpenDrmContentL(ContentAccess::EExecute); TInt dataUnit = 0; GetIntFromConfig(ConfigSection(),_L("DataUnit"), dataUnit); TInt fileNumber = 0; GetIntFromConfig(ConfigSection(),_L("FileNumber"), fileNumber); // Create a file handle to pass RFs sharedFs; RFile sharedFile; User::LeaveIfError(sharedFs.Connect()); User::LeaveIfError(sharedFs.ShareProtected()); _LIT(KTempFileName,"\\tsishelper.temp"); TDriveUnit sysDrive (RFs::GetSystemDrive()); TBuf<64> tempFileName (sysDrive.Name()); tempFileName.Append(KTempFileName); User::LeaveIfError(sharedFile.Replace (sharedFs, tempFileName, EFileWrite)); TInt fakeUiHandler=0; Swi::RUiHandler& uiHandler=reinterpret_cast<Swi::RUiHandler&>(fakeUiHandler); User::LeaveIfError(server.ExtractFileL(sharedFs, sharedFile, fileNumber, dataUnit, uiHandler)); sharedFile.Close(); sharedFs.Close(); TPtrC expectedData; GetStringFromConfig(ConfigSection(),_L("ExpectedData"), expectedData); RFile oldFile; User::LeaveIfError(oldFile.Open(iFs, expectedData, EFileRead)); RFile newFile; User::LeaveIfError(newFile.Open(iFs, tempFileName, EFileRead)); // KErrBusy means SISHelper didn't close! TInt expectedLength(0); oldFile.Seek(ESeekEnd,expectedLength); TInt actualLength(0); newFile.Seek(ESeekEnd,actualLength); if (expectedLength == actualLength) { TInt pos = 0; oldFile.Seek(ESeekStart, pos); newFile.Seek(ESeekStart, pos); SetTestStepResult(EPass); for (TInt i=0; i<expectedLength; i++) { TInt8 oldChar; TInt8 newChar; TPckg<TInt8> oldPkg(oldChar); TPckg<TInt8> newPkg(newChar); oldFile.Read(oldPkg); newFile.Read(newPkg); if (oldChar != newChar) { SetTestStepResult(EFail); break; } } } oldFile.Close(); newFile.Close(); RFs fs; User::LeaveIfError(fs.Connect()); // Delete the temp file TInt error = fs.Delete(tempFileName); if (error != KErrNone && error != KErrNotFound) { User::Leave(error); } fs.Close(); server.Close(); return TestStepResult(); }