|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * Declares the CXmlParser class for ADM application. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "ADMSisParser.h" |
|
22 #include "ADMPackageInfo.h" |
|
23 #include <sisparser.h> |
|
24 #include <siscontents.h> |
|
25 #include <siscontroller.h> |
|
26 #include <sisinfo.h> |
|
27 #include <sisdependency.h> |
|
28 #include <sisuid.h> |
|
29 #include <sisversion.h> |
|
30 #include <sisprerequisites.h> |
|
31 #include <sisversionrange.h> |
|
32 #include <filesisdataprovider.h> |
|
33 #include <dessisdataprovider.h> |
|
34 #include <sisversionrange.h> |
|
35 #include <sisinstallblock.h> |
|
36 #include <sissupportedlanguages.h> |
|
37 |
|
38 using namespace Swi; |
|
39 |
|
40 CSisParser* CSisParser::NewLC() |
|
41 { |
|
42 CSisParser* object = new ( ELeave ) CSisParser(); |
|
43 CleanupStack::PushL( object ); |
|
44 object->ConstructL(); |
|
45 return object; |
|
46 } |
|
47 |
|
48 CSisParser* CSisParser::NewL() |
|
49 { |
|
50 CSisParser* object = CSisParser::NewLC(); |
|
51 CleanupStack::Pop(); |
|
52 return object; |
|
53 } |
|
54 |
|
55 CSisParser::CSisParser() |
|
56 { |
|
57 } |
|
58 |
|
59 CSisParser::~CSisParser() |
|
60 { |
|
61 iRfs.Close(); |
|
62 } |
|
63 |
|
64 void CSisParser::ConstructL() |
|
65 { |
|
66 User::LeaveIfError(iRfs.Connect()); |
|
67 } |
|
68 |
|
69 //TODO: a http sis data provider would allow partial download? |
|
70 CPackageInfo* CSisParser::GetDepContentsL(const TDesC& aDepFileName, CPackageInfo *packageInfo,CDepTree* mainTree) |
|
71 { |
|
72 CFileSisDataProvider *provider = CFileSisDataProvider::NewLC(iRfs, aDepFileName); |
|
73 Sis::CContents* contents = Sis::Parser::ContentsL(*provider); |
|
74 CleanupStack::PushL(contents); |
|
75 HBufC8* controllerpkg = contents->ReadControllerL(); |
|
76 CleanupStack::PushL(controllerpkg); |
|
77 CDesDataProvider* controllerProvider= CDesDataProvider::NewLC(*controllerpkg); |
|
78 Sis::CController* controller = CController::NewLC(*controllerProvider); |
|
79 SetDependenciesL(packageInfo, mainTree, controller, aDepFileName); |
|
80 |
|
81 CleanupStack::PopAndDestroy(controller); |
|
82 CleanupStack::PopAndDestroy(controllerProvider); |
|
83 CleanupStack::PopAndDestroy(controllerpkg); |
|
84 CleanupStack::PopAndDestroy(contents); |
|
85 CleanupStack::PopAndDestroy(provider); |
|
86 return packageInfo; |
|
87 } |
|
88 |
|
89 void CSisParser::SetDependenciesL(CPackageInfo *packageInfo,CDepTree* mainTree, Sis::CController* controller, const TDesC& aFileName) |
|
90 { |
|
91 //have now extracted the controller (header information) from the sis file. |
|
92 if(mainTree->IsDepTreeEmpty()) |
|
93 { |
|
94 packageInfo = CPackageInfo::NewL(); |
|
95 packageInfo->iPackageUid = controller->Info().Uid().Uid().iUid; |
|
96 packageInfo->iVendor = controller->Info().UniqueVendorName().Data().AllocL(); |
|
97 packageInfo->iVersion = TVersion(controller->Info().Version().Major(), |
|
98 controller->Info().Version().Minor(), |
|
99 controller->Info().Version().Build()); |
|
100 SetLanguageSpecificNamesL(controller, packageInfo); |
|
101 |
|
102 packageInfo->iPackageStatus = EPackageRootToBeInstalled; |
|
103 //TODO: HACK - ADM expects to use iPackageName as a filename, SIS file contains only UIDs |
|
104 packageInfo->iSisPackageName = aFileName.AllocL(); |
|
105 //TODO: end HACK |
|
106 mainTree->AddPackageInfo(packageInfo); |
|
107 } |
|
108 |
|
109 //Get dependencies |
|
110 const RPointerArray<Sis::CDependency> &deps(controller->Prerequisites().Dependencies()); |
|
111 for(TInt i=0;i<deps.Count();i++) |
|
112 { |
|
113 const Sis::CDependency* dep(deps[i]); |
|
114 TUint32 uid = dep->Uid().Uid().iUid; |
|
115 CPackageInfo *dependentPackage = mainTree->LocatePackageInDepTree(uid); |
|
116 if(dependentPackage == NULL) |
|
117 { |
|
118 dependentPackage = CPackageInfo::NewLC(); |
|
119 dependentPackage->iPackageUid = dep->Uid().Uid().iUid; |
|
120 //TODO: HACK - ADM expects to use iPackageName as a filename, SIS file contains only UIDs |
|
121 TBuf<8> uidBuf; |
|
122 uidBuf.Num(dependentPackage->iPackageUid, EHex); |
|
123 dependentPackage->iPackageName = uidBuf.AllocL(); |
|
124 //TODO: end HACK |
|
125 packageInfo->AddEdgeL(dependentPackage); |
|
126 mainTree->AddPackageInfo(dependentPackage); |
|
127 CleanupStack::Pop(dependentPackage); |
|
128 } |
|
129 //embedded and outer sis may depend on different version of the same package - in this case, use the higher version number |
|
130 const Sis::CVersion& ver = dep->VersionRange()->From(); |
|
131 if(dependentPackage->iVersion.iMajor < ver.Major() || |
|
132 (dependentPackage->iVersion.iMajor == ver.Major() && dependentPackage->iVersion.iMinor < ver.Minor()) || |
|
133 (dependentPackage->iVersion.iMajor == ver.Major() && dependentPackage->iVersion.iMinor == ver.Minor() && dependentPackage->iVersion.iBuild < ver.Build())) |
|
134 { |
|
135 dependentPackage->iVersion = TVersion(ver.Major(), |
|
136 ver.Minor(), |
|
137 ver.Build()); |
|
138 } |
|
139 //also available : dependency names (localised list) |
|
140 } |
|
141 |
|
142 //Get embedded SIS files' dependencies too |
|
143 const RPointerArray<Sis::CController> &embedded = controller->InstallBlock().EmbeddedControllers(); |
|
144 for(TInt i=0;i<embedded.Count();i++) |
|
145 { |
|
146 SetDependenciesL(packageInfo, mainTree, embedded[i], KNullDesC); |
|
147 } |
|
148 } |
|
149 |
|
150 void CSisParser::SetLanguageSpecificNamesL(Sis::CController* aController, CPackageInfo* aPackageInfo) |
|
151 { |
|
152 const Sis::CSupportedLanguages &lang = aController->SupportedLanguages(); |
|
153 TLocale locale; |
|
154 TInt langIdx = KErrNotFound; |
|
155 // find the language index, so we can access the proper localised |
|
156 // names in the sis package |
|
157 for (TInt downgradeIdx = -1; downgradeIdx < 3; downgradeIdx++) |
|
158 { |
|
159 // Go through the language downgrade path |
|
160 // See the documentation of TLocale::LanguageDowngrade() |
|
161 const TLanguage language = (downgradeIdx == -1) |
|
162 ? User::Language() |
|
163 : locale.LanguageDowngrade(downgradeIdx); |
|
164 if (language == ELangNone) |
|
165 break; |
|
166 for (TInt i = 0; i < lang.Count(); i++) |
|
167 { |
|
168 if (lang[i] == language) |
|
169 { |
|
170 langIdx = i; |
|
171 break; |
|
172 } |
|
173 } |
|
174 } |
|
175 const RPointerArray<Sis::CString>& names = aController->Info().Names(); |
|
176 // also available: VendorNames() |
|
177 |
|
178 // Set localised name for the package |
|
179 // Sis package didn't contain localised name, use the default |
|
180 if (langIdx != KErrNotFound) |
|
181 { |
|
182 aPackageInfo->iPackageName = names[langIdx]->Data().AllocL(); |
|
183 } |
|
184 else if (names.Count() > 0) |
|
185 { |
|
186 aPackageInfo->iPackageName = names[0]->Data().AllocL(); |
|
187 } |
|
188 else |
|
189 { |
|
190 aPackageInfo->iPackageName = KNullDesC().AllocL(); |
|
191 } |
|
192 } |