|
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 class EnvEntry : EnvEntryBase |
|
25 { |
|
26 #region Constructors |
|
27 internal EnvEntry( DriveInfo aDriveInfo, out bool aIsValid ) |
|
28 : base( aDriveInfo ) |
|
29 { |
|
30 aIsValid = false; |
|
31 |
|
32 // Check whether drive contains Symbian OS environment |
|
33 try |
|
34 { |
|
35 bool gotSymbianVersion = BuildSymbianOSVersion(); |
|
36 bool gotS60Version = BuildS60Version(); |
|
37 |
|
38 // Check whether we have a valid Symbian OS version string. |
|
39 // If we do, then we don't care if the S60 version is missing |
|
40 if ( gotSymbianVersion ) |
|
41 { |
|
42 aIsValid = true; |
|
43 } |
|
44 else |
|
45 { |
|
46 // Not valid - we didn't get a Symbian OS version |
|
47 } |
|
48 } |
|
49 catch |
|
50 { |
|
51 // Not valid |
|
52 } |
|
53 } |
|
54 #endregion |
|
55 |
|
56 #region Internal methods |
|
57 private bool BuildSymbianOSVersion() |
|
58 { |
|
59 string ver = string.Empty; |
|
60 string fileName = Path.Combine( DriveName, KSymbianBuildInfoFileAndPath ); |
|
61 |
|
62 try |
|
63 { |
|
64 if ( File.Exists( fileName ) ) |
|
65 { |
|
66 // |
|
67 using ( StreamReader reader = new StreamReader( fileName ) ) |
|
68 { |
|
69 string line = reader.ReadLine(); |
|
70 while ( line != null ) |
|
71 { |
|
72 if ( line.IndexOf( KSymbianBuildInfoMarkerText ) >= 0 ) |
|
73 { |
|
74 ver = line.Replace( KSymbianBuildInfoMarkerText, "" ).Trim(); |
|
75 break; |
|
76 } |
|
77 line = reader.ReadLine(); |
|
78 } |
|
79 } |
|
80 } |
|
81 else |
|
82 { |
|
83 // Try to use a variant file instead. |
|
84 string variantPath = Path.Combine( DriveName, KSymbianVariantPath ); |
|
85 DirectoryInfo dir = new DirectoryInfo( variantPath ); |
|
86 if ( dir.Exists ) |
|
87 { |
|
88 FileInfo[] files = dir.GetFiles(); |
|
89 |
|
90 // Find the most recent file |
|
91 FileInfo newest = null; |
|
92 foreach ( FileInfo file in files ) |
|
93 { |
|
94 if ( newest == null || file.LastWriteTimeUtc > newest.LastWriteTimeUtc ) |
|
95 { |
|
96 newest = file; |
|
97 } |
|
98 } |
|
99 |
|
100 if ( newest != null ) |
|
101 { |
|
102 ver = Path.GetFileNameWithoutExtension( newest.FullName ); |
|
103 } |
|
104 } |
|
105 } |
|
106 } |
|
107 catch |
|
108 { |
|
109 } |
|
110 |
|
111 // Update version |
|
112 bool valid = string.IsNullOrEmpty( ver ) == false; |
|
113 if ( valid ) |
|
114 { |
|
115 base.VersionStringSymbian = ver; |
|
116 } |
|
117 return valid; |
|
118 } |
|
119 |
|
120 private bool BuildS60Version() |
|
121 { |
|
122 string ver = string.Empty; |
|
123 string fileName = Path.Combine( DriveName, KS60BuildInfoFileAndPath ); |
|
124 // |
|
125 try |
|
126 { |
|
127 if ( File.Exists( fileName ) ) |
|
128 { |
|
129 using ( StreamReader reader = new StreamReader( fileName ) ) |
|
130 { |
|
131 string line = reader.ReadLine(); |
|
132 while ( line != null ) |
|
133 { |
|
134 if ( line.IndexOf( KS60BuildInfoMarkerText ) == 0 ) |
|
135 { |
|
136 int breakPos = line.IndexOf( "\\n" ); |
|
137 if ( breakPos > 0 ) |
|
138 { |
|
139 ver = line.Substring( KS60BuildInfoMarkerText.Length, breakPos - KS60BuildInfoMarkerText.Length ); |
|
140 break; |
|
141 } |
|
142 } |
|
143 line = reader.ReadLine(); |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 catch |
|
149 { |
|
150 } |
|
151 |
|
152 // Update version |
|
153 bool valid = string.IsNullOrEmpty( ver ) == false; |
|
154 if ( valid ) |
|
155 { |
|
156 base.VersionStringS60 = ver; |
|
157 } |
|
158 return valid; |
|
159 } |
|
160 #endregion |
|
161 |
|
162 #region Internal constants |
|
163 private const string KSymbianBuildInfoMarkerText = "ManufacturerSoftwareBuild"; |
|
164 private const string KS60BuildInfoMarkerText = "V "; |
|
165 private const string KSymbianBuildInfoFileAndPath = @"epoc32\data\buildinfo.txt"; |
|
166 private const string KSymbianVariantPath = @"epoc32\include\variant\"; |
|
167 private const string KS60BuildInfoFileAndPath = @"epoc32\data\z\resource\versions\sw.txt"; |
|
168 #endregion |
|
169 |
|
170 #region Data members |
|
171 #endregion |
|
172 } |
|
173 } |