crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/Mmp/MmpFileReader.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 
       
    21 namespace SymbianUtils.Mmp
       
    22 {
       
    23     public class MmpFileReader : AsyncTextFileReader
       
    24     {
       
    25         #region Constructor & destructor
       
    26         public MmpFileReader( string aFileName )
       
    27             : base( aFileName )
       
    28         {
       
    29             iFileInfo = new MmpFileInfo( aFileName );
       
    30         }
       
    31         #endregion
       
    32 
       
    33         #region API
       
    34         public void Read()
       
    35         {
       
    36             base.SyncRead();
       
    37         }
       
    38         #endregion
       
    39 
       
    40         #region Properties
       
    41         public MmpFileInfo FileInfo
       
    42         {
       
    43             get { return iFileInfo; }
       
    44         }
       
    45         #endregion
       
    46 
       
    47         #region Internal methods
       
    48         private string[] ExtractElements( string aLine )
       
    49         {
       
    50             List<string> ret = new List<string>();
       
    51             //
       
    52             string line = aLine.Trim();
       
    53             line = line.Replace( '\t', ' ' );
       
    54             //
       
    55             string[] elements = line.Split( new char[] { ' ' } );
       
    56             foreach ( string element in elements )
       
    57             {
       
    58                 if ( element.Length > 0 && element != " " )
       
    59                 {
       
    60                     ret.Add( element );
       
    61                 }
       
    62             }
       
    63             //
       
    64             return ret.ToArray();
       
    65         }
       
    66         #endregion
       
    67 
       
    68         #region From AsyncTextFileReader
       
    69         protected override void HandleFilteredLine( string aLine )
       
    70         {
       
    71             string[] elements = ExtractElements( aLine );
       
    72             //
       
    73             if ( elements.Length >= 2 )
       
    74             {
       
    75                 string line = elements[ 0 ].ToUpper();
       
    76                 //
       
    77                 if ( line == "TARGET" )
       
    78                 {
       
    79                     iFileInfo.Target = elements[ 1 ];
       
    80 
       
    81                     // Use extension as a means of guessing target type.
       
    82                     string extension = System.IO.Path.GetExtension( iFileInfo.Target ).ToUpper();
       
    83                     if ( extension == ".EXE" && iFileInfo.TargetType == MmpFileInfo.TTargetType.ETargetTypeUnsupported )
       
    84                     {
       
    85                         iFileInfo.TargetType = MmpFileInfo.TTargetType.ETargetTypeEXE;
       
    86                     }
       
    87                 }
       
    88                 else if ( line == "UID" )
       
    89                 {
       
    90                     for ( int i = 1; i < elements.Length; i++ )
       
    91                     {
       
    92                         try
       
    93                         {
       
    94                             string uidString = elements[ i ];
       
    95 
       
    96                             uint val = 0;
       
    97                             if ( uint.TryParse( uidString, out val ) )
       
    98                             {
       
    99                                 iFileInfo.Uids.Add( val );
       
   100                             }
       
   101                             else
       
   102                             {
       
   103                                 // Try again, skipping any possible leading 0x prefix and using
       
   104                                 // hex number formatting.
       
   105                                 if ( uidString.StartsWith( "0x" ) )
       
   106                                 {
       
   107                                     uidString = uidString.Substring( 2 );
       
   108                                     if ( uint.TryParse( uidString, System.Globalization.NumberStyles.HexNumber, null, out val ) )
       
   109                                     {
       
   110                                         iFileInfo.Uids.Add( val );
       
   111                                     }
       
   112                                 }
       
   113                             }
       
   114                         }
       
   115                         catch ( Exception )
       
   116                         {
       
   117                         }
       
   118                     }
       
   119                 }
       
   120                 else if ( line == "TARGETTYPE" )
       
   121                 {
       
   122                     // These are the only target types we need to support at the moment.
       
   123                     string targetType = elements[ 1 ].ToUpper();
       
   124                     //
       
   125                     if ( targetType == "EXE" )
       
   126                     {
       
   127                         iFileInfo.TargetType = MmpFileInfo.TTargetType.ETargetTypeEXE;
       
   128                     }
       
   129                     else if ( targetType == "EXEXP" )
       
   130                     {
       
   131                         iFileInfo.TargetType = MmpFileInfo.TTargetType.ETargetTypeEXE;
       
   132                     }
       
   133                     else if ( targetType == "DLL" )
       
   134                     {
       
   135                         iFileInfo.TargetType = MmpFileInfo.TTargetType.ETargetTypeDLL;
       
   136                     }
       
   137                 }
       
   138             }
       
   139         }
       
   140         #endregion
       
   141 
       
   142         #region Data members
       
   143         private readonly MmpFileInfo iFileInfo;
       
   144         #endregion
       
   145     }
       
   146 }