crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianImageLib/E32Image/Image/SymbianE32Image.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 using System.IO;
       
    21 using SymbianUtils.Tracer;
       
    22 using SymbianUtils.Streams;
       
    23 using SymbianStructuresLib.Uids;
       
    24 using SymbianStructuresLib.Compression.Common;
       
    25 using SymbianImageLib.Common.Header;
       
    26 using SymbianImageLib.Common.Image;
       
    27 using SymbianImageLib.Common.Streams;
       
    28 using SymbianImageLib.E32Image.Content;
       
    29 using SymbianImageLib.E32Image.Header;
       
    30 using SymbianImageLib.E32Image.Exceptions;
       
    31 
       
    32 namespace SymbianImageLib.E32Image.Image
       
    33 {
       
    34     public class SymbianImageE32 : SIImage
       
    35     {
       
    36         #region Constructors
       
    37         public SymbianImageE32( FileInfo aFileInfo, ITracer aTracer )
       
    38             : this( aFileInfo.FullName, (uint) aFileInfo.Length, 0, new SIStream( aFileInfo.OpenRead() ), aTracer )
       
    39         {
       
    40         }
       
    41 
       
    42         internal SymbianImageE32( string aImageName, uint aImageContentSize, long aImageContentOffset, SIStream aStream, ITracer aTracer )
       
    43             : base( aTracer, aStream, aImageName )
       
    44         {
       
    45             iContentOffsetWithinDataStream = aImageContentOffset;
       
    46             //
       
    47             using ( SymbianStreamReaderLE reader = base.Stream.CreateReader() )
       
    48             {
       
    49                 reader.Seek( iContentOffsetWithinDataStream );
       
    50                 iHeader = new SIHeaderE32Image( this, reader );
       
    51             }
       
    52 
       
    53             // Since we are a single e32 image, we have a single e32 Image file descriptor
       
    54             SIContentE32Image file = new SIContentE32Image( this, aImageName, aImageContentSize, aImageContentOffset );
       
    55             base.RegisterFile( file );
       
    56         }
       
    57         #endregion
       
    58 
       
    59         #region From SIImage
       
    60         public override SIHeader Header
       
    61         {
       
    62             get { return iHeader; }
       
    63         }
       
    64         #endregion
       
    65 
       
    66         #region API
       
    67         public static bool IsImageFile( Stream aStream )
       
    68         {
       
    69             return IsImageFile( aStream, aStream.Position );
       
    70         }
       
    71         
       
    72         public static bool IsImageFile( Stream aStream, long aPosition )
       
    73         {
       
    74             bool ret = false;
       
    75             //
       
    76             try
       
    77             {
       
    78                 using ( SymbianStreamReaderLE reader = SymbianStreamReaderLE.New( aStream, SymbianStreamReaderLE.TCloseOperation.EResetPosition ) )
       
    79                 {
       
    80                     aStream.Seek( aPosition, SeekOrigin.Begin );
       
    81                     //
       
    82                     byte[] bytes = reader.ReadBytes( SIHeaderE32Image.KMinimumSize );
       
    83                     ret = SIHeaderE32Image.IsSymbianImageHeader( bytes );
       
    84                 }
       
    85             }
       
    86             catch ( Exception )
       
    87             {
       
    88             }
       
    89             return ret;
       
    90         }
       
    91         #endregion
       
    92 
       
    93         #region Properties
       
    94         internal TCheckedUid Uid
       
    95         {
       
    96             get
       
    97             {
       
    98                 return iHeader.Uid;
       
    99             }
       
   100         }
       
   101 
       
   102         internal long ContentOffsetWithinDataStream
       
   103         {
       
   104             get { return iContentOffsetWithinDataStream; }
       
   105         }
       
   106         #endregion
       
   107 
       
   108         #region Internal methods
       
   109         #endregion
       
   110 
       
   111         #region Data members
       
   112         private readonly SIHeaderE32Image iHeader;
       
   113         private readonly long iContentOffsetWithinDataStream;
       
   114         #endregion
       
   115     }
       
   116 }