|
1 /* |
|
2 * Copyright (c) 2004-2008 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 |
|
18 using System; |
|
19 using System.IO; |
|
20 using System.Collections.Generic; |
|
21 using System.Text; |
|
22 using System.Text.RegularExpressions; |
|
23 using SymbianStructuresLib.Debug.Symbols; |
|
24 using SymbianSymbolLib.SourceManagement.Source; |
|
25 using SymbianSymbolLib.SourceManagement.Provisioning; |
|
26 using SymbianUtils.FileTypes; |
|
27 using SymbianUtils; |
|
28 |
|
29 namespace SLPluginObey.Reader |
|
30 { |
|
31 internal class ObeyFileReader : AsyncTextFileReader |
|
32 { |
|
33 #region Delegates & events |
|
34 public delegate void ObyEntryHandler( ObeyFileReader aReader, string aHost, string aDevice ); |
|
35 public event ObyEntryHandler EntryRead; |
|
36 #endregion |
|
37 |
|
38 #region Constructors |
|
39 public ObeyFileReader( string aFileName ) |
|
40 : base( aFileName ) |
|
41 { |
|
42 // We should identify what kind of prefix to apply to all the (host) file name |
|
43 // entries that we read from the OBY file. |
|
44 // |
|
45 // For example, the OBY might say: |
|
46 // |
|
47 // \epoc32\release\ARMV5\urel\somebinary.dll "..." |
|
48 // |
|
49 // We must work out where that '\epoc32' directory is relative to, and then |
|
50 // use this as the basis of the prefix to apply to every line we read |
|
51 // from the OBY itself. |
|
52 // |
|
53 // Pre-conditions: |
|
54 // * We will only ever look on the host drive that contains the actual OBY file. |
|
55 // |
|
56 // Algorithm: |
|
57 // |
|
58 // 1) We will search up the directory tree, starting at the directory containing the OBY |
|
59 // and check whether it contains an \epoc32\ subdirectory. |
|
60 // 2) If an \epoc32 subdirectory exists, then this is our prefix. |
|
61 // 3) If no such subdirectory exists, then we pop a level from the directory (i.e. move to parent) |
|
62 // and try again. |
|
63 // 4) Eventually, we'll end up with [OBY drive letter]:\epoc32\ - at this point, even if |
|
64 // the specified directory does not exist, we'll just give up. |
|
65 // |
|
66 |
|
67 // Fail safe |
|
68 iRootPathToApplyToAllHostFileNames = Path.GetPathRoot( base.FileName ); |
|
69 try |
|
70 { |
|
71 DirectoryInfo dirInfo = new DirectoryInfo( Path.GetDirectoryName( aFileName ) ); |
|
72 while( dirInfo.Exists ) |
|
73 { |
|
74 string path = Path.Combine( dirInfo.FullName, KStandardEpoc32Path ); |
|
75 if ( Directory.Exists( path ) ) |
|
76 { |
|
77 iRootPathToApplyToAllHostFileNames = dirInfo.FullName; |
|
78 break; |
|
79 } |
|
80 else |
|
81 { |
|
82 dirInfo = new DirectoryInfo( dirInfo.Parent.FullName ); |
|
83 } |
|
84 } |
|
85 } |
|
86 catch |
|
87 { |
|
88 } |
|
89 } |
|
90 #endregion |
|
91 |
|
92 #region API |
|
93 public void Read( TSynchronicity aSynchronicity ) |
|
94 { |
|
95 base.StartRead( aSynchronicity ); |
|
96 } |
|
97 #endregion |
|
98 |
|
99 #region Properties |
|
100 #endregion |
|
101 |
|
102 #region From AsyncTextFileReader |
|
103 protected override void HandleFilteredLine( string aLine ) |
|
104 { |
|
105 Match m = KMapParserRegex.Match( aLine ); |
|
106 if ( m.Success ) |
|
107 { |
|
108 GroupCollection groups = m.Groups; |
|
109 string type = groups[ "Type" ].Value; |
|
110 string host = groups[ "Host" ].Value; |
|
111 string device = groups[ "Device" ].Value; |
|
112 |
|
113 // Fix up names |
|
114 try |
|
115 { |
|
116 if ( type != "ROFS_HEADER" ) |
|
117 { |
|
118 host = CombineWithHostDrive( host ); |
|
119 device = CombineWithDeviceDrive( device ); |
|
120 |
|
121 if ( EntryRead != null ) |
|
122 { |
|
123 EntryRead( this, host, device ); |
|
124 } |
|
125 } |
|
126 } |
|
127 catch ( Exception ) |
|
128 { |
|
129 base.Trace( "WARNING: exception when trying to parse OBY line: [{0}], file: [{1}]", aLine, base.FileName ); |
|
130 } |
|
131 } |
|
132 } |
|
133 #endregion |
|
134 |
|
135 #region Internal constants |
|
136 public static readonly Regex KMapParserRegex = new Regex( |
|
137 @"(?<Type>.+)\=(\x22|)(?<Host>.+?)(\x22|)(?:\s+)\x22(?<Device>.+)\x22", |
|
138 RegexOptions.CultureInvariant |
|
139 | RegexOptions.IgnorePatternWhitespace |
|
140 | RegexOptions.Compiled |
|
141 ); |
|
142 private const string KStandardEpoc32Path = @"epoc32\"; |
|
143 #endregion |
|
144 |
|
145 #region Internal methods |
|
146 private string CombineWithHostDrive( string aFileAndPath ) |
|
147 { |
|
148 string fileName = aFileAndPath.Trim(); |
|
149 if ( fileName.StartsWith( @"\" ) ) |
|
150 { |
|
151 fileName = fileName.Substring( 1 ); |
|
152 } |
|
153 |
|
154 string ret = Path.Combine( iRootPathToApplyToAllHostFileNames, fileName ); |
|
155 return ret; |
|
156 } |
|
157 |
|
158 private string CombineWithDeviceDrive( string aFileAndPath ) |
|
159 { |
|
160 string ret = Path.Combine( @"Z:\", aFileAndPath ); |
|
161 return ret; |
|
162 } |
|
163 #endregion |
|
164 |
|
165 #region Data members |
|
166 private readonly string iRootPathToApplyToAllHostFileNames; |
|
167 #endregion |
|
168 } |
|
169 } |