crashanalysercmd/Libraries/Engine/CrashItemLib/PluginAPI/FW/CFFFileList.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.Text;
       
    19 using System.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Reflection;
       
    22 using SymbianDebugLib.Engine;
       
    23 using CrashItemLib.Crash;
       
    24 using CrashItemLib.PluginAPI;
       
    25 using CrashItemLib.Engine.Sources;
       
    26 
       
    27 namespace CrashItemLib.PluginAPI
       
    28 {
       
    29     public class CFFFileList
       
    30     {
       
    31         #region Constructors
       
    32         internal CFFFileList()
       
    33         {
       
    34         }
       
    35 
       
    36         internal CFFFileList( DirectoryInfo aDir )
       
    37             : this( aDir, SearchOption.TopDirectoryOnly )
       
    38         {
       
    39         }
       
    40 
       
    41         internal CFFFileList( DirectoryInfo aDir, SearchOption aSearchOption )
       
    42 		{
       
    43             BuildLists( aDir, aSearchOption );
       
    44         }
       
    45 		#endregion
       
    46 
       
    47         #region API
       
    48         public void Clear()
       
    49         {
       
    50             iDictionary.Clear();
       
    51             iFiles.Clear();
       
    52         }
       
    53 
       
    54         public bool Contains( string aFileName )
       
    55         {
       
    56             string key = Key( aFileName );
       
    57             return iDictionary.ContainsKey( key );
       
    58         }
       
    59 
       
    60         public bool Contains( FileInfo aFile )
       
    61         {
       
    62             return Contains( aFile.FullName );
       
    63         }
       
    64 
       
    65         public void Remove( string aFileName )
       
    66         {
       
    67             string key = Key( aFileName );
       
    68             if ( iDictionary.ContainsKey( key ) )
       
    69             {
       
    70                 FileInfo file = iDictionary[ key ];
       
    71                 iFiles.Remove( file );
       
    72                 iDictionary.Remove( key );
       
    73             }
       
    74         }
       
    75 
       
    76         public void Remove( FileInfo aFile )
       
    77         {
       
    78             Remove( aFile.FullName );
       
    79         }
       
    80 
       
    81         public FileInfo Dequeue()
       
    82         {
       
    83             System.Diagnostics.Debug.Assert( Count > 0 );
       
    84             FileInfo ret = this[ 0 ];
       
    85             //
       
    86             iFiles.RemoveAt( 0 );
       
    87             iDictionary.Remove( Key( ret ) );
       
    88             //
       
    89             return ret;
       
    90         }
       
    91         #endregion
       
    92 
       
    93         #region Properties
       
    94         public int Count
       
    95         {
       
    96             get
       
    97             {
       
    98                 System.Diagnostics.Debug.Assert( iFiles.Count == iDictionary.Count );
       
    99                 return iFiles.Count;
       
   100             }
       
   101         }
       
   102 
       
   103         public bool IsEmpty
       
   104         {
       
   105             get { return Count == 0; }
       
   106         }
       
   107 
       
   108         public FileInfo this[ int aIndex ]
       
   109         {
       
   110             get { return iFiles[ aIndex ]; }
       
   111         }
       
   112         #endregion
       
   113 
       
   114         #region Internal methods
       
   115         private string Key( FileInfo aFile )
       
   116         {
       
   117             return Key( aFile.FullName );
       
   118         }
       
   119 
       
   120         private string Key( string aFileName )
       
   121         {
       
   122             return aFileName.ToUpper();
       
   123         }
       
   124 
       
   125         private void BuildLists( DirectoryInfo aDirectory, SearchOption aSearchOption )
       
   126         {
       
   127             Clear();
       
   128             //
       
   129             FileInfo[] files = aDirectory.GetFiles( "*.*", aSearchOption );
       
   130             iFiles.AddRange( files );
       
   131             //
       
   132             iDictionary = new Dictionary<string, FileInfo>();
       
   133             foreach ( FileInfo file in files )
       
   134             {
       
   135                 string key = file.FullName.ToUpper();
       
   136                 if ( iDictionary.ContainsKey( key ) )
       
   137                 {
       
   138                     iDictionary.Add( key, file );
       
   139                 }
       
   140             }
       
   141         }
       
   142         #endregion
       
   143 
       
   144         #region From System.Object
       
   145         #endregion
       
   146 
       
   147         #region Data members
       
   148         private List<FileInfo> iFiles = new List<FileInfo>();
       
   149         private Dictionary<string, FileInfo> iDictionary = new Dictionary<string, FileInfo>();
       
   150 		#endregion
       
   151     }
       
   152 }