|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "fileextractor.h" |
|
20 #include "progressbar.h" |
|
21 #include "sishelper.h" |
|
22 #include "sisuihandler.h" |
|
23 |
|
24 #include "sisregistryfiledescription.h" |
|
25 |
|
26 namespace Swi |
|
27 { |
|
28 |
|
29 /*static*/ CFileExtractor* CFileExtractor::NewLC(RFs& aFs, RSisHelper& aSisHelper, RUiHandler& aUiHandler, const TAppInfo& aAppInfo) |
|
30 { |
|
31 CFileExtractor* self=new(ELeave) CFileExtractor(aFs, aSisHelper, aUiHandler, aAppInfo); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 /*static*/ CFileExtractor* CFileExtractor::NewL(RFs& aFs, RSisHelper& aSisHelper, RUiHandler& aUiHandler, const TAppInfo& aAppInfo) |
|
38 { |
|
39 CFileExtractor* self=NewLC(aFs, aSisHelper, aUiHandler, aAppInfo); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CFileExtractor::~CFileExtractor() |
|
45 { |
|
46 Deque(); |
|
47 |
|
48 if (iManagedFileHandle) |
|
49 { |
|
50 iCurrentFile->Close(); |
|
51 delete iCurrentFile; |
|
52 } |
|
53 delete iFileDescription; |
|
54 } |
|
55 |
|
56 CFileExtractor::CFileExtractor(RFs& aFs, RSisHelper& aSisHelper, RUiHandler& aUiHandler, const TAppInfo& aAppInfo) |
|
57 : CActive(EPriorityStandard), iFs(aFs), iSisHelper(aSisHelper), iUiHandler(aUiHandler), iAppInfo(aAppInfo) |
|
58 { |
|
59 CActiveScheduler::Add(this); |
|
60 } |
|
61 |
|
62 void CFileExtractor::ConstructL() |
|
63 { |
|
64 User::LeaveIfError(iFs.ShareProtected()); |
|
65 } |
|
66 |
|
67 // public methods |
|
68 |
|
69 void CFileExtractor::ExtractFileL(TInt aDataUnit, const CSisRegistryFileDescription& aFileDescription, const TDesC& aFileName, TRequestStatus& aStatus) |
|
70 { |
|
71 iManagedFileHandle=ETrue; |
|
72 |
|
73 iCurrentFile=new(ELeave) RFile; |
|
74 User::LeaveIfError(iCurrentFile->Replace(iFs, aFileName, EFileWrite)); |
|
75 |
|
76 ExtractFileL(aDataUnit, aFileDescription, *iCurrentFile, aStatus); |
|
77 } |
|
78 |
|
79 |
|
80 void CFileExtractor::ExtractFileL(TInt aDataUnit, const CSisRegistryFileDescription& aFileDescription, RFile& aFile, TRequestStatus& aStatus) |
|
81 { |
|
82 iCancelled=EFalse; |
|
83 iClientStatus=&aStatus; |
|
84 iCurrentFile=&aFile; |
|
85 iBytesToExtract=aFileDescription.UncompressedLength(); |
|
86 iDataUnit=aDataUnit; |
|
87 |
|
88 delete iFileDescription; |
|
89 iFileDescription=0; |
|
90 iFileDescription=CSisRegistryFileDescription::NewL(aFileDescription); |
|
91 |
|
92 |
|
93 *iClientStatus=KRequestPending; |
|
94 |
|
95 iSisHelper.SetupAsyncExtractionL(iFs, *iCurrentFile, iFileDescription->Index(), iDataUnit); |
|
96 |
|
97 TRequestStatus* status=&iStatus; |
|
98 User::RequestComplete(status, KErrNone); |
|
99 SetActive(); |
|
100 } |
|
101 |
|
102 |
|
103 TInt CFileExtractor::FinishExtraction(TInt aResult) |
|
104 { |
|
105 TRAPD(err, iSisHelper.EndAsyncExtractionL()); |
|
106 if (err != KErrNone) |
|
107 return err; |
|
108 |
|
109 if (iManagedFileHandle) |
|
110 { |
|
111 iCurrentFile->Close(); |
|
112 delete iCurrentFile; |
|
113 iCurrentFile=0; |
|
114 iManagedFileHandle = EFalse; |
|
115 } |
|
116 |
|
117 if (aResult==KErrNone) |
|
118 { |
|
119 // The progress bar should always be incremented at the end of a successful extraction |
|
120 TRAPD(err, iUiHandler.UpdateProgressBarL(iAppInfo, KProgressBarEndIncrement)); |
|
121 if (err != KErrNone) |
|
122 return err; |
|
123 } |
|
124 |
|
125 // notify the user |
|
126 User::RequestComplete(iClientStatus, aResult); |
|
127 iClientStatus = NULL; |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 // CActive methods |
|
132 |
|
133 void CFileExtractor::RunL() |
|
134 { |
|
135 if (iStatus.Int() != KErrNone) |
|
136 { |
|
137 User::LeaveIfError(FinishExtraction(iStatus.Int())); |
|
138 return; |
|
139 } |
|
140 |
|
141 if (iCancelled) |
|
142 { |
|
143 User::LeaveIfError(FinishExtraction(KErrCancel)); |
|
144 return; |
|
145 } |
|
146 |
|
147 TInt32 chunkSize=iBytesToExtract > KProgressBarInstallChunkSize ? KProgressBarInstallChunkSize : iBytesToExtract; |
|
148 |
|
149 if (chunkSize==0) |
|
150 { |
|
151 User::LeaveIfError(FinishExtraction(KErrNone)); |
|
152 return; |
|
153 } |
|
154 |
|
155 // Extract the next chunk |
|
156 iUiHandler.UpdateProgressBarL(iAppInfo, ProgressBarChunkIncrement(chunkSize)); |
|
157 iSisHelper.AsyncExtractionL(chunkSize, iStatus); |
|
158 iBytesToExtract-=chunkSize; |
|
159 SetActive(); |
|
160 } |
|
161 |
|
162 void CFileExtractor::DoCancel() |
|
163 { |
|
164 iCancelled=ETrue; |
|
165 if (iClientStatus) |
|
166 { |
|
167 TInt err = FinishExtraction(KErrCancel); |
|
168 if (err != KErrNone) |
|
169 { |
|
170 User::RequestComplete(iClientStatus, KErrCancel); |
|
171 iClientStatus=NULL; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 TInt CFileExtractor::RunError(TInt aError) |
|
177 { |
|
178 iCancelled = ETrue; |
|
179 if (iClientStatus) |
|
180 { |
|
181 TInt err = FinishExtraction(aError); |
|
182 if (err != KErrNone) |
|
183 { |
|
184 User::RequestComplete(iClientStatus, aError); |
|
185 iClientStatus = NULL; |
|
186 } |
|
187 } |
|
188 return KErrNone; |
|
189 } |
|
190 |
|
191 |
|
192 } |
|
193 |