|
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 |
|
22 namespace SymbianUtils.FileSystem |
|
23 { |
|
24 public class FSExtensionList : IEnumerable<FSExtensionDescriptor> |
|
25 { |
|
26 #region Constructors |
|
27 public FSExtensionList() |
|
28 { |
|
29 } |
|
30 #endregion |
|
31 |
|
32 #region API |
|
33 public void Clear() |
|
34 { |
|
35 iEntries.Clear(); |
|
36 } |
|
37 |
|
38 public void Add( string aExtension, string aDescription ) |
|
39 { |
|
40 Add( new FSExtensionDescriptor( aExtension, aDescription ) ); |
|
41 } |
|
42 |
|
43 public void Add( FSExtensionDescriptor aEntry ) |
|
44 { |
|
45 if ( !Contains( aEntry ) ) |
|
46 { |
|
47 iEntries.Add( aEntry.GetHashCode(), aEntry ); |
|
48 } |
|
49 } |
|
50 |
|
51 public void AddRange( IEnumerable<FSExtensionDescriptor> aEntries ) |
|
52 { |
|
53 foreach ( FSExtensionDescriptor entry in aEntries ) |
|
54 { |
|
55 Add( entry ); |
|
56 } |
|
57 } |
|
58 |
|
59 public bool Contains( string aExtension ) |
|
60 { |
|
61 bool ret = false; |
|
62 // |
|
63 foreach ( FSExtensionDescriptor entry in this ) |
|
64 { |
|
65 if ( entry.ContainsExtension( aExtension ) ) |
|
66 { |
|
67 ret = true; |
|
68 break; |
|
69 } |
|
70 } |
|
71 // |
|
72 return ret; |
|
73 } |
|
74 |
|
75 public bool Contains( FSExtensionDescriptor aEntry ) |
|
76 { |
|
77 bool ret = iEntries.ContainsKey( aEntry.GetHashCode() ); |
|
78 return ret; |
|
79 } |
|
80 #endregion |
|
81 |
|
82 #region Properties |
|
83 public int Count |
|
84 { |
|
85 get { return iEntries.Count; } |
|
86 } |
|
87 |
|
88 public FSExtensionDescriptor this[ int aIndex ] |
|
89 { |
|
90 get { return iEntries[ aIndex ]; } |
|
91 } |
|
92 |
|
93 public FSExtensionDescriptor this[ string aExtension ] |
|
94 { |
|
95 get |
|
96 { |
|
97 FSExtensionDescriptor ret = null; |
|
98 // |
|
99 if ( Contains( aExtension ) ) |
|
100 { |
|
101 FSExtensionDescriptor temp = new FSExtensionDescriptor( aExtension ); |
|
102 ret = iEntries[ temp.GetHashCode() ]; |
|
103 } |
|
104 // |
|
105 return ret; |
|
106 } |
|
107 } |
|
108 #endregion |
|
109 |
|
110 #region Internal methods |
|
111 #endregion |
|
112 |
|
113 #region From System.Object |
|
114 public override string ToString() |
|
115 { |
|
116 // Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.* |
|
117 StringBuilder ret = new StringBuilder(); |
|
118 |
|
119 foreach ( FSExtensionDescriptor ext in this ) |
|
120 { |
|
121 string extString = ext.ToString(); |
|
122 ret.AppendFormat( "{0};", extString ); |
|
123 } |
|
124 |
|
125 // Add "all files" |
|
126 ret.Append( "All Files (*.*)|*.*" ); |
|
127 |
|
128 return ret.ToString(); |
|
129 } |
|
130 #endregion |
|
131 |
|
132 #region From IEnumerable<FSExtensionDescriptor> |
|
133 public IEnumerator<FSExtensionDescriptor> GetEnumerator() |
|
134 { |
|
135 foreach ( KeyValuePair<int, FSExtensionDescriptor> kvp in iEntries ) |
|
136 { |
|
137 yield return kvp.Value; |
|
138 } |
|
139 } |
|
140 |
|
141 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
142 { |
|
143 foreach ( KeyValuePair<int, FSExtensionDescriptor> kvp in iEntries ) |
|
144 { |
|
145 yield return kvp.Value; |
|
146 } |
|
147 } |
|
148 #endregion |
|
149 |
|
150 #region Data members |
|
151 private SortedList<int, FSExtensionDescriptor> iEntries = new SortedList<int, FSExtensionDescriptor>(); |
|
152 #endregion |
|
153 } |
|
154 } |