|
1 /* |
|
2 * Copyright (c) 2007 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: Interface for quering system version information. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <e32std.h> |
|
21 #include <f32file.h> |
|
22 #include "versioninfo.h" |
|
23 #include "platformverdebug.h" |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT( KS60ProductIDFiles, "z:\\system\\install\\series60v*.sis" ); |
|
27 const TInt KS60ProductIDPos = 9; // Length of 'series60v' |
|
28 _LIT( KS60ProductIDSplitMark, "." ); // For splitting 'XX.YY' to 'XX' and 'YY' |
|
29 |
|
30 |
|
31 // ============================= LOCAL FUNCTIONS =============================== |
|
32 // ----------------------------------------------------------------------------- |
|
33 // GetPlatformVersion |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 static TInt GetPlatformVersion( |
|
37 VersionInfo::TPlatformVersion& aVersion, |
|
38 RFs& aFs ) |
|
39 { |
|
40 FUNC_LOG |
|
41 |
|
42 CDir* productIds = NULL; |
|
43 TFindFile find( aFs ); |
|
44 TInt ret( find.FindWildByPath( KS60ProductIDFiles, NULL, productIds ) ); |
|
45 if ( ret == KErrNone && productIds ) |
|
46 { |
|
47 ret = productIds->Sort( ESortByName | EDescending ); |
|
48 } |
|
49 |
|
50 TPtrC ptr; |
|
51 TInt splitPos( KErrNotFound ); |
|
52 if ( ret == KErrNone && productIds ) |
|
53 { |
|
54 // Get version string 'XX.YY' |
|
55 TParsePtrC parse( ( *productIds )[ 0 ].iName ); |
|
56 ptr.Set( parse.Name().Mid( KS60ProductIDPos ) ); |
|
57 splitPos = ptr.Find( KS60ProductIDSplitMark ); |
|
58 } |
|
59 |
|
60 if ( splitPos != KErrNotFound ) |
|
61 { |
|
62 // Get major version |
|
63 TLex lex( ptr.Left( splitPos ) ); |
|
64 ret = lex.Val( aVersion.iMajorVersion, EDecimal ); |
|
65 if ( ret == KErrNone ) |
|
66 { |
|
67 // Get minor version |
|
68 lex.Assign( ptr.Mid( |
|
69 splitPos + KS60ProductIDSplitMark().Length() ) ); |
|
70 ret = lex.Val( aVersion.iMinorVersion, EDecimal ); |
|
71 } |
|
72 } |
|
73 |
|
74 if ( !productIds || splitPos == KErrNotFound || ret == KErrNotFound || |
|
75 ret == KErrPathNotFound ) |
|
76 { |
|
77 ret = KErrNotSupported; // Use not supported if info is unavailable |
|
78 } |
|
79 |
|
80 delete productIds; |
|
81 return ret; |
|
82 } |
|
83 |
|
84 |
|
85 // ============================ MEMBER FUNCTIONS =============================== |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // VersionInfo::GetVersion |
|
89 // ----------------------------------------------------------------------------- |
|
90 EXPORT_C TInt VersionInfo::GetVersion( TVersionBase& aVersion ) |
|
91 { |
|
92 FUNC_LOG_WITH_CLIENT_NAME |
|
93 |
|
94 RFs fs; |
|
95 TInt ret( fs.Connect() ); |
|
96 if ( ret == KErrNone ) |
|
97 { |
|
98 ret = GetVersion( aVersion, fs ); |
|
99 fs.Close(); |
|
100 } |
|
101 |
|
102 LOG_IF_ERROR2( |
|
103 ret, |
|
104 "VersionInfo::GetVersion-aType=%d,ret=%d", |
|
105 aVersion.iType, ret ) |
|
106 |
|
107 return ret; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // VersionInfo::GetVersion |
|
112 // ----------------------------------------------------------------------------- |
|
113 EXPORT_C TInt VersionInfo::GetVersion( TVersionBase& aVersion, RFs& aFs ) |
|
114 { |
|
115 FUNC_LOG_WITH_CLIENT_NAME |
|
116 |
|
117 // Make sure that trap handler exists because used APIs may |
|
118 // require cleanup stack even any leaving methods are not called. |
|
119 CTrapCleanup* cs = NULL; |
|
120 if ( !User::TrapHandler() ) |
|
121 { |
|
122 // Setup temporary trap handler |
|
123 cs = CTrapCleanup::New(); |
|
124 if ( !cs ) |
|
125 { |
|
126 ERROR_LOG2( |
|
127 "VersionInfo::GetVersion-type=%d,ret=%d", |
|
128 aVersion.iType, KErrNoMemory ) |
|
129 |
|
130 return KErrNoMemory; |
|
131 } |
|
132 } |
|
133 |
|
134 TInt ret( KErrNotSupported ); |
|
135 switch( aVersion.iType ) |
|
136 { |
|
137 case EPlatformVersion: |
|
138 { |
|
139 ret = GetPlatformVersion( |
|
140 static_cast< TPlatformVersion& >( aVersion ), aFs ); |
|
141 break; |
|
142 } |
|
143 default: |
|
144 { |
|
145 break; |
|
146 } |
|
147 } |
|
148 |
|
149 if ( cs ) |
|
150 { |
|
151 // Remove temporary trap handler |
|
152 User::SetTrapHandler( NULL ); |
|
153 delete cs; |
|
154 } |
|
155 |
|
156 LOG_IF_ERROR2( ret, |
|
157 "VersionInfo::GetVersion-type=%d,ret=%d", |
|
158 aVersion.iType, ret ) |
|
159 |
|
160 return ret; |
|
161 } |
|
162 |
|
163 // End of File |