crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/Environment/EnvEntryBase.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;
       
    19 using System.IO;
       
    20 using System.Text;
       
    21 
       
    22 namespace SymbianUtils.Environment
       
    23 {
       
    24     public abstract class EnvEntryBase
       
    25     {
       
    26         #region Static factory function
       
    27         internal static EnvEntryBase New( DriveInfo aDriveInfo )
       
    28         {
       
    29             bool valid;
       
    30             //
       
    31             EnvEntryBase ret = new EnvEntry( aDriveInfo, out valid );
       
    32             if ( valid == false )
       
    33             {
       
    34                 ret = new EnvEntryNull();
       
    35             }
       
    36             return ret;
       
    37         }
       
    38         #endregion
       
    39 
       
    40         #region Constructors
       
    41         protected EnvEntryBase( DriveInfo aDriveInfo )
       
    42         {
       
    43             iDriveInfo = aDriveInfo;
       
    44         }
       
    45         #endregion
       
    46 
       
    47         #region API
       
    48         public string CombineWithFile( string aFileName )
       
    49         {
       
    50             string ret = aFileName;
       
    51             //
       
    52             if ( iDriveInfo != null )
       
    53             {
       
    54                 string drive = DriveName;
       
    55 
       
    56                 if ( aFileName.Length > 2 )
       
    57                 {
       
    58                     bool isDrive = aFileName[ 1 ] == ':';
       
    59                     if ( isDrive )
       
    60                     {
       
    61                         // Remove drive before combining with environment drive
       
    62                         aFileName = aFileName.Substring( 2 );
       
    63                     }
       
    64 
       
    65                     // Strip trailing backslash from drive name if already part
       
    66                     // of file name prefix
       
    67                     if ( aFileName.StartsWith( "\\" ) && drive.EndsWith( "\\" ) )
       
    68                     {
       
    69                         drive = drive.Substring( 0, drive.Length - 1 );
       
    70                     }
       
    71                 }
       
    72 
       
    73                 ret = drive + aFileName;
       
    74             }
       
    75             //
       
    76             return ret;
       
    77         }
       
    78         #endregion
       
    79 
       
    80         #region Properties
       
    81         public bool IsValid
       
    82         {
       
    83             get
       
    84             {
       
    85                 bool ret = ( iDriveInfo != null ) && ( string.IsNullOrEmpty( iVersionStringSymbian ) == false );
       
    86                 return ret;
       
    87             }
       
    88         }
       
    89 
       
    90         public DriveInfo DriveInfo
       
    91         {
       
    92             get { return iDriveInfo; }
       
    93         }
       
    94 
       
    95         public string DriveName
       
    96         {
       
    97             get
       
    98             {
       
    99                 string ret = string.Empty;
       
   100                 if ( iDriveInfo != null )
       
   101                 {
       
   102                     ret = iDriveInfo.Name;
       
   103                 }
       
   104                 return ret;
       
   105             }
       
   106         }
       
   107 
       
   108         public string VolumeName
       
   109         {
       
   110             get
       
   111             {
       
   112                 string ret = string.Empty;
       
   113                 if ( iDriveInfo != null )
       
   114                 {
       
   115                     ret = string.Format( "[ {0} ]", iDriveInfo.VolumeLabel );
       
   116                 }
       
   117                 return ret;
       
   118             }
       
   119         }
       
   120 
       
   121         public string VersionStringSymbian
       
   122         {
       
   123             get { return iVersionStringSymbian; }
       
   124             protected set { iVersionStringSymbian = value; }
       
   125         }
       
   126 
       
   127         public string VersionStringS60
       
   128         {
       
   129             get { return iVersionStringS60; }
       
   130             protected set { iVersionStringS60 = value; }
       
   131         }
       
   132 
       
   133         public bool IsS60Environment
       
   134         {
       
   135             get { return string.IsNullOrEmpty( iVersionStringS60 ) == false; }
       
   136         }
       
   137         #endregion
       
   138 
       
   139         #region From System.Object
       
   140         public override string ToString()
       
   141         {
       
   142             StringBuilder ret = new StringBuilder();
       
   143             ret.Append( DriveName );
       
   144             ret.Append( " " );
       
   145             ret.Append( VolumeName );
       
   146             ret.Append( " " );
       
   147 
       
   148             // Try to use S60 version string if we have it...
       
   149             if ( VersionStringS60.Length > 0 )
       
   150             {
       
   151                 ret.Append( VersionStringS60 );
       
   152             }
       
   153             else
       
   154             {
       
   155                 ret.Append( VersionStringSymbian );
       
   156             }
       
   157             //
       
   158             return ret.ToString();
       
   159         }
       
   160         #endregion
       
   161 
       
   162         #region Data members
       
   163         private readonly DriveInfo iDriveInfo;
       
   164         private string iVersionStringSymbian = string.Empty;
       
   165         private string iVersionStringS60 = string.Empty;
       
   166         #endregion
       
   167     }
       
   168 }