|
1 /* |
|
2 * Copyright (c) 2006-2006 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: Global methods for brandinstaller |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <eikenv.h> |
|
21 #include <f32file.h> |
|
22 #include <e32property.h> |
|
23 |
|
24 #include "cbsimportmanager.h" |
|
25 #include "importlogwriter.h" |
|
26 #include "bsbrandremover.h" |
|
27 |
|
28 namespace |
|
29 { |
|
30 |
|
31 // CONSTANTS |
|
32 // |
|
33 _LIT( KProcessName, "BSInstall" ); |
|
34 |
|
35 // Search these files for processing |
|
36 _LIT( KInstallFiles, "*.xml" ); |
|
37 |
|
38 // Path to installed xml files inside own private folder. |
|
39 _LIT( KInstallPath, "import\\" ); |
|
40 _LIT( KInstallDrive, "C:" ); |
|
41 |
|
42 // separators for uninstalled brands |
|
43 _LIT( KLineFeed, "\n" ); |
|
44 _LIT( KBrandSeparator, "$" ); |
|
45 |
|
46 // Pub & sub keys for uninstall buffer |
|
47 const TInt KBrandingServerUid = 0x102828DD; |
|
48 const TUint KUninstallKey = 0x01; |
|
49 } |
|
50 |
|
51 // ======== GLOBAL FUNCTIONS ======== |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // DeleteRPtrArray |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 LOCAL_C void DeleteRPtrArray( TAny* aArray ) |
|
58 { |
|
59 RPointerArray<HBufC>* array = static_cast< RPointerArray<HBufC>* >(aArray); |
|
60 TInt count = array->Count(); |
|
61 for( TInt i = 0; i < count; i++ ) |
|
62 { |
|
63 delete (*array)[i]; |
|
64 } |
|
65 array->Reset(); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // ParseInstallableBrandsL |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 LOCAL_C void ParseInstallableBrandsL( RFs& aFs, RPointerArray<HBufC>& aFiles ) |
|
73 { |
|
74 IMPORT_DP_TXT("ParseInstallableBrandsL begin"); |
|
75 // list import content |
|
76 CDir* dir = NULL; |
|
77 TPath privatePath; |
|
78 aFs.PrivatePath( privatePath ); |
|
79 privatePath.Insert( 0, KInstallDrive ); |
|
80 privatePath.Append( KInstallPath ); |
|
81 |
|
82 TFileName find( privatePath ); |
|
83 find.Append( KInstallFiles ); |
|
84 User::LeaveIfError( |
|
85 aFs.GetDir( find, KEntryAttNormal, ESortNone, dir ) ); |
|
86 CleanupStack::PushL( dir ); |
|
87 |
|
88 // create array of files (as text) |
|
89 TInt count = dir->Count(); |
|
90 for( TInt i = 0; i < count; i++ ) |
|
91 { |
|
92 TFileName file( privatePath ); |
|
93 file.Append( (*dir)[i].iName ); |
|
94 aFiles.Append( file.AllocL() ); |
|
95 } |
|
96 |
|
97 CleanupStack::PopAndDestroy( dir ); |
|
98 IMPORT_DP_TXT("ParseInstallableBrandsL end"); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // Uninstall |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 LOCAL_C void UninstallL() |
|
106 { |
|
107 |
|
108 // Get uninstalled brands |
|
109 HBufC* dataBuf = HBufC::NewLC( RProperty::KMaxPropertySize ); |
|
110 |
|
111 HBufC* newDataBuf = HBufC::NewLC( RProperty::KMaxPropertySize ); |
|
112 TPtr newData( newDataBuf->Des() ); |
|
113 TBool error( EFalse ); |
|
114 |
|
115 TPtr data( dataBuf->Des() ); |
|
116 RProperty::Get( TUid::Uid( KBrandingServerUid ), KUninstallKey, data ); |
|
117 |
|
118 //IMPORT_DP( D_IMPORT_LIT( "Property data='%S'" ), &data ); |
|
119 |
|
120 TPtrC processing( data ); |
|
121 while( processing.Length() > 0 ) |
|
122 { |
|
123 // get first brand from buffer |
|
124 TInt pos = processing.Find( KLineFeed ); |
|
125 TPtrC brand( (pos >= 0) ? processing.Left( pos ) : processing ); |
|
126 if( pos == KErrNotFound ) |
|
127 { |
|
128 // this was last item. reset process. |
|
129 processing.Set( KNullDesC ); |
|
130 } |
|
131 else |
|
132 { |
|
133 // cut out the brand part from processing |
|
134 processing.Set( processing.Mid( brand.Length() + 1 ) ); |
|
135 } |
|
136 |
|
137 // divide brand |
|
138 TInt sepPos = brand.Find( KBrandSeparator ); |
|
139 if( sepPos != KErrNotFound ) |
|
140 { |
|
141 // remove brand |
|
142 TRAPD( err, BSBrandRemover::RemoveBrandL( |
|
143 brand.Left( sepPos ), brand.Mid( sepPos + 1 ) ) ); |
|
144 //If the brand removal failed and due to a KErrInUse errorcode, |
|
145 //it must not be deleted from the property-->try to delete next |
|
146 //time again! in any other case, we simply delete the un- |
|
147 //uninstallation string from the RProperty. |
|
148 //NOTE also: Since we check here for an errorcode that is (probably) |
|
149 //raised in CBSSession.cpp by calling User::Leave, it has to be |
|
150 //considered whether the condition of the following if statement |
|
151 //has to be updated or not, if the errorcode of that User::Leave |
|
152 //in CBSSession.cpp is modified. |
|
153 if ( KErrInUse == err ) |
|
154 { |
|
155 error = ETrue; |
|
156 if( newData.Length() > 0 ) |
|
157 { |
|
158 newData.Append( KLineFeed ); |
|
159 } |
|
160 newData.Append( brand ); |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 // Reset uninstall buffer |
|
166 if ( error ) |
|
167 { |
|
168 if( newData.Length() <= RProperty::KMaxPropertySize ) |
|
169 { |
|
170 User::LeaveIfError( RProperty::Set( TUid::Uid( KBrandingServerUid ), |
|
171 KUninstallKey, |
|
172 newData ) ); |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 RProperty::Set( TUid::Uid( KBrandingServerUid ), |
|
178 KUninstallKey, |
|
179 KNullDesC ); |
|
180 } |
|
181 CleanupStack::PopAndDestroy( newDataBuf ); |
|
182 CleanupStack::PopAndDestroy( dataBuf ); |
|
183 |
|
184 IMPORT_DP_TXT("UninstallL end"); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // MainL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 LOCAL_C void MainL() |
|
192 { |
|
193 IMPORT_DP_TXT("MainL begin"); |
|
194 // Codescanner warning: User of non-pointer/refer3ence RFs (Id:76) |
|
195 // this code cannot get file server handle from anywhere, so it has to be |
|
196 // created here |
|
197 RFs fs; // CSI: 76 # See above |
|
198 User::LeaveIfError( fs.Connect() ); |
|
199 CleanupClosePushL( fs ); |
|
200 |
|
201 // Uninstall removed brands |
|
202 TRAP_IGNORE( UninstallL() ); |
|
203 |
|
204 // find new xml files |
|
205 RPointerArray<HBufC> files; |
|
206 CleanupStack::PushL( TCleanupItem( DeleteRPtrArray, &files ) ); |
|
207 ParseInstallableBrandsL( fs, files); |
|
208 |
|
209 // convert PointerArray to MDesCArray |
|
210 |
|
211 TInt count = files.Count(); |
|
212 if(count) |
|
213 { |
|
214 |
|
215 // Do install |
|
216 CBSImportManager* installer = CBSImportManager::NewLC(); |
|
217 |
|
218 for( TInt i = 0; i < count; i++ ) |
|
219 { |
|
220 TRAPD( err, installer->ImportFileL( *(files[i]) ) ); |
|
221 // only delete the xml file if the installation succeeded; ignore errors. |
|
222 // If there is a reason to save these files, then change this to |
|
223 // move operation. |
|
224 if ( KErrNone == err ) |
|
225 { |
|
226 fs.Delete( *(files[i]) ); |
|
227 } |
|
228 } |
|
229 |
|
230 //User::LeaveIfError( err ); //TODO: should we still leave at this point? |
|
231 CleanupStack::PopAndDestroy( installer ); |
|
232 |
|
233 } |
|
234 CleanupStack::PopAndDestroy( 2 ); // files, fs |
|
235 IMPORT_DP_TXT("MainL end"); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // Main function of the application executable. |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 GLDEF_C TInt E32Main() |
|
243 { |
|
244 __UHEAP_MARK; |
|
245 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
246 TInt returnCode( KErrNone ); |
|
247 IMPORT_DP_TXT("----- NEW IMPORT SESSION ------( INSTALLER )---"); |
|
248 User::RenameThread( KProcessName ); |
|
249 TRAPD( error, MainL() ); |
|
250 if( error ) |
|
251 { |
|
252 IMPORT_DP( D_IMPORT_LIT( "ERROR installing brand: %d" ), error ); |
|
253 } |
|
254 IMPORT_DP_TXT("-----------------------------------------------"); |
|
255 __ASSERT_ALWAYS( !error, User::Panic( KProcessName, error ) ); |
|
256 delete cleanup; |
|
257 __UHEAP_MARKEND; |
|
258 return returnCode; |
|
259 } |