|
1 // Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: File to Parse Resource File for Class AppRegistrationInfo and Create Input for |
|
14 // XML Generator. |
|
15 // |
|
16 |
|
17 |
|
18 #include "parameterlist.h" |
|
19 #include "stringutils.h" |
|
20 #include "is_utils.h" |
|
21 #include "dirparse.h" |
|
22 #include "barsc2.h" |
|
23 #include "commontypes.h" |
|
24 #include "sisregistry.h" |
|
25 #include "errors.h" |
|
26 #include "dbconstants.h" |
|
27 #include "parse.h" |
|
28 #include "utility_interface.h" |
|
29 |
|
30 using namespace std; |
|
31 |
|
32 /** |
|
33 @internalTechnology |
|
34 */ |
|
35 std::wstring AppResourceFileExtension = L".rsc"; |
|
36 |
|
37 /** |
|
38 * Identify if input file is a Registration Resource File. |
|
39 @ Param : aRegistrationFileName - File name to be scanned. |
|
40 */ |
|
41 TInt FindRegistrationResourceFileL(std::string& aRegistrationFileName) |
|
42 { |
|
43 CResourceFile* registrationFile = NULL; |
|
44 try { |
|
45 registrationFile = new CResourceFile(aRegistrationFileName, 0, 0); |
|
46 if(NULL==registrationFile) |
|
47 { |
|
48 std::cout<<"Failed : Error in Reading File. Memory Allocation Failed"<<std::endl; |
|
49 return 1; |
|
50 } |
|
51 else |
|
52 { |
|
53 TUid iAppUid = registrationFile->ReadFileUidL(); |
|
54 if(KUidAppRegistrationResourceFile == iAppUid.GetUid()) |
|
55 { |
|
56 delete registrationFile; |
|
57 return 0; |
|
58 } |
|
59 } |
|
60 } |
|
61 catch(const CResourceFileException& aObject) |
|
62 { |
|
63 if(registrationFile) |
|
64 delete registrationFile; |
|
65 return 1; |
|
66 } |
|
67 |
|
68 delete registrationFile; |
|
69 return 1; |
|
70 } |
|
71 |
|
72 |
|
73 /** |
|
74 * Creates Class TAppDataType for XML Parsing |
|
75 */ |
|
76 |
|
77 std::wstring Ptr8_2_Wstring(const Ptr8* aBuf) |
|
78 { |
|
79 std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters |
|
80 |
|
81 TUint8* temp = aBuf->GetPtr(); |
|
82 std::copy(temp,temp+aBuf->GetLength(),str2.begin()); |
|
83 |
|
84 return str2; |
|
85 } |
|
86 |
|
87 |
|
88 void CreateAppDataType(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo& aAppDataType, |
|
89 const TDataTypeWithPriority* aTemp) |
|
90 { |
|
91 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TDataType componentDataType; |
|
92 |
|
93 componentDataType.iPriority = aTemp->iPriority; |
|
94 componentDataType.iType = Ptr8_2_Wstring(aTemp->iDataType.GetDataType()); |
|
95 |
|
96 aAppDataType.iDataType.push_back(componentDataType); |
|
97 } |
|
98 |
|
99 /** |
|
100 * Creates Class TViewData for XML Parsing |
|
101 */ |
|
102 void CreateViewDataL(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo& aLocalizableAttribute, |
|
103 const CAppLocalizableInfo* aAppInfoReader) |
|
104 { |
|
105 std::wstring sStr1; |
|
106 std::wstring sStr; |
|
107 |
|
108 std::vector<CAppViewData*>* viewDataArray = aAppInfoReader->GetViewDataArray(); |
|
109 |
|
110 if(viewDataArray) |
|
111 { |
|
112 for(TInt i = 0; i<viewDataArray->size(); i++) |
|
113 { |
|
114 |
|
115 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData ViewData; |
|
116 CAppViewData *temp = viewDataArray->at(i); |
|
117 |
|
118 sStr = DbConstants::CompUID; |
|
119 TUid ID = temp->Uid(); |
|
120 sStr1 = Utils::IntegerToWideString(ID.GetUid()); |
|
121 CreateViewDataAttributes(ViewData,sStr,sStr1,true,false); |
|
122 |
|
123 sStr = DbConstants::CompScreenMode; |
|
124 TInt SMode = temp->GetScreenMode(); |
|
125 |
|
126 sStr1 = Utils::IntegerToWideString(SMode); |
|
127 CreateViewDataAttributes(ViewData,sStr,sStr1,true,false); |
|
128 |
|
129 sStr = DbConstants::CompCaption; |
|
130 Ptr16* caption = temp->GetCaption(); |
|
131 if(caption) |
|
132 sStr1 = Ptr16ToWstring(caption); |
|
133 else |
|
134 sStr1=L'\0'; |
|
135 CreateViewDataAttributes(ViewData,sStr,sStr1,false,false); |
|
136 |
|
137 sStr = DbConstants::CompNumberOfIcons; |
|
138 TInt IconNum = temp->GetNumOfViewIcons(); |
|
139 sStr1 = Utils::IntegerToWideString(IconNum); |
|
140 CreateViewDataAttributes(ViewData,sStr,sStr1,true,false); |
|
141 |
|
142 sStr = DbConstants::CompIconFile; |
|
143 Ptr16* IconName = temp->GetIconFileName(); |
|
144 if(IconName) |
|
145 sStr1 = Ptr16ToWstring(IconName); |
|
146 else |
|
147 sStr1=L'\0'; |
|
148 CreateViewDataAttributes(ViewData,sStr,sStr1,false,false); |
|
149 |
|
150 aLocalizableAttribute.iViewData.push_back(ViewData); |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 void CreateViewDataAttributes(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData& aViewData, |
|
156 const std::wstring& aName,const std::wstring& aValue, |
|
157 const bool aIsIntValue, const int aIsStr8Bit) |
|
158 { |
|
159 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData::TViewDataAttributes ViewDataAttributes; |
|
160 |
|
161 ViewDataAttributes.iName = aName; |
|
162 ViewDataAttributes.iValue = aValue; |
|
163 ViewDataAttributes.iIsIntValue = aIsIntValue; |
|
164 ViewDataAttributes.iIsStr8Bit = aIsStr8Bit; |
|
165 |
|
166 aViewData.iViewDataAttributes.push_back(ViewDataAttributes); |
|
167 } |
|
168 |
|
169 /** |
|
170 * Creates Class TLocalizableAttribute for XML Parsing |
|
171 */ |
|
172 |
|
173 void CreateLocalizableAttribute(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo& aLocalizableAttribute, |
|
174 const std::wstring& aName, const std::wstring& aValue, |
|
175 const bool aIsIntValue, const int aIsStr8Bit) |
|
176 { |
|
177 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TLocalizableAttribute LocalizableAttribute; |
|
178 |
|
179 LocalizableAttribute.iName = aName; |
|
180 LocalizableAttribute.iValue = aValue; |
|
181 LocalizableAttribute.iIsIntValue = aIsIntValue; |
|
182 LocalizableAttribute.iIsStr8Bit = aIsStr8Bit; |
|
183 |
|
184 aLocalizableAttribute.iLocalizableAttribute.push_back(LocalizableAttribute); |
|
185 } |
|
186 |
|
187 /** |
|
188 * Creates Class TAppLocalizableInfo for XML Parsing |
|
189 */ |
|
190 void CreateLocalizableInfoL(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppLocalizableInfo, |
|
191 const CAppLocalizableInfo* aInfoReader) |
|
192 { |
|
193 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo componentLocalizableInfo; |
|
194 |
|
195 Ptr16* shortCaption = aInfoReader->GetShortCaption(); |
|
196 std::wstring sStr = DbConstants::CompShortCaption; |
|
197 std::wstring sStr1; |
|
198 |
|
199 if(shortCaption) |
|
200 sStr1 = Ptr16ToWstring(shortCaption); |
|
201 else |
|
202 sStr1=L'\0'; |
|
203 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false); |
|
204 |
|
205 Ptr16* caption = aInfoReader->GetCaption(); |
|
206 sStr = DbConstants::CompCaption; |
|
207 if(caption) |
|
208 sStr1 = Ptr16ToWstring(caption); |
|
209 else |
|
210 sStr1=L'\0'; |
|
211 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false); |
|
212 |
|
213 TInt iNumOfAppIcons = aInfoReader->GetNumOfAppIcons(); |
|
214 sStr = DbConstants::CompNumberOfIcons; |
|
215 sStr1 = Utils::IntegerToWideString(iNumOfAppIcons); |
|
216 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,true,false); |
|
217 |
|
218 TInt iLocale = aInfoReader->GetLocale(); |
|
219 sStr = DbConstants::CompLocale; |
|
220 sStr1 = Utils::IntegerToWideString(iLocale); |
|
221 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,true,false); |
|
222 |
|
223 Ptr16* iIconFileName = aInfoReader->GetIconFileName(); |
|
224 sStr = DbConstants::CompIconFile; |
|
225 if(iIconFileName) |
|
226 sStr1 = Ptr16ToWstring(iIconFileName); |
|
227 else |
|
228 sStr1=L'\0'; |
|
229 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false); |
|
230 |
|
231 Ptr16* iGroupName = aInfoReader->GetGroupName(); |
|
232 sStr = DbConstants::CompGroupName; |
|
233 if(iGroupName) |
|
234 sStr1 = Ptr16ToWstring(iGroupName); |
|
235 else |
|
236 sStr1=L'\0'; |
|
237 CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false); |
|
238 |
|
239 CreateViewDataL(componentLocalizableInfo,aInfoReader); |
|
240 |
|
241 aAppLocalizableInfo.iApplicationLocalizableInfo.push_back(componentLocalizableInfo); |
|
242 } |
|
243 |
|
244 |
|
245 /** |
|
246 * Creates Class TAppServiceInfo for XML Parsing |
|
247 */ |
|
248 |
|
249 void CreateAppServiceInfo(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppServiceInfo, |
|
250 const TUid& aUid, const std::vector<TDataTypeWithPriority*>& aDataType) |
|
251 { |
|
252 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo componentServiceInfo; |
|
253 |
|
254 componentServiceInfo.iUid = aUid.GetUid(); |
|
255 for(TInt ii = 0; ii<aDataType.size(); ii++) |
|
256 { |
|
257 TDataTypeWithPriority *temp = aDataType.at(ii); |
|
258 CreateAppDataType(componentServiceInfo,temp); |
|
259 } |
|
260 |
|
261 aAppServiceInfo.iApplicationServiceInfo.push_back(componentServiceInfo); |
|
262 } |
|
263 |
|
264 /** |
|
265 * Creates Class TAppAttribute for XML Parsing |
|
266 */ |
|
267 |
|
268 void CreateAppAttribute(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppAttribute, |
|
269 const std::wstring& aName,const std::wstring& aValue, |
|
270 const bool aIsIntValue, const int aIsStr8Bit ) |
|
271 { |
|
272 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppAttribute componentAttribute; |
|
273 |
|
274 componentAttribute.iName = aName; |
|
275 componentAttribute.iValue = aValue; |
|
276 componentAttribute.iIsIntValue = aIsIntValue; |
|
277 componentAttribute.iIsStr8Bit = aIsStr8Bit; |
|
278 |
|
279 aAppAttribute.iApplicationAttribute.push_back(componentAttribute); |
|
280 } |
|
281 |
|
282 /** |
|
283 * Creates Class TAppAttribute for XML Parsing |
|
284 */ |
|
285 |
|
286 void CreateAppProperty(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppProperty, |
|
287 const std::wstring& aStrValue, const int aLocale, |
|
288 const int aServiceUid, const bool aIsStr8Bit ) |
|
289 { |
|
290 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppProperty componentproperty; |
|
291 |
|
292 componentproperty.iName = DbConstants::CompOpaqueData; |
|
293 componentproperty.iLocale = aLocale; |
|
294 componentproperty.iServiceUid = aServiceUid; |
|
295 componentproperty.iIntValue = 0; |
|
296 componentproperty.iStrValue = aStrValue; |
|
297 componentproperty.iIsStr8Bit = aIsStr8Bit; |
|
298 |
|
299 aAppProperty.iApplicationProperty.push_back(componentproperty); |
|
300 } |
|
301 |
|
302 /** |
|
303 * Creates Class TOpaqueDataType for XML Parsing |
|
304 */ |
|
305 |
|
306 void CreateOpaqueDataType(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppOpaqueData, |
|
307 const std::wstring& aStrValue, const int aLocale, const int aServUid) |
|
308 { |
|
309 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TOpaqueDataType componentData; |
|
310 |
|
311 componentData.iLocale = aLocale; |
|
312 componentData.iServiceUid = aServUid; |
|
313 componentData.iOpaqueData = aStrValue; |
|
314 |
|
315 aAppOpaqueData.iOpaqueDataType.push_back(componentData); |
|
316 } |
|
317 |
|
318 /** |
|
319 * Get the path of Database "scr.db" |
|
320 */ |
|
321 |
|
322 std::string GetDbPath(const CParameterList* aParamList) |
|
323 { |
|
324 if ( |
|
325 (aParamList->RomLogFileNames().size() != 0 && aParamList->RomDrivePath().size() == 0 ) || |
|
326 aParamList->IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) |
|
327 ) |
|
328 { |
|
329 return wstring2string(aParamList->SystemDrivePath()) + "\\sys\\install\\scr\\scr.db"; |
|
330 } |
|
331 |
|
332 return wstring2string(aParamList->RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db"; |
|
333 } |
|
334 |
|
335 /** |
|
336 * Update Installation Information in Database using SRCTOOL |
|
337 */ |
|
338 |
|
339 void UpdateInstallationInformation_xml(const CParameterList* aParamList, |
|
340 XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail) |
|
341 { |
|
342 CXmlGenerator xmlGenerator; |
|
343 char* tmpFileName = tmpnam(NULL); |
|
344 std::wstring filename(string2wstring(tmpFileName)); |
|
345 |
|
346 int isRomApplication = 1; |
|
347 xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication); |
|
348 |
|
349 std::string executable = "scrtool.exe"; |
|
350 std::string command; |
|
351 |
|
352 command = executable + " -d " + GetDbPath(aParamList) + " -p " + tmpFileName; |
|
353 |
|
354 cout << "Updating DB : " << command << endl; |
|
355 |
|
356 int error = system(command.c_str()); |
|
357 |
|
358 if(error != 0) |
|
359 { |
|
360 LERROR(L"Scrtool failed to upload the database registry entry."); |
|
361 } |
|
362 |
|
363 error = remove(tmpFileName); |
|
364 |
|
365 if(error != 0) |
|
366 { |
|
367 LERROR(L"Temporary file removal failed."); |
|
368 } |
|
369 } |
|
370 |
|
371 /** |
|
372 * Creates Class TApplicationRegistrationInfo for XML Parsing |
|
373 */ |
|
374 |
|
375 |
|
376 void CreateApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, |
|
377 const CAppInfoReader* aAppInfoReader) |
|
378 { |
|
379 XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo atemp; |
|
380 |
|
381 Ptr16* iAppBinaryFullName = aAppInfoReader->AppBinaryFullName(); |
|
382 std::wstring sStr = DbConstants::CompAppFile; |
|
383 std::wstring sStr1 = Ptr16ToWstring(iAppBinaryFullName); |
|
384 CreateAppAttribute(atemp,sStr,sStr1,false,false); |
|
385 |
|
386 TUidType iAppBinaryUidType = aAppInfoReader->AppBinaryUidType();; |
|
387 sStr = DbConstants::CompAppUid; |
|
388 TUid Uid = iAppBinaryUidType[2]; |
|
389 sStr1 = Utils::IntegerToWideString(Uid.GetUid()); |
|
390 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
391 |
|
392 sStr = DbConstants::CompTypeId; |
|
393 TInt TypeId = -1367772926; |
|
394 sStr1 = Utils::IntegerToWideString(TypeId); |
|
395 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
396 |
|
397 TAppCapability iCapability; |
|
398 aAppInfoReader->Capability(iCapability); |
|
399 |
|
400 sStr = DbConstants::CompAttributes; |
|
401 sStr1 = Utils::IntegerToWideString(iCapability.iAttributes); |
|
402 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
403 |
|
404 sStr = DbConstants::CompHidden; |
|
405 sStr1 = Utils::IntegerToWideString(iCapability.iAppIsHidden); |
|
406 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
407 |
|
408 sStr = DbConstants::CompEmbeddable; |
|
409 sStr1 = Utils::IntegerToWideString(iCapability.iEmbeddability); |
|
410 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
411 |
|
412 sStr = DbConstants::CompNewfile; |
|
413 sStr1 = Utils::IntegerToWideString(iCapability.iSupportsNewFile); |
|
414 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
415 |
|
416 sStr = DbConstants::CompLaunch; |
|
417 sStr1 = Utils::IntegerToWideString(iCapability.iLaunchInBackground); |
|
418 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
419 |
|
420 sStr = DbConstants::CompGroupName; |
|
421 if(iCapability.iGroupName) |
|
422 sStr1 = Ptr16ToWstring(iCapability.iGroupName); |
|
423 else |
|
424 sStr1=L'\0'; |
|
425 CreateAppAttribute(atemp,sStr,sStr1,false,false); |
|
426 |
|
427 TUint iDefaultScreenNumber = aAppInfoReader->DefaultScreenNumber(); |
|
428 sStr = DbConstants::CompDefaultScreenNumber; |
|
429 sStr1 = Utils::IntegerToWideString(iDefaultScreenNumber); |
|
430 CreateAppAttribute(atemp,sStr,sStr1,true,false); |
|
431 |
|
432 std::vector<Ptr16*>* ownedFileArray = aAppInfoReader->OwnedFiles(); |
|
433 if(ownedFileArray) |
|
434 { |
|
435 for(TInt ii = 0; ii<ownedFileArray->size(); ii++) |
|
436 { |
|
437 Ptr16 *temp = ownedFileArray->at(ii); |
|
438 if(temp) |
|
439 sStr = Ptr16ToWstring(temp); |
|
440 else |
|
441 sStr=L'\0'; |
|
442 atemp.iFileOwnershipInfo.push_back(sStr); |
|
443 } |
|
444 } |
|
445 |
|
446 TInt iIndexOfFirstOpenService; |
|
447 std::vector<TAppServiceInfo*>* iServiceArray = aAppInfoReader->ServiceArray(iIndexOfFirstOpenService); |
|
448 if(iServiceArray) |
|
449 { |
|
450 for(TInt i = 0; i<iServiceArray->size(); i++) |
|
451 { |
|
452 TAppServiceInfo* temp = iServiceArray->at(i); |
|
453 TUid iUid = temp->GetUid(); |
|
454 std::vector<TDataTypeWithPriority*> iData = temp->GetDataType(); |
|
455 CreateAppServiceInfo(atemp,iUid,iData); |
|
456 |
|
457 int servUid = iUid.GetUid(); |
|
458 std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray(); |
|
459 for(TInt i = 0; i<opaqueDataArray.size(); i++) |
|
460 { |
|
461 CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i); |
|
462 |
|
463 TUint32 serviceUid = tp->GetServiceUid(); |
|
464 if(servUid == serviceUid) |
|
465 { |
|
466 Ptr8* opaqueData = tp->GetOpaqueData(); |
|
467 if(opaqueData) |
|
468 sStr1 = Ptr8ToWstring(opaqueData); |
|
469 else |
|
470 sStr1=L'\0'; |
|
471 |
|
472 TInt locale = tp->GetLocale(); |
|
473 CreateOpaqueDataType(atemp,sStr1,locale,serviceUid); |
|
474 } |
|
475 } |
|
476 } |
|
477 } |
|
478 |
|
479 std::vector<CAppLocalizableInfo*> aAppLocalizable = aAppInfoReader->LocalizableInfo(); |
|
480 |
|
481 for(TInt i = 0; i<aAppLocalizable.size(); i++) |
|
482 { |
|
483 CAppLocalizableInfo* tp = aAppLocalizable.at(i); |
|
484 CreateLocalizableInfoL(atemp,tp); |
|
485 } |
|
486 |
|
487 std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray(); |
|
488 for(TInt i = 0; i<opaqueDataArray.size(); i++) |
|
489 { |
|
490 CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i); |
|
491 |
|
492 TUint32 serviceUid = tp->GetServiceUid(); |
|
493 if(0 == serviceUid) |
|
494 { |
|
495 Ptr8* opaqueData = tp->GetOpaqueData(); |
|
496 if(opaqueData) |
|
497 sStr1 = Ptr8ToWstring(opaqueData); |
|
498 else |
|
499 sStr1=L'\0'; |
|
500 |
|
501 TInt locale = tp->GetLocale(); |
|
502 CreateOpaqueDataType(atemp,sStr1,locale,serviceUid); |
|
503 } |
|
504 } |
|
505 |
|
506 aComponent.iApplicationRegistrationInfo.push_back(atemp); |
|
507 } |
|
508 |
|
509 |
|
510 /** |
|
511 * Get the path of Localizefile. |
|
512 */ |
|
513 |
|
514 std::string GetLocalizeFilePath(const std::string& aFileName, const CParameterList* aParamList) |
|
515 { |
|
516 if(aParamList->IsFlagSet(CParameterList::EFlagsResourceFilePathSet)) |
|
517 { |
|
518 size_t found; |
|
519 std::string folder; |
|
520 found=aFileName.find("private\\10003a3f\\"); |
|
521 |
|
522 if( found != string::npos ) |
|
523 folder = aFileName.substr(0,found); |
|
524 else |
|
525 { |
|
526 std::string errMsg= "Failed : Resource File Path should contain \\private\\10003a3f\\"; |
|
527 throw CResourceFileException(errMsg); |
|
528 } |
|
529 |
|
530 return folder; |
|
531 } |
|
532 else |
|
533 return wstring2string(aParamList->RomDrivePath()); |
|
534 } |
|
535 |
|
536 |
|
537 /** |
|
538 * Generate XML for Class AppInfoReader and call the function to Update Installation Information in Database using SRCTOOL |
|
539 */ |
|
540 void ReadApplicationInformationFromResourceFilesL(XmlDetails::TScrPreProvisionDetail& aScrPreProvisionDetail, |
|
541 const std::string& aFileName,const CParameterList* aParamList, |
|
542 const CInterpretSIS& aInterpretSis, int& aNewFileFlag) |
|
543 { |
|
544 |
|
545 std::string LocalizePath = GetLocalizeFilePath(aFileName, aParamList); |
|
546 |
|
547 CAppInfoReader* appInfoReader = NULL; |
|
548 appInfoReader = CAppInfoReader::NewL(aFileName, NullUid, LocalizePath); |
|
549 if (!appInfoReader) |
|
550 { |
|
551 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
552 throw CResourceFileException(errMsg); |
|
553 } |
|
554 else |
|
555 { |
|
556 TBool readSuccessful=EFalse; |
|
557 |
|
558 readSuccessful= appInfoReader->ReadL(); |
|
559 |
|
560 if (readSuccessful) |
|
561 { |
|
562 const SisRegistry* SisReg( aInterpretSis.GetSisRegistry()); |
|
563 const DbHelper* dbHelper( SisReg->GetDbHelper()); |
|
564 |
|
565 TUid aAppUid = appInfoReader->AppUid(); |
|
566 int val = dbHelper->IsAppUidInstalled(aAppUid.GetUid()); |
|
567 if(!val) |
|
568 { |
|
569 aNewFileFlag = 1; |
|
570 // for sis file entries the software type would always be Native. |
|
571 aScrPreProvisionDetail.iSoftwareTypeName = L"native";; |
|
572 |
|
573 XmlDetails::TScrPreProvisionDetail::TComponent component; |
|
574 CreateApplicationRegistrationInfoL(component,appInfoReader); |
|
575 aScrPreProvisionDetail.iComponents.push_back(component); |
|
576 } |
|
577 else |
|
578 { |
|
579 std::cout<<",Ignoring : AppUid "<<hex<<aAppUid.iUid<<" already present in SCR."; |
|
580 } |
|
581 } |
|
582 else |
|
583 { |
|
584 delete appInfoReader; |
|
585 std::string errMsg= "Reading Resource File failed."; |
|
586 throw CResourceFileException(errMsg); |
|
587 } |
|
588 delete appInfoReader; |
|
589 } |
|
590 |
|
591 } |
|
592 |
|
593 /** |
|
594 * Parse the Directory for resource file. |
|
595 */ |
|
596 |
|
597 void ParseResourceDir(const CParameterList* aParamList, const CInterpretSIS& aInterpretSis) |
|
598 { |
|
599 std::wstring aFilePath; |
|
600 int iNewFileFlag = 0; |
|
601 |
|
602 if ( aParamList->IsFlagSet(CParameterList::EFlagsResourceFilePathSet)) |
|
603 { |
|
604 aFilePath = aParamList->ResourceFilePath(); |
|
605 } |
|
606 else |
|
607 { |
|
608 aFilePath = aParamList->RomDrivePath(); |
|
609 aFilePath.append(L"\\private\\10003a3f\\apps"); |
|
610 } |
|
611 |
|
612 int iCount = 0; |
|
613 std::list<std::wstring> regDirs; |
|
614 GetDirContents( aFilePath, regDirs ); |
|
615 |
|
616 // store the object in registry database |
|
617 XmlDetails::TScrPreProvisionDetail scrPreProvisionDetail; |
|
618 |
|
619 std::list<std::wstring>::iterator curr = regDirs.begin(); |
|
620 for( curr = regDirs.begin(); curr != regDirs.end(); ++curr ) |
|
621 { |
|
622 |
|
623 if(aParamList->RegistryVersionExists()) |
|
624 { |
|
625 std::string errMsg= "Database not updated. SIS Registry version file present.\n Remove file RomDrive\\system\\data\\sisregistry_*.txt"; |
|
626 throw CResourceFileException(errMsg); |
|
627 } |
|
628 |
|
629 try |
|
630 { |
|
631 if (curr->find(AppResourceFileExtension,0) != std::wstring::npos) |
|
632 { |
|
633 iCount++; |
|
634 std::string fName; |
|
635 fName = Ucs2ToUtf8( *curr ); |
|
636 std::string FilePath = wstring2string(aFilePath); |
|
637 FilePath.append("\\"); |
|
638 FilePath.append(fName); |
|
639 std::cout<<"Parsing - "<<fName<<" "; |
|
640 ReadApplicationInformationFromResourceFilesL(scrPreProvisionDetail,FilePath,aParamList,aInterpretSis,iNewFileFlag); |
|
641 std::cout<<" "<<std::endl; |
|
642 } |
|
643 } |
|
644 catch(const CResourceFileException& aObject) |
|
645 { |
|
646 //LERROR(L"Resource File Parsing Error - "); |
|
647 //aObject.Display(); |
|
648 } |
|
649 } |
|
650 |
|
651 if(iNewFileFlag) |
|
652 UpdateInstallationInformation_xml(aParamList,scrPreProvisionDetail); |
|
653 |
|
654 if(!iCount) |
|
655 LERROR(L"Failed : No Resource File in the Directory Specified - "); |
|
656 } |
|
657 |
|
658 /** |
|
659 * Backup hash files for re-installation (SA over SA or PU over PU) |
|
660 */ |
|
661 void BackupHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath) |
|
662 { |
|
663 std::wstring hashdir = L"$:\\sys\\hash\\"; |
|
664 std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ; |
|
665 if (basename.size() == 0) |
|
666 { |
|
667 basename = aFile.substr(aFile.rfind(L"\\")); |
|
668 } |
|
669 |
|
670 hashdir[0] = aDriveLetter; |
|
671 std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename; |
|
672 |
|
673 if (FileExists(hashFile)) |
|
674 { |
|
675 std::string iLocalFile = wstring2string(hashFile); |
|
676 std::string iBackupFile = wstring2string(hashFile); |
|
677 iBackupFile.append("_backup"); |
|
678 |
|
679 int err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0); |
|
680 if (err == 0) |
|
681 LERROR(L"Failed to Backup hash file "); |
|
682 } |
|
683 } |
|
684 |
|
685 /** |
|
686 * Restore hash files for re-installation (SA over SA or PU over PU) |
|
687 */ |
|
688 void RestoreHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath) |
|
689 { |
|
690 std::wstring hashdir = L"$:\\sys\\hash\\"; |
|
691 std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ; |
|
692 if (basename.size() == 0) |
|
693 { |
|
694 basename = aFile.substr(aFile.rfind(L"\\")); |
|
695 } |
|
696 |
|
697 hashdir[0] = aDriveLetter; |
|
698 std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename; |
|
699 std::wstring LocalFile(hashFile); |
|
700 hashFile.append(L"_backup"); |
|
701 |
|
702 if (FileExists(hashFile)) |
|
703 { |
|
704 std::string iLocalFile = wstring2string(LocalFile); |
|
705 std::string iBackupFile = wstring2string(hashFile); |
|
706 |
|
707 int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str()); |
|
708 |
|
709 if (err == 0) |
|
710 LERROR(L"Failed to Restore hash file "); |
|
711 } |
|
712 } |
|
713 |
|
714 /** |
|
715 * Returns the size of the first occurance of an invalid directory separator. |
|
716 * @param aPath Path to be validated. |
|
717 * @param aIndex index from which the search begin. On function return this |
|
718 * index will point to the illegal directory separator. |
|
719 * @return 0 if path is valid. Else the number of character to be replaced. |
|
720 * e.g. /sys/bin/ should be replaced with \sys\bin\ |
|
721 * and //sys//bin// should be replaced with \sys\bin\ |
|
722 */ |
|
723 |
|
724 // Constants |
|
725 const std::wstring KSisDirectorySeparatortap( L"\\" ); |
|
726 |
|
727 int FirstInvalidDirSeparatorSizetap(std::wstring& aPath, std::wstring::size_type& aIndex) |
|
728 { |
|
729 // If path semantics is correct (as needed by sisx library) |
|
730 // then the function will return 0 |
|
731 int ret = 0; |
|
732 int pos = 0; |
|
733 if((pos = aPath.find(L"//", aIndex)) != std::wstring::npos) |
|
734 { |
|
735 ret = 2; |
|
736 } |
|
737 else if((pos = aPath.find(L"/", aIndex)) != std::wstring::npos) |
|
738 { |
|
739 ret = 1; |
|
740 } |
|
741 aIndex = pos; |
|
742 return ret; |
|
743 } |
|
744 |
|
745 std::wstring FixPathDelimiterstap( const std::wstring& aString ) |
|
746 { |
|
747 std::wstring ret = aString; |
|
748 std::wstring::size_type idx = 0; |
|
749 int len = 0; |
|
750 while(len = FirstInvalidDirSeparatorSizetap(ret, idx)) |
|
751 { |
|
752 ret.replace( idx, len, KSisDirectorySeparatortap ); |
|
753 } |
|
754 return ret; |
|
755 } |