/** Write a file asynchronously in blocks of aBlockSize size @param fs RFs object @param aFileWrite RFile object, needs to exist beyond the scope of this function @param aFile File name @param aSize Size of the file in bytes @param aBlockSize Size of the blocks to be used in bytes @param aStatus TRequestStatus array for all the requests */ void WriteFileAsync(RFs& fs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aBlockSize, TRequestStatus aStatus[]) { TInt r = 0; TEST(aBlockSize > 0); // Block size must be greater than 0 r = aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite|EFileWriteDirectIO); TESTERROR(r); TInt j = 0; TInt i = 0; while(j < aSize) { if((aSize - j) >= aBlockSize) // All the blocks but the last one aFileWrite.Write(gBufWritePtr, aBlockSize, aStatus[i]); else // The last block aFileWrite.Write(gBufWritePtr, (aSize - j), aStatus[i]); TInt status = aStatus[i].Int(); if (status != KErrNone && status != KRequestPending) { test.Printf(_L("RFile::Write() returned %d\n"), aStatus[i].Int()); } test (status == KErrNone || status == KRequestPending); i++; j += aBlockSize; } }
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); }
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(); }
// 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(); }
void CRefTestAgentImportFile::DumpMetaData(const CMetaDataArray& aMetaDataArray) { _LIT(KMetaDataLogFile, "c:\\logs\\rta\\metadata"); _LIT(KExt, ".log"); TInt id(0); TInt err(KErrNone); TFileName filename; RFile file; do { filename.SetLength(0); filename.Append(KMetaDataLogFile); filename.AppendNum(++id); filename.Append(KExt); err = file.Create(iFs,filename,EFileWrite); } while(err == KErrAlreadyExists); if(err == KErrNone) { for(TInt i=0;i<aMetaDataArray.Count();i++) { file.Write(aMetaDataArray[i].Field8()); file.Write(_L8(" ")); file.Write(aMetaDataArray[i].Data8()); file.Write(_L8("\r\n")); } file.Close(); } }
void TestMessageCreateAttachmentL(const TDesC8& aMimeType, TUint aCharset) { RFile createdAttachment; CleanMailFolder(KMsvDraftEntryId); // Create a message. RSendAsMessage message; theUtils->WriteComment(_L("Create a message.")); message.CreateL(gSendAs, sendAsTestMtmUid); theUtils->WriteComment(_L("Create first attachment file.")); message.CreateAttachmentL(KCreatedAttachmentName1, createdAttachment, aMimeType, aCharset); // RFile should now be open on the new attachment. test(createdAttachment.Write(KAttachmentContent) == KErrNone); createdAttachment.Close(); theUtils->WriteComment(_L("Create second attachment file.")); message.CreateAttachmentL(KCreatedAttachmentName2, createdAttachment, aMimeType, aCharset); // RFile should now be open on the new attachment. test(createdAttachment.Write(KAttachmentContent) == KErrNone); createdAttachment.Close(); message.SaveMessageAndCloseL(); CheckNewAttachmentL(KCreatedAttachmentName1, 0, aMimeType, aCharset, EFalse); CheckNewAttachmentL(KCreatedAttachmentName2, 0, aMimeType, aCharset, EFalse); theUtils->Complete(); }
void CWmDrmDataStore::WriteInitialFreeSpaceL( const TDesC& aFileName, TBool& aConfiguredDrive ) { RFile file; TBuf8<KMaxTInt64BufLength + 2 * KAESKeyLength> encryptedData; TBuf8<KMaxTInt64BufLength + 2 * KAESKeyLength> decryptedData; TBuf8<KAESKeyLength> key; TBuf8<KAESKeyLength> iv; CBufferedEncryptor* encryptor = NULL; CModeCBCEncryptor* cbcEncryptor = NULL; CAESEncryptor* aesEncryptor = NULL; CPaddingPKCS7* padding = NULL; LOGFN( "CWmDrmDataStore::WriteInitialFreeSpaceL" ); User::LeaveIfError( file.Create( iServer->Fs(), aFileName, EFileWrite ) ); CleanupClosePushL( file ); if ( aConfiguredDrive ) { iInitialFreeSpace2 = iServer->FreeSpaceL( aConfiguredDrive ); } else { iInitialFreeSpace = iServer->FreeSpaceL( aConfiguredDrive ); } iv.SetLength( KAESKeyLength ); TRandom::RandomL( iv ); #if defined(FF_PLATFORM_SIMULATOR) || defined(__WINSCW__) key.Copy( KDummyKey ); #else iServer->Cache()->iKeyStorage->GetDeviceSpecificKeyL( key ); #endif aesEncryptor = CAESEncryptor::NewL( key ); CleanupStack::PushL( aesEncryptor ); cbcEncryptor = CModeCBCEncryptor::NewL( aesEncryptor, iv ); CleanupStack::Pop( aesEncryptor ); CleanupStack::PushL( cbcEncryptor ); padding = CPaddingPKCS7::NewL( KAESKeyLength ); CleanupStack::PushL( padding ); encryptor = CBufferedEncryptor::NewL( cbcEncryptor, padding ); CleanupStack::Pop( 2, cbcEncryptor ); //padding, cbcEncryptor CleanupStack::PushL( encryptor ); if ( aConfiguredDrive ) { decryptedData.AppendNum( iInitialFreeSpace2 ); } else { decryptedData.AppendNum( iInitialFreeSpace ); } encryptor->ProcessFinalL( decryptedData, encryptedData ); User::LeaveIfError( file.Write( iv ) ); User::LeaveIfError( file.Write( encryptedData ) ); CleanupStack::PopAndDestroy( 2, &file ); //encryptor, file }
void CRightsCriteriaCount::WriteDescription(RFile& aFile) { TBuf8 <10> count; count.Num(iCount); aFile.Write(_L8("Count = ")); aFile.Write(count); aFile.Write(_L8("\r\n")); }
// --------------------------------------------------------------------------------- // CUpnpTmServerDeviceXmlParser::OnStartDocumentL // Called when parser hits the start of the document // --------------------------------------------------------------------------------- // void CUpnpTmServerDeviceXmlParser::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt aErrorCode ) { OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTDOCUMENTL_ENTRY ); User::LeaveIfError(aErrorCode); TBuf<KMaxBufLength> tmpBuf(iDeviceDir); tmpBuf.Append(KDeviceName()); iDescFilePath.CreateL(tmpBuf); tmpBuf.Zero(); // Create TmAppServer service xml tmpBuf.Copy(iDeviceDir); tmpBuf.Append(KAppServerSrvName()); RFile appServerSrvFile; CleanupClosePushL(appServerSrvFile); TInt err(KErrNone); err = appServerSrvFile.Create(iFs, tmpBuf, EFileWrite); if ( err == KErrAlreadyExists ) { User::LeaveIfError(appServerSrvFile.Open(iFs, tmpBuf, EFileWrite)); } else { User::LeaveIfError(err); } User::LeaveIfError(appServerSrvFile.Write(iAppServerSrvDescription)); CleanupStack::PopAndDestroy( &appServerSrvFile ); iAppServerSrvFilePath.CreateL(tmpBuf); tmpBuf.Zero(); // Create TmClientProfile service xml tmpBuf.Copy(iDeviceDir); tmpBuf.Append(KClientProfSrvName()); RFile clientProfSrvFile; CleanupClosePushL(clientProfSrvFile); err = clientProfSrvFile.Create(iFs, tmpBuf, EFileWrite); if ( err == KErrAlreadyExists ) { User::LeaveIfError(clientProfSrvFile.Open(iFs, tmpBuf, EFileWrite)); } else { User::LeaveIfError(err); } User::LeaveIfError(clientProfSrvFile.Write(iClientProfSrvDescription)); CleanupStack::PopAndDestroy( &clientProfSrvFile ); iClientProfSrvFilePath.CreateL(tmpBuf); iDeviceDescription.Append(KStartLine()); iDescriptionUri.CreateMaxL(UpnpString::KDefaultStringLength); iDescriptionUri.SetLength(KErrNone); iDescriptionUri.Append(KScpdUrl()); iDescriptionUri.Append(KDeviceName()); OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTDOCUMENTL_EXIT ); }
void CVirtualFile::WriteDescriptor8L(RFile& aFile, const TDesC8& aBuffer) { // Write the length of the descriptor TInt length = aBuffer.Length(); TPckg<TInt> lengthPckg(length); User::LeaveIfError(aFile.Write(lengthPckg,lengthPckg.Length())); // write the data User::LeaveIfError(aFile.Write(aBuffer, length)); }
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 Parser::WriteSymbianHeaderL(RFile& aFile, TInt32& aUid1, TInt32& aUid2, TInt32& aUid3, TUint32& aUidCrc) { TPckg<TInt32> uid1Pckg(aUid1); User::LeaveIfError(aFile.Write(uid1Pckg)); TPckg<TInt32> uid2Pckg(aUid2); User::LeaveIfError(aFile.Write(uid2Pckg)); TPckg<TInt32> uid3Pckg(aUid3); User::LeaveIfError(aFile.Write(uid3Pckg)); TPckg<TUint32> uidCrcPckg(aUidCrc); User::LeaveIfError(aFile.Write(uidCrcPckg)); }
/** 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); } }
void CPolicyTest::WriteScriptFileL(const TDesC& aPath, const TDesC8& aAction) { iFs.Delete(aPath); // ignore errors RFile file; User::LeaveIfError(file.Create(iFs, aPath, EFileShareExclusive | EFileWrite)); CleanupClosePushL(file); User::LeaveIfError(file.Write(*iPreActions)); User::LeaveIfError(file.Write(aAction)); User::LeaveIfError(file.Write(*iPostActions)); CleanupStack::PopAndDestroy(&file); }
void CHttpTypes::SaveHttpTypesFileL(const TDesC& aFileName) const { RFs fs; RFile cfg; TBuf8<256> buffer; TInt len; User::LeaveIfError(fs.Connect()); User::LeaveIfError(cfg.Replace(fs,aFileName,EFileStreamText|EFileWrite)); len = iHttpTypesArray->Count(); for (TInt index = 0; index < len; index++) { // *NOTE* With wide build, Copy will do 16 -> 8 truncation // which should not cause problems, as type strings must be // plain ASCII anyway -- msa buffer.Copy((*iHttpTypesArray)[index]); buffer.Append('\n'); cfg.Write(buffer); } cfg.Close(); fs.Close(); }
void createVcardFileL(const TDesC8& aOrgLine, RFs& aFileSession) { RFile file; User::LeaveIfError(file.Replace(aFileSession, KVImportFileName, EFileWrite|EFileShareAny)); CleanupClosePushL(file); file.Write(KBegin); file.Write(KVersion); file.Write(KName); file.Write(aOrgLine); file.Write(KEnd); file.Flush(); CleanupStack::PopAndDestroy(); //file.Close() }
TInt LoadLogicalDriverL(RFs &fileSystem, const TDesC16 &lddName, i_status_notif* cb) { TInt ret; TUint val = 0x51000000U; TPtr8 bufPtr((unsigned char *)&val, 4, 4); TInt flag = 0; TInt cnt = 0; RFile ldd; do { ret = User::LoadLogicalDevice(lddName); if(ret == KErrNotSupported) { cb->error(_L("KErrNotSupported")); ldd.Open(fileSystem, lddName, EFileWrite); ldd.Write(0x48, bufPtr); cnt++; val += 0x40000; ldd.Close(); } else if(ret == KErrNone || ret == KErrAlreadyExists) flag = 1; else User::Leave(ret); } while(!flag && val != 0x51000000U); if(ret == KErrAlreadyExists) cb->error(_L("KErrAlreadyExists")); return cnt; }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0612 @SYMTestCaseDesc Database validity test @SYMTestPriority Medium @SYMTestActions Tests for opening and closing of database @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestOpenL() { _LIT(KFileNotFound,"not a database"); TInt r=TheDatabase.Open(TheFs,KFileNotFound); test (r==KErrNotFound || r==KErrPathNotFound); // _LIT(KPathNotFound,"C:\\not a path\\database.db"); r=TheDatabase.Open(TheFs,KPathNotFound); test (r==KErrPathNotFound); // _LIT(KNotFormat,"not.a.dbx"); r=TheDatabase.Open(TheFs,KFileNotFound,KNotFormat); test (r==KErrNotFound || r==KErrPathNotFound); // DbCreateL(); TheDatabase.Close(); r=TheDatabase.Open(TheFs,KTestDatabase,TUid::Uid(0x01234567).Name()); test (r==KErrNone); // New code has no loadable drivers, it is irrelevant to expect error here TheDatabase.Close(); // We have added it here because previous statement does not return error anymore // RFile f; r=f.Replace(TheFs,KTestDatabase,EFileWrite); test (r==KErrNone); TCheckedUid type(KDirectFileStoreLayoutUid); r=f.Write(type.Des()); test (r==KErrNone); f.Close(); r=TheDatabase.Open(TheFs,KTestDatabase); test (r==KErrNotSupported); // _LIT(KDefaultFormat,"epoc"); r=TheDatabase.Open(TheFs,KTestDatabase,KDefaultFormat); test (r==KErrNotSupported); // We expect not supported db here }
LOCAL_C void Test1() { // Basic clamp operation test.Next(_L("T_DENYCLAMP - Test1()")); TBuf<256> fileName; TBuf<256> buf(_L("buffer for file used")); fileName = _L("clampFile.tst"); RFile testFile; TInt r=testFile.Replace(TheFs,fileName,EFileWrite); test(r==KErrNone); TPtrC8 pBuf((TUint8*)&buf); testFile.Write(pBuf); testFile.Flush(); // Attempt to clamp file should be rejected RFileClamp handle; r=handle.Clamp(testFile); test(r==KErrPermissionDenied); // Attempt to unclamp a file should be rejected // Using an invalid-content cookie is OK - the request should // be rejected before the content is examined handle.iCookie[0]=MAKE_TINT64(-1,-1); handle.iCookie[1]=0; r=handle.Close(TheFs); test (r==KErrPermissionDenied); // Tidy up testFile.Close(); r=TheFs.Delete(_L("clampFile.tst")); test (r==KErrNone); }
// Actual implementation of method TInt CMMFAacDecoderConfig::SetAudioConfig(TAudioConfig& aAudioConfig) { RFs fs; RFile file; TInt err = KErrNone; if ( KErrNone != (err = fs.Connect()) ) { return err; } // this file name will be use on the testStep to compare the stored value. _LIT(KFileName, "c:\\temp\\aacDecoderConfig.txt"); fs.MkDirAll(KFileName); if ( KErrNone != (err = file.Replace(fs, KFileName, EFileWrite)) ) { return err; } TBuf8<4> Line; Line.Format(_L8("%02d"), aAudioConfig.iAudioObjectType); file.Write(Line); file.Close(); fs.Close(); return err; }
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 CIpsPlgMessagePartStorerOperation::StoreTextHtmlPartL( CFSMailMessagePart* aPart) { User::LeaveIfNull(aPart); // Text buffer for html text content HBufC* data16 = aPart->GetLocalTextContentLC(); // Convert from 16 to 8 bit data - data must exist until request is completed iDataBuffer = HBufC8::NewL((data16->Length() * 2) + 1); TPtr8 ptr8(iDataBuffer->Des()); CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, *data16); // Get text/html part file for write RFile file = aPart->GetContentFileL(ETrue); CleanupClosePushL(file); // if we don't do SetSize(0) characters from the original mail are left in the end of the mail // if the modified mail contains less characters. User::LeaveIfError( file.SetSize( 0 ) ); // Write new content to text/html part file - async function file.Write( 0, *iDataBuffer, iDataBuffer->Length(), iStatus ); CleanupStack::PopAndDestroy(2, data16); SetActive(); }
//write received class0sms data to file void CClass0SmsTxtNotifier::CreateFile(const TDesC8& aBuff) { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TInt startPos, endPos; TBool isLastMessage = EFalse; RDesReadStream readStream(aBuff); CleanupClosePushL (readStream); startPos = readStream.ReadInt32L(); endPos = readStream.ReadInt32L(); isLastMessage = readStream.ReadInt32L(); TBuf<1000> smsMsg1; readStream >> smsMsg1; RFile file; TPtrC8 smsMsg(REINTERPRET_CAST(const TUint8*, smsMsg1.Ptr()), smsMsg1.Size()); User::LeaveIfError(file.Replace(fs, KTestClas0Sms, EFileShareAny | EFileWrite)); file.Write(smsMsg); file.Close(); CleanupStack::PopAndDestroy(&readStream); CleanupStack::PopAndDestroy(&fs); }
TInt CopyFile(const TDesC& aSource, const TDesC& aTarget) { RFile file; TInt ret=file.Open(TheFs,aSource,EFileRead); if (ret!=KErrNone) return ret; TInt fileSize; file.Size(fileSize); HBufC8* buf=HBufC8::New(fileSize); if (!buf) { file.Close(); return KErrNoMemory; } TPtr8 mod(buf->Des()); file.Read(mod); file.Close(); ret=file.Replace(TheFs,aTarget,EFileWrite); if (ret==KErrNone) { file.Write(*buf); } file.Close(); delete buf; return ret; }
// ----------------------------------------------------------------------------- // CLibxml2Tester::CompressBufferGZIPL // test GZIP Compress to buffer // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::CompressBufferGZIPL(CStifItemParser& aItem) { _LIT(tem,"Error in code"); // resize heap he = UserHeap::ChunkHeap(&KNullDesC(), 0, 20000000); if(!he) { User::Leave(100); } oldHeap = User::SwitchHeap(he);// Change heaps cleanup=CTrapCleanup::New(); //-- TInt trapResult; // start trap TRAP(trapResult, TPtrC pInput; aItem.GetNextString( pInput ); TPtrC pOutput; aItem.GetNextString( pOutput ); HBufC8* bufferOutput = CnvUtfConverter::ConvertFromUnicodeToUtf8L(pOutput); CleanupStack::PushL( bufferOutput ); TPtr8 pOutput8 = bufferOutput->Des(); HBufC8* buffer = ReadFileToBufferL( pInput ); CleanupStack::PushL( buffer ); // CVtcpBufferManager::NewL( in.Ptr() ,in.Length()); CTestBufferManager* bm = CTestBufferManager::NewLC( buffer->Ptr(), buffer->Size() ); CEZCompressor* compressor = CEZCompressor::NewLC( *bm ); // decompressor->DecompressL( pOutput8, buffer->Des() ); while ( compressor->DeflateL() ) { /* empty */ } TPtrC8 out=bm->OutputData(); RFs aRFs; User::LeaveIfError(aRFs.Connect()); CleanupClosePushL(aRFs); RFile fOut; User::LeaveIfError ( fOut.Replace( aRFs, pOutput, EFileWrite ) ); CleanupClosePushL( fOut ); User::LeaveIfError ( fOut.Write(out ) ); //WriteFileFromBufferL(pOutput,out) CleanupStack::PopAndDestroy( 6 ); );
void CRuleManager::WriteFavToFile() { TFileName filename; GetAppPath(filename); filename.Append(KFavRuleFile); int pos = filename.LocateReverse('\\'); if (pos != KErrNotFound) { TPtrC dirName = filename.Left(pos + 1); CCoeEnv::Static()->FsSession().MkDirAll(dirName); } RFile file; TInt err; err = file.Replace(CCoeEnv::Static()->FsSession(), filename, EFileWrite); if (KErrNone != err) { return; } CleanupClosePushL(file); WriteToFile(file,iFavRule); TBuf8<4> num; num.AppendNum(iFavRule->GetFavCount()); file.Write(num); CleanupStack::PopAndDestroy(); // file }
long RudeRegistrySymbian::SetByte(TCHAR *app, TCHAR *name, void *buffer, long buffersize) { TInt err; RudeDebug *debug = RudeDebug::GetInstance(); _LIT(KMyFile,"\\system\\Apps\\VectorBlaster\\file.txt"); RFile myFile; err = myFile.Open(CEikonEnv::Static()->FsSession(), KMyFile, EFileWrite); debug->Print(_T("myFile.Open"), err); if(err == KErrNotFound) { err = myFile.Create(CEikonEnv::Static()->FsSession(), KMyFile, EFileWrite); debug->Print(_T("myFile.Create"), err); } if(err != KErrNone) return err; _LIT8(KWriteBuf,"write data"); myFile.Write(KWriteBuf); myFile.Close(); debug->Print(_T("myFile.Close")); return 0; }
void CEdgedWin::DumpDetails(RFile& aFile, TInt aDepth) { TBuf8<256> buf; buf.SetLength(0); for (TInt d = 0; d < aDepth; ++d) { buf.Append(_L8(" ")); } buf.Append(_L8("Transparent = [")); buf.AppendNum((TInt64)iTransparent); buf.Append(_L8("] randomize_alpha = [")); buf.AppendNum((TInt64)iRandomizeAlpha); buf.Append(_L8("] pen_style = [")); buf.AppendNum((TInt64)iPenStyle); buf.Append(_L8("] brush_style = [")); buf.AppendNum((TInt64)iBrushStyle); buf.Append(_L8("] transFgColor = [")); buf.AppendNum(iTransFgColor.Value()); buf.Append(_L8("] transBgColor = [")); buf.AppendNum(iTransBgColor.Value()); buf.Append(_L8("] FgColor = [")); buf.AppendNum(iFgColor.Value()); buf.Append(_L8("] BgColor = [")); buf.AppendNum(iBgColor.Value()); buf.Append(_L8("]\r\n")); aFile.Write(buf); }
/** @SYMTestCaseID SYSLIB-STORE-CT-3350 @SYMTestCaseDesc Direct file store verification test @SYMTestPriority High @SYMTestActions Open a corrupted direct store file @SYMTestExpectedResults the function called leaves with KErrNotSupported @SYMDEF DEF100757 */ LOCAL_C void DirectFileL() { Test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-3350 Creating Direct File Store ")); TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive())); TParse parse; parse.Set(drive.Name(), &KTestDirectFileName, NULL); // create a direct file store TheStore=CDirectFileStore::ReplaceLC(TheFs,parse.FullName(),EFileWrite); TheStore->SetTypeL(TheStore->Layout()); TInt8 val=100; TStreamId id=TheSink.CreateL(*TheStore); TheSink<<val; TheSink.Close(); TheStore->SetRootL(id); TheStore->CommitL(); CleanupStack::PopAndDestroy(TheStore); // corrupt the store file RFile file; User::LeaveIfError(file.Open(TheFs,parse.FullName(),EFileWrite)); CleanupClosePushL(file); User::LeaveIfError(file.Write(KTestJunkData,sizeof(TCheckedUid))); CleanupStack::PopAndDestroy(&file); // the CDirectFileStore::OpenLC should leave if passed the corrupted store file name TheStore = NULL; TRAPD(r, \ {\ TheStore=CDirectFileStore::OpenLC(TheFs,parse.FullName(),EFileRead);\ CleanupStack::PopAndDestroy(TheStore); \ }\ );
TVerdict CDumpDrmArchive::doTestStepL() { // SetTestStepResult(EInconclusive) is a bad idea. // It makes the TEST macroes unusable. TPtrC fileName; TPtrC outputPath; GetStringFromConfig(ConfigSection(),_L("Filename"),fileName); GetStringFromConfig(ConfigSection(),_L("outputpath"),outputPath); __UHEAP_MARK; INFO_PRINTF2(_L("Reading DRM archive: %S "), &fileName); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API RFile64 file; #else RFile file; #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API User::LeaveIfError(file.Open(fs, fileName, EFileRead | EFileStream | EFileShareReadersOnly)); CleanupClosePushL(file); CRefTestAgentArchive* archive = CRefTestAgentArchive::NewL(file); CleanupStack::PushL(archive); TBuf <256> mimeType; mimeType.Copy(archive->DefaultMimeType()); INFO_PRINTF2(_L("Default Mime Type : %S "), &mimeType); CDrmFiles& drmFiles = archive->DrmFilesL(); // enhance this later // just dump out the default content object CDrmFileContent& defaultContent = drmFiles.FindL(KDefaultContentObject()); TBuf8 <1024> buffer; TInt length = 1024; TFileName outputFileName; outputFileName.Copy(outputPath); outputFileName.Append(_L("output.txt")); RFile outputFile; User::LeaveIfError(outputFile.Create(fs, outputFileName, EFileWrite | EFileStream | EFileShareAny)); CleanupClosePushL(outputFile); while(length > 0) { User::LeaveIfError(defaultContent.Read(buffer, buffer.MaxLength())); length = buffer.Length(); User::LeaveIfError(outputFile.Write(buffer)); } CleanupStack::PopAndDestroy(4, &fs); // fs, file, archive, outputFile __UHEAP_MARKEND; return TestStepResult(); }