memspy/Engine/Source/MemSpyEngineUtils.cpp
branchRCL_3
changeset 49 7fdc9a71d314
parent 44 52e343bb8f80
child 59 8ad140f3dd41
equal deleted inserted replaced
46:e26895079d7c 49:7fdc9a71d314
   272     }
   272     }
   273 
   273 
   274 
   274 
   275 EXPORT_C TMemSpyPercentText MemSpyEngineUtils::FormatPercentage( TReal aOneHundredPercentValue, TReal aValue )
   275 EXPORT_C TMemSpyPercentText MemSpyEngineUtils::FormatPercentage( TReal aOneHundredPercentValue, TReal aValue )
   276     {
   276     {
   277     const TReal value = (TInt) (( aValue / aOneHundredPercentValue) * 100.0);
   277     const TReal value = (( aValue / aOneHundredPercentValue) * 100.0);
   278     
   278     
   279     _LIT(KPercentFormat, "%3.2f %%");
   279     _LIT(KPercentFormat, "%3.2f %%");
   280 
   280 
   281     TMemSpyPercentText val;
   281     TMemSpyPercentText val;
   282     val.Format( KPercentFormat, value );
   282     val.Format( KPercentFormat, value );
   363 
   363 
   364 
   364 
   365 EXPORT_C void MemSpyEngineUtils::GetFolderL( RFs& aFsSession, TDes& aFolder, const CMemSpyEngineSinkMetaData& aMetaData, const TDriveNumber* aForceDrive )
   365 EXPORT_C void MemSpyEngineUtils::GetFolderL( RFs& aFsSession, TDes& aFolder, const CMemSpyEngineSinkMetaData& aMetaData, const TDriveNumber* aForceDrive )
   366     {
   366     {
   367     const TChar KMemSpyDirectorySeparator = '\\';
   367     const TChar KMemSpyDirectorySeparator = '\\';
       
   368     const TChar KMemSpyDriveSeparator = ':';
   368 
   369 
   369     TDriveList drives;
   370     TDriveList drives;
   370     User::LeaveIfError( aFsSession.DriveList( drives ) );
   371     User::LeaveIfError( aFsSession.DriveList( drives ) );
   371     
   372     
   372     // We prefer to log to MMC if its available. If not, we'll log to C: instead. On
   373     // We prefer to log to MMC if its available. If not, we'll log to C: instead. On
   377         logDrive = *aForceDrive;
   378         logDrive = *aForceDrive;
   378         TRACE( RDebug::Printf( "MemSpyEngineUtils::GetFolderL() - FORCED TO DRIVE: %c:\\", *aForceDrive + 'A' ) );
   379         TRACE( RDebug::Printf( "MemSpyEngineUtils::GetFolderL() - FORCED TO DRIVE: %c:\\", *aForceDrive + 'A' ) );
   379         }
   380         }
   380     else
   381     else
   381         {
   382         {
   382         logDrive = MemSpyEngineUtils::LocateSuitableDrive( aFsSession );
   383 		// check if drive is specified in root path
       
   384 		if ( aMetaData.Root().Length() > 2 && aMetaData.Root()[1] == KMemSpyDriveSeparator )
       
   385 			{
       
   386 			TChar drive = aMetaData.Root()[0];
       
   387 			
       
   388 			// check if drive is valid
       
   389 			if (drives.Locate(drive) != KErrNone)
       
   390 				{
       
   391 				TDriveUnit driveUnit( aMetaData.Root().Left(1) );
       
   392 				logDrive = static_cast<TDriveNumber>(static_cast<TInt>(driveUnit));
       
   393 				}
       
   394 			else
       
   395 				{
       
   396 				logDrive = MemSpyEngineUtils::LocateSuitableDrive( aFsSession );
       
   397 				}
       
   398 			}
       
   399 		else
       
   400 			{
       
   401 			logDrive = MemSpyEngineUtils::LocateSuitableDrive( aFsSession );
       
   402 			}
   383         }
   403         }
   384 
   404 
   385     // Prepare the drive buffer
   405     // Prepare the drive buffer
   386     HBufC* fileName = HBufC::NewLC( KMaxFileName * 2 );
   406     HBufC* fileName = HBufC::NewLC( KMaxFileName * 2 );
   387     TPtr pFileName( fileName->Des() );
   407     TPtr pFileName( fileName->Des() );
   388 
   408 
   389     // Prepare the drive name
   409     // Prepare the drive name
   390     TDriveUnit driveUnit( logDrive );
   410     TDriveUnit driveUnit( logDrive );
   391     pFileName.Append( driveUnit.Name() );
   411     pFileName.Append( driveUnit.Name() );
   392     pFileName.Append( KMemSpyLogRootPath );
   412     
       
   413     if ( aMetaData.Root().Length() == 0 )
       
   414     	{
       
   415 		pFileName.Append( KMemSpyLogRootPath );
       
   416     	}
       
   417     else
       
   418     	{
       
   419 		TPtrC root( aMetaData.Root() );
       
   420 		// check if root path contains drive (e.g. c:) and remove it
       
   421 		if ( root.Length() > 2 && root[1] == KMemSpyDriveSeparator )
       
   422 			{
       
   423 			root.Set( root.Mid( 2 ) );
       
   424 			}
       
   425 		// check if root starts with \ and remove it
       
   426 		if ( root.Length() > 1 && root[0] == KMemSpyDirectorySeparator )
       
   427 			{
       
   428 			root.Set( root.Mid( 1 ) );
       
   429 			}
       
   430 		
       
   431 		// append root path
       
   432 		pFileName.Append( KMemSpyDirectorySeparator );
       
   433 		pFileName.Append( root );
       
   434 		
       
   435 		// add trailing slash if necessary
       
   436 		if ( root[root.Length() - 1] != KMemSpyDirectorySeparator )
       
   437 			{
       
   438 			pFileName.Append( KMemSpyDirectorySeparator );
       
   439 			}
       
   440     	}
   393 
   441 
   394     // Add any custom folder information
   442     // Add any custom folder information
   395     if  ( aMetaData.Folder().Length() > 0 )
   443     if  ( aMetaData.Folder().Length() > 0 )
   396         {
   444         {
   397         pFileName.Append( aMetaData.Folder() );
   445         pFileName.Append( aMetaData.Folder() );