void Cdmatest::SaveMappingsL()
    {
	TInt c( iMappingTable.Count() );
	if ( c > 0 )
	{
    	RFs fs;
    	User::LeaveIfError( fs.Connect() );
    	CleanupClosePushL( fs );
    	RFileWriteStream buf;
    	User::LeaveIfError( buf.Replace( fs, KMappingTableFile, EFileWrite ) );
    	CleanupClosePushL( buf );
		
		TInt i( 0 ) ;
		do 
			{
			buf.WriteUint32L( iMappingTable[i].iURI.Length() );
			buf.WriteL( iMappingTable[i].iURI );
			buf.WriteUint32L( iMappingTable[i].iLuid.Length() );
			buf.WriteL( iMappingTable[i].iLuid );
			}
		while ( ++i < c )	;
		buf.CommitL();
		buf.Close();
	
		CleanupStack::PopAndDestroy(); // buf
		CleanupStack::PopAndDestroy(); // fs
		}
    }
Exemple #2
0
void CApaAppListServer::ExternalizeNonNativeApplicationTypeArrayL(TInt aIndexToIgnore/*=-1*/) const
	{
	RFs& fs=const_cast<RFs&>(iFs);
	fs.MkDirAll(iNonNativeApplicationTypeRegistry); // ignore any error
	RFile file;
	CleanupClosePushL(file);
	User::LeaveIfError(file.Replace(fs, iNonNativeApplicationTypeRegistry, EFileShareExclusive|EFileStream|EFileWrite));
	RFileWriteStream targetStream;
	targetStream.Attach(file); // 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);
	const TInt arrayCount(iNonNativeApplicationTypeArray.Count());
	TInt arrayCountToExternalize=arrayCount;
	if (aIndexToIgnore>=0)
		{
		--arrayCountToExternalize;
		}
	TCardinality(arrayCountToExternalize).ExternalizeL(targetStream);
	for (TInt i=0; i<arrayCount; ++i)
		{
		if (i!=aIndexToIgnore)
			{
			const SNonNativeApplicationType& nonNativeApplicationType=iNonNativeApplicationTypeArray[i];
			targetStream.WriteUint32L(nonNativeApplicationType.iTypeUid.iUid);
			targetStream << *nonNativeApplicationType.iNativeExecutable;
			}
		}
	targetStream.CommitL();
	CleanupStack::PopAndDestroy(2, &file);
	}
// ---------------------------------------------------------------------------
// 
// ---------------------------------------------------------------------------
//    
void CNcdProviderUtils::WriteDatabaseVersionsL(
    const TDesC& aRootPath,
    TUint32 aGeneralVersion,
    TUint32 aPurchaseHistoryVersion )
    {
    DLTRACEIN(("Writing versions, general: %d, purchase history: %d",
        aGeneralVersion, aPurchaseHistoryVersion ));

    RBuf path;
    
    AppendPathsLC( 
        path, 
        aRootPath, 
        NcdProviderDefines::KNcdDatabaseVersionFile );
        
    RFileWriteStream stream;
    CleanupClosePushL( stream );
    User::LeaveIfError( stream.Replace( FileSession(),
        path, EFileWrite ) );
    stream.WriteUint32L( aGeneralVersion );
    stream.WriteUint32L( aPurchaseHistoryVersion );
    CleanupStack::PopAndDestroy( 2, &path );
    DLTRACEOUT(("Versions successfully written"));
    }
// ---------------------------------------------------------------------------
// Write the file to correct directory.
// ---------------------------------------------------------------------------
//
EXPORT_C void CXIMPTestFileTool::PluginStoreL( const TDesC8& aExternalizedObject )
    {
    HBufC* fileName = GetFileNameLC( 
            KFileToolPluginDirBase,
            iObjIndex );

    RFileWriteStream out;
    CleanupClosePushL( out );
    out.Create( iFs, *fileName, EFileWrite|EFileStream|EFileShareAny );

    // write the file
    TUint32 len = aExternalizedObject.Length();
    out.WriteUint32L( len );
    out.WriteL( aExternalizedObject );
    CleanupStack::PopAndDestroy(); // out

    CleanupStack::PopAndDestroy( fileName ); // fileName

    // next file will have a new index
    iObjIndex++;
    }
// ---------------------------------------------------------------------------
// CLbtCleanupHandler::WriteCleanupDataToFileL
// ---------------------------------------------------------------------------
//
void CLbtCleanupHandler::WriteCleanupDataToFileL()
	{
	FUNC_ENTER("CLbtCleanupHandler::WriteCleanupDataToFileL");	
	
	RFs fs;
	User::LeaveIfError( fs.Connect() );
	
	CleanupClosePushL( fs );
    
    // Obtain the file path
    TFileName file;
    
    // Gets the path in which the file can be created
    fs.SessionPath(file);

    // Create the file Directory ie the private directory of the process
    fs.MkDirAll(file);
    
    // Append the name of the file
    file.Append(KLbtAppCleanupFileName);
    
    // Open write stream to write to the file
    RFileWriteStream writeStream;
    
    // Open the file to replace the contents. If the file is not preset
    // this method will create the file
    TInt error = writeStream.Replace( fs, file, EFileWrite );    
    if( error != KErrNone )
    	{
    	ERROR("Opening of cleanup file failed with : %d", error);
    	writeStream.Close();
    	CleanupStack::PopAndDestroy(); //fs
    	User::Leave(error);
    	}
    CleanupClosePushL( writeStream );
    
    // First write the number of cleanup items
    writeStream.WriteInt16L( iCleanupItems.Count() );

	for(TInt i=0;i<iCleanupItems.Count();++i)
		{
		RArray<TLbtTriggerId>& triggers = iCleanupItems[i]->GetTriggers();
		
		// Write the trigger ids into the file
		writeStream.WriteInt16L( triggers.Count() );
		for(TInt j=0;j<triggers.Count();++j)
			{
			writeStream.WriteUint32L( triggers[j] );
			}
		
		// Write the time into the file
		const TDateTime dateTime = iCleanupItems[i]->GetTime().DateTime();
		
		// Write the year
		writeStream.WriteInt32L( dateTime.Year() );
		
		// Write the month
		writeStream.WriteInt32L( dateTime.Month() );
		
		// Write the day
		writeStream.WriteInt32L( dateTime.Day() );
		}
    
    CleanupStack::PopAndDestroy(2); //fs and writeSteam    
	}