1 /* |
|
2 * Copyright (c) 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 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 * Implementation of the adorned filename handling utility functions |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "appregextractor.h" |
|
20 #include "sishelper.h" |
|
21 |
|
22 namespace Swi |
|
23 { |
|
24 |
|
25 /*static*/ CAppRegExtractor* CAppRegExtractor::NewLC(RFs& aFs, RArray<TLanguage> deviceSupportedLanguages, RPointerArray<Usif::CApplicationRegistrationData>& aApparcRegFileData ) |
|
26 { |
|
27 CAppRegExtractor* self=new(ELeave) CAppRegExtractor(aFs, deviceSupportedLanguages, aApparcRegFileData); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /*static*/ CAppRegExtractor* CAppRegExtractor::NewL(RFs& aFs, RArray<TLanguage> deviceSupportedLanguages, RPointerArray<Usif::CApplicationRegistrationData>& aApparcRegFileData ) |
|
34 { |
|
35 CAppRegExtractor* self=NewLC(aFs, deviceSupportedLanguages, aApparcRegFileData); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CAppRegExtractor::~CAppRegExtractor() |
|
41 { |
|
42 Deque(); |
|
43 |
|
44 if (iManagedFileHandle) |
|
45 { |
|
46 iCurrentFile->Close(); |
|
47 delete iCurrentFile; |
|
48 } |
|
49 |
|
50 iLauncher.Close(); |
|
51 |
|
52 if (iDeviceSupportedLanguages.Count()) |
|
53 iDeviceSupportedLanguages.Close(); |
|
54 } |
|
55 |
|
56 CAppRegExtractor::CAppRegExtractor(RFs& aFs, RArray<TLanguage> deviceSupportedLanguages, RPointerArray<Usif::CApplicationRegistrationData>& aApparcRegFileData) |
|
57 : CActive(EPriorityStandard), iFs(aFs), iDeviceSupportedLanguages(deviceSupportedLanguages), iApparcRegFileData(aApparcRegFileData) |
|
58 { |
|
59 CActiveScheduler::Add(this); |
|
60 } |
|
61 |
|
62 void CAppRegExtractor::ConstructL() |
|
63 { |
|
64 User::LeaveIfError(iFs.ShareProtected()); |
|
65 User::LeaveIfError(iLauncher.Connect()); |
|
66 } |
|
67 |
|
68 // public methods |
|
69 |
|
70 void CAppRegExtractor::ExtractAppRegInfoSizeL(const TDesC& aFileName, TRequestStatus& aStatus) |
|
71 { |
|
72 DEBUG_PRINTF2(_L("CAppRegExtractor - ExtractAppRegInfoSizeL - extracting size of resource file '%S'"),&aFileName); |
|
73 iErrCode = KErrNone; |
|
74 iManagedFileHandle=ETrue; |
|
75 iCancelled=EFalse; |
|
76 iClientStatus=&aStatus; |
|
77 if(iCurrentFile != NULL) |
|
78 delete iCurrentFile; |
|
79 iCurrentFile=new(ELeave) RFile; |
|
80 User::LeaveIfError(iCurrentFile->Open(iFs, aFileName, EFileRead)); |
|
81 *iClientStatus = KRequestPending; |
|
82 |
|
83 iLauncher.AsyncParseResourceFileSizeL(*iCurrentFile, iDeviceSupportedLanguages, iStatus); |
|
84 SetActive(); |
|
85 } |
|
86 |
|
87 |
|
88 // CActive methods |
|
89 |
|
90 void CAppRegExtractor::RunL() |
|
91 { |
|
92 //iStatus shall have the lenght of parsed object if it is greater than 0 |
|
93 if (iStatus.Int() < KErrNone ) |
|
94 { |
|
95 DEBUG_PRINTF2(_L("CAppRegExtractor - RunL - parsing failed with %d error"),iStatus.Int()); |
|
96 User::LeaveIfError(FinishAppRegExtraction(iStatus.Int())); |
|
97 return; |
|
98 } |
|
99 |
|
100 if (iCancelled) |
|
101 { |
|
102 DEBUG_PRINTF(_L("CAppRegExtractor - RunL - User cancelled")); |
|
103 User::LeaveIfError(FinishAppRegExtraction(KErrCancel)); |
|
104 return; |
|
105 } |
|
106 |
|
107 TInt size = iStatus.Int(); |
|
108 Usif::CApplicationRegistrationData* applicationRegistrationData = 0; |
|
109 DEBUG_PRINTF2(_L("CAppRegExtractor - ParseResourceFileDataL - Invoking with size = %d"),size); |
|
110 applicationRegistrationData = iLauncher.AsyncParseResourceFileDataL(size); |
|
111 CleanupStack::PushL(applicationRegistrationData); |
|
112 iApparcRegFileData.AppendL(applicationRegistrationData); |
|
113 CleanupStack::Pop(); |
|
114 FinishAppRegExtraction(KErrNone); |
|
115 // Extract the next chunk |
|
116 } |
|
117 |
|
118 void CAppRegExtractor::DoCancel() |
|
119 { |
|
120 DEBUG_PRINTF(_L("CAppRegExtractor - DoCancel - User cancelled")); |
|
121 iCancelled=ETrue; |
|
122 if (iClientStatus) |
|
123 { |
|
124 TInt err = FinishAppRegExtraction(KErrCancel); |
|
125 if (err != KErrNone) |
|
126 { |
|
127 User::RequestComplete(iClientStatus, KErrCancel); |
|
128 iClientStatus=NULL; |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 TInt CAppRegExtractor::RunError(TInt aError) |
|
134 { |
|
135 DEBUG_PRINTF(_L("CAppRegExtractor - DoError")); |
|
136 iCancelled = ETrue; |
|
137 if (iClientStatus) |
|
138 { |
|
139 TInt err = FinishAppRegExtraction(aError); |
|
140 if (err != KErrNone) |
|
141 { |
|
142 User::RequestComplete(iClientStatus, aError); |
|
143 iClientStatus = NULL; |
|
144 } |
|
145 } |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 TInt CAppRegExtractor::FinishAppRegExtraction(TInt aResult) |
|
150 { |
|
151 DEBUG_PRINTF2(_L("CAppRegExtractor - FinishAppRegExtraction - received result = %d"),aResult); |
|
152 if (iManagedFileHandle) |
|
153 { |
|
154 iCurrentFile->Close(); |
|
155 delete iCurrentFile; |
|
156 iCurrentFile=0; |
|
157 iManagedFileHandle = EFalse; |
|
158 } |
|
159 iErrCode = aResult; |
|
160 |
|
161 // notify the user |
|
162 if (aResult == KErrCorrupt) |
|
163 { |
|
164 User::RequestComplete(iClientStatus, KErrNone); |
|
165 } |
|
166 else |
|
167 { |
|
168 User::RequestComplete(iClientStatus, aResult); |
|
169 } |
|
170 iClientStatus = NULL; |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 TInt CAppRegExtractor::GetErrorCode() const |
|
175 { |
|
176 return iErrCode; |
|
177 } |
|
178 |
|
179 } |
|
180 |
|