|
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.IO; |
|
19 using System.Text; |
|
20 using System.Collections.Generic; |
|
21 using SymbianUtils; |
|
22 |
|
23 namespace SymbianStructuresLib.Debug.Common.FileName |
|
24 { |
|
25 public class PlatformFileName |
|
26 { |
|
27 #region Static constructor |
|
28 public static PlatformFileName New( PlatformFileName aCopy ) |
|
29 { |
|
30 PlatformFileName ret = new PlatformFileName(); |
|
31 ret.FileNameInDevice = aCopy.FileNameInDevice; |
|
32 ret.FileNameInHost = aCopy.FileNameInHost; |
|
33 return ret; |
|
34 } |
|
35 |
|
36 public static PlatformFileName NewByHostName( string aFileName ) |
|
37 { |
|
38 PlatformFileName ret = new PlatformFileName(); |
|
39 |
|
40 ret.FileNameInHost = aFileName; |
|
41 |
|
42 // Seed the device file name based upon the host info |
|
43 string justFileName = Path.GetFileName( aFileName ); |
|
44 ret.FileNameInDevice = Path.Combine( PlatformFileNameConstants.Device.KPathWildcardSysBin, justFileName ); |
|
45 |
|
46 return ret; |
|
47 } |
|
48 |
|
49 public static PlatformFileName NewByDeviceName( string aFileName ) |
|
50 { |
|
51 PlatformFileName ret = new PlatformFileName(); |
|
52 |
|
53 ret.FileNameInDevice = aFileName; |
|
54 |
|
55 // Seed the device file name based upon the host info |
|
56 string justFileName = Path.GetFileName( ret.FileNameInDevice ); |
|
57 ret.FileNameInHost = Path.Combine( PlatformFileNameConstants.Host.KPathEpoc32ReleaseArmv5Urel, justFileName ); |
|
58 |
|
59 return ret; |
|
60 } |
|
61 #endregion |
|
62 |
|
63 #region Constructors |
|
64 private PlatformFileName() |
|
65 { |
|
66 } |
|
67 #endregion |
|
68 |
|
69 #region API |
|
70 public bool Contains( string aText ) |
|
71 { |
|
72 string text = aText.ToUpper(); |
|
73 bool ret = iFileNameInDevice.ToUpper().Contains( text ) || |
|
74 iFileNameInHost.ToUpper().Contains( text ); |
|
75 return ret; |
|
76 } |
|
77 #endregion |
|
78 |
|
79 #region Properties |
|
80 public bool ContainsWildcard |
|
81 { |
|
82 get { return iFileNameInDevice.StartsWith( PlatformFileNameConstants.Device.KPathWildcardRoot ); } |
|
83 } |
|
84 |
|
85 public string EitherFullNameButDevicePreferred |
|
86 { |
|
87 get |
|
88 { |
|
89 // Prefer the in-device file name if possible |
|
90 string ret = iFileNameInDevice; |
|
91 // |
|
92 if ( string.IsNullOrEmpty( ret ) ) |
|
93 { |
|
94 ret = iFileNameInHost; |
|
95 if ( string.IsNullOrEmpty( ret ) ) |
|
96 { |
|
97 ret = string.Empty; |
|
98 } |
|
99 } |
|
100 // |
|
101 return ret; |
|
102 } |
|
103 } |
|
104 |
|
105 public string FileNameInDevice |
|
106 { |
|
107 get { return iFileNameInDevice; } |
|
108 set |
|
109 { |
|
110 string name = value; |
|
111 if ( name.Length < 2 ) |
|
112 { |
|
113 throw new ArgumentException( "File name is invalid" ); |
|
114 } |
|
115 |
|
116 // If the specified filename doesn't enclude a drive letter, then add one. |
|
117 bool needsDrive = false; |
|
118 if ( name.StartsWith( @"/" ) || name.StartsWith( @"\" ) ) |
|
119 { |
|
120 needsDrive = true; |
|
121 } |
|
122 else if ( name[ 1 ] != ':' ) |
|
123 { |
|
124 needsDrive = true; |
|
125 } |
|
126 |
|
127 if ( needsDrive ) |
|
128 { |
|
129 StringBuilder fileName = new StringBuilder( name ); |
|
130 if ( fileName[ 0 ] != Path.DirectorySeparatorChar ) |
|
131 { |
|
132 fileName.Insert( 0, @"\" ); |
|
133 } |
|
134 fileName.Insert( 0, PlatformFileNameConstants.Device.KPathWildcardRoot ); |
|
135 iFileNameInDevice = string.Intern( fileName.ToString() ); |
|
136 } |
|
137 else |
|
138 { |
|
139 iFileNameInDevice = string.Intern( name ); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 public string FileNameInHost |
|
145 { |
|
146 get { return iFileNameInHost; } |
|
147 set |
|
148 { |
|
149 iFileNameInHost = string.Intern( value ); |
|
150 } |
|
151 } |
|
152 #endregion |
|
153 |
|
154 #region From System.Object |
|
155 public override int GetHashCode() |
|
156 { |
|
157 return iFileNameInDevice.GetHashCode(); |
|
158 } |
|
159 |
|
160 public override string ToString() |
|
161 { |
|
162 return EitherFullNameButDevicePreferred; |
|
163 } |
|
164 |
|
165 public override bool Equals( object aObject ) |
|
166 { |
|
167 bool ret = false; |
|
168 // |
|
169 if ( aObject is PlatformFileName ) |
|
170 { |
|
171 PlatformFileName other = (PlatformFileName) aObject; |
|
172 |
|
173 // These are the strings we'll compare - we'll assume exact comparison |
|
174 // required by default... |
|
175 string pathHostThis = this.FileNameInHost; |
|
176 string pathHostOther = other.FileNameInHost; |
|
177 string pathDeviceThis = this.FileNameInDevice; |
|
178 string pathDeviceOther = other.FileNameInDevice; |
|
179 |
|
180 // We must find out if this object (or aObject) contains a wildcard. |
|
181 if ( this.ContainsWildcard || other.ContainsWildcard ) |
|
182 { |
|
183 // Compare just the in-device paths, not the drives, since one or |
|
184 // other of the drive letters is unknown. |
|
185 pathDeviceThis = this.FileNameInDeviceWithoutRoot; |
|
186 pathDeviceOther = other.FileNameInDeviceWithoutRoot; |
|
187 } |
|
188 |
|
189 // Now we can compare the two... |
|
190 bool sameDevice = string.Compare( pathDeviceThis, pathDeviceOther, StringComparison.CurrentCultureIgnoreCase ) == 0; |
|
191 bool sameHost = string.Compare( pathHostThis, pathHostOther, StringComparison.CurrentCultureIgnoreCase ) == 0; |
|
192 // |
|
193 ret = ( sameDevice || sameHost ); |
|
194 } |
|
195 else |
|
196 { |
|
197 ret = base.Equals( aObject ); |
|
198 } |
|
199 // |
|
200 return ret; |
|
201 } |
|
202 #endregion |
|
203 |
|
204 #region Internal methods |
|
205 internal string FileNameInDeviceWithoutRoot |
|
206 { |
|
207 get |
|
208 { |
|
209 string ret = iFileNameInDevice; |
|
210 // |
|
211 if ( ret.Length > 2 ) |
|
212 { |
|
213 if ( ret[ 1 ] == ':' ) |
|
214 { |
|
215 ret = ret.Substring( 2 ); |
|
216 } |
|
217 } |
|
218 // |
|
219 return ret; |
|
220 } |
|
221 } |
|
222 #endregion |
|
223 |
|
224 #region Data members |
|
225 private string iFileNameInDevice = string.Empty; |
|
226 private string iFileNameInHost = string.Empty; |
|
227 #endregion |
|
228 } |
|
229 } |