|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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 * Definition of the CContentProvider |
|
16 * Life-Cycle methods |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file siscontentprovider.cpp |
|
23 */ |
|
24 |
|
25 #include "siscontentprovider.h" |
|
26 #include "siscontroller.h" |
|
27 #include "sissupportedlanguages.h" |
|
28 #include "sislanguage.h" |
|
29 #include "sisstring.h" |
|
30 #include "sisinfo.h" |
|
31 #include "sissupportedoptions.h" |
|
32 #include "sissupportedoption.h" |
|
33 #include "sisversion.h" |
|
34 #include "sisinstallblock.h" |
|
35 #include "swi/sisinstallerrors.h" |
|
36 #include "siselseif.h" |
|
37 |
|
38 using namespace Swi; |
|
39 using namespace Swi::Sis; |
|
40 |
|
41 /*static*/ CContentProvider* CContentProvider::NewLC(const CController& aController) |
|
42 { |
|
43 CContentProvider* self = new(ELeave) CContentProvider(aController); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 /*static*/ CContentProvider* CContentProvider::NewL(const CController& aController) |
|
50 { |
|
51 CContentProvider* self = CContentProvider::NewLC(aController); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CContentProvider::CContentProvider(const CController& aController) : iController(aController) |
|
57 { |
|
58 } |
|
59 |
|
60 void CContentProvider::ConstructL() |
|
61 { |
|
62 const CSupportedLanguages& supportedLanguages = iController.SupportedLanguages(); |
|
63 iAvailableLanguages.Reset(); |
|
64 |
|
65 // builds a list of TLanguage of available languages from SISX file |
|
66 for(TInt language = 0; language < supportedLanguages.Count(); language++) |
|
67 { |
|
68 User::LeaveIfError(iAvailableLanguages.Append(supportedLanguages[language])); |
|
69 } |
|
70 } |
|
71 |
|
72 CContentProvider::~CContentProvider() |
|
73 { |
|
74 iAvailableLanguages.Close(); |
|
75 } |
|
76 |
|
77 // Business methods |
|
78 |
|
79 TAppInfo CContentProvider::DefaultLanguageAppInfoL() const |
|
80 { |
|
81 return DefaultLanguageAppInfoL(iController.Info()); |
|
82 } |
|
83 |
|
84 TAppInfo CContentProvider::LocalizedAppInfoL(TInt aLanguageIndex) const |
|
85 { |
|
86 return LocalizedAppInfoL(iController.Info(), aLanguageIndex); |
|
87 } |
|
88 |
|
89 TAppInfo CContentProvider::DefaultLanguageAppInfoL(const CInfo& aInfo) const |
|
90 { |
|
91 TLanguage current = User::Language(); // Language of the current locale |
|
92 |
|
93 // Check whether the current locale is in the list of available languages |
|
94 TInt idx = iAvailableLanguages.Find(current); |
|
95 |
|
96 if (idx == KErrNotFound) |
|
97 { |
|
98 idx = 0; |
|
99 } |
|
100 return LocalizedAppInfoL(aInfo, idx); |
|
101 } |
|
102 |
|
103 TAppInfo CContentProvider::LocalizedAppInfoL(const CInfo& aInfo, TInt aLanguageIndex) const |
|
104 { |
|
105 const RPointerArray<CString>& names = aInfo.Names(); |
|
106 |
|
107 const RPointerArray<CString>& vendors = aInfo.VendorNames(); |
|
108 |
|
109 // These two things can leave if the language specified is not present |
|
110 if (names.Count() <= aLanguageIndex) |
|
111 { |
|
112 User::Leave(KErrSISInfoSISNamesMissing); |
|
113 } |
|
114 CString* localizedName = names[aLanguageIndex]; |
|
115 |
|
116 if (vendors.Count() <= aLanguageIndex) |
|
117 { |
|
118 User::Leave(KErrSISInfoSISVendorNamesMissing); |
|
119 } |
|
120 CString* localizedVendor = vendors[aLanguageIndex]; |
|
121 |
|
122 const CVersion& version = aInfo.Version(); |
|
123 TVersion ver(version.Major(), version.Minor(), version.Build()); |
|
124 |
|
125 TAppInfo appaInfo = TAppInfo(localizedName->Data(), localizedVendor->Data(), ver); |
|
126 |
|
127 return appaInfo; |
|
128 } |
|
129 |
|
130 TInt64 CContentProvider::TotalSizeL(const CInstallBlock& aInstallBlock, |
|
131 CExpressionEvaluator* aCreateExpressionEvaluator, |
|
132 TBool aEmbedded) const |
|
133 { |
|
134 // Calculate the total size of the SIS file descriptions in this SISInstallBlock. |
|
135 TInt64 sizeOfInstallationBelowController = SizeOfFileDescriptionsInInstallBlock(aInstallBlock); |
|
136 |
|
137 // Process the expressions. |
|
138 for (TInt i=0 ; i < aInstallBlock.IfStatements().Count(); i++) |
|
139 { |
|
140 Sis::CIf* ifBlock=aInstallBlock.IfStatements()[i]; |
|
141 |
|
142 if (!ifBlock) |
|
143 { |
|
144 User::Leave(KErrCorrupt); |
|
145 } |
|
146 |
|
147 // Main expression. |
|
148 if (aCreateExpressionEvaluator->EvaluateL(ifBlock->Expression()).BoolValueL()) |
|
149 { |
|
150 sizeOfInstallationBelowController += TotalSizeL(ifBlock->InstallBlock(), |
|
151 aCreateExpressionEvaluator, |
|
152 aEmbedded); |
|
153 } |
|
154 else |
|
155 { |
|
156 // There are Else If blocks. |
|
157 const RPointerArray<CElseIf>& elseIfs=ifBlock->ElseIfs(); |
|
158 |
|
159 for (TInt j = 0 ; j < elseIfs.Count(); j++) |
|
160 { |
|
161 if (!elseIfs[j]) |
|
162 { |
|
163 User::Leave(KErrCorrupt); |
|
164 } |
|
165 |
|
166 if (aCreateExpressionEvaluator->EvaluateL(elseIfs[j]->Expression()).BoolValueL()) |
|
167 { |
|
168 sizeOfInstallationBelowController += TotalSizeL(elseIfs[j]->InstallBlock(), |
|
169 aCreateExpressionEvaluator, |
|
170 aEmbedded); |
|
171 break; // stop processing else if blocks |
|
172 } |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 if(aEmbedded) |
|
178 { |
|
179 // Embedded controllers in this SISInstallBlock. |
|
180 for (TInt k=0 ; k < aInstallBlock.EmbeddedControllers().Count(); k++) |
|
181 { |
|
182 if (aInstallBlock.EmbeddedControllers()[k]==NULL) |
|
183 { |
|
184 User::Leave(KErrCorrupt); |
|
185 } |
|
186 sizeOfInstallationBelowController += TotalSizeL(aInstallBlock.EmbeddedControllers()[k]->InstallBlock(), |
|
187 aCreateExpressionEvaluator, |
|
188 aEmbedded); |
|
189 } |
|
190 } |
|
191 return sizeOfInstallationBelowController; |
|
192 } |
|
193 |
|
194 RPointerArray<TDesC> CContentProvider::LocalizedOptionsL(TInt aLanguageIndex) const |
|
195 { |
|
196 const CSupportedOptions& options= iController.SupportedOptions(); |
|
197 |
|
198 // Now get the options and localize them... |
|
199 RPointerArray<TDesC> ret; |
|
200 CleanupClosePushL(ret); |
|
201 |
|
202 for (TInt option = 0; option < options.Count(); option++) |
|
203 { |
|
204 const RPointerArray<CString>& names = options[option].Names(); |
|
205 ret.Append(&names[aLanguageIndex]->Data()); |
|
206 } |
|
207 |
|
208 CleanupStack::Pop(&ret); |
|
209 return ret; |
|
210 } |
|
211 |
|
212 TInt64 CContentProvider::SizeOfFileDescriptionsInInstallBlock(const CInstallBlock& aInstallBlock) const |
|
213 { |
|
214 // Get all the SIS file descriptions in this SISInstallBlock. |
|
215 const RPointerArray<CFileDescription>& files=aInstallBlock.FileDescriptions(); |
|
216 |
|
217 TInt64 totalSizeOfFileDescriptions = 0; |
|
218 |
|
219 // Calculate the size of all the SIS file descriptions in this SISInstallBlock. |
|
220 for (TInt l=0; l < files.Count(); l++) |
|
221 { |
|
222 CFileDescription& sisFileDescription = (*files[l]); |
|
223 totalSizeOfFileDescriptions += sisFileDescription.UncompressedLength(); |
|
224 } |
|
225 return totalSizeOfFileDescriptions; |
|
226 } |