42 // |
42 // |
43 void CCaSqLiteStorage::ConstructL() |
43 void CCaSqLiteStorage::ConstructL() |
44 { |
44 { |
45 User::LeaveIfError( iRfs.Connect() ); |
45 User::LeaveIfError( iRfs.Connect() ); |
46 |
46 |
47 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDriveDb, KCDrive, |
47 User::LeaveIfError( |
48 KDbName ) ); |
48 CreatePrivateDirPath( iPrivatePathCDriveDb, KCDrive, KDbName ) ); |
49 |
49 User::LeaveIfError( |
50 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathZDriveDb, KZDrive, |
50 CreatePrivateDirPath( iPrivatePathZDriveDb, KZDrive, KDbName ) ); |
51 KDbName ) ); |
51 User::LeaveIfError( |
52 |
52 CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, KNullDesC ) ); |
53 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, |
53 User::LeaveIfError( |
54 KNullDesC ) ); |
54 CreatePrivateDirPath( |
55 |
55 iPrivatePathCDriveDbBackup, KCDrive, KDbNameBackup ) ); |
56 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDriveDbBackup, KCDrive, |
|
57 KDbNameBackup ) ); |
|
58 |
|
59 |
56 |
60 if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) ) |
57 if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) ) |
61 { |
58 { |
62 //we could not load data base from C-drive lets try Rom |
59 //we could not load data base from C-drive lets try Rom |
63 LoadDataBaseFromRomL(); |
60 LoadDataBaseFromRomL(); |
64 } |
61 } |
65 else |
62 else |
66 { |
63 { |
67 TBuf<KCaMaxAttrNameLen> versionValue; |
64 TBuf<KCaMaxAttrNameLen> versionValue; |
68 DbPropertyL(KCaDbPropVersion, versionValue); |
65 DbPropertyL( KCaDbPropVersion, versionValue ); |
69 ASSERT(versionValue.Length()>0); |
66 ASSERT( versionValue.Length() > 0 ); |
70 if( versionValue.CompareC( KCaDbVersion ) ) |
67 if( versionValue.CompareC( KCaDbVersion ) ) |
71 { |
68 { |
72 // database loaded from C: is obsolete, load from Z: |
69 // database loaded from C: is obsolete, load from Z: |
73 iSqlDb.Close(); |
70 iSqlDb.Close(); |
74 LoadDataBaseFromRomL(); |
71 LoadDataBaseFromRomL(); |
75 } |
72 } |
76 } |
73 } |
|
74 TBuf<KCaMaxAttrNameLen> restoreValue; |
|
75 DbPropertyL( KCaDbPropRestore, restoreValue ); |
|
76 if( restoreValue.CompareC( KCaDbPropRestoreVal ) == KErrNone ) |
|
77 { |
|
78 RestoreDatabaseL(); |
|
79 } |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CCASqLiteStorage::GetDownloadedApplicationsArrayL() |
|
84 // |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CCaSqLiteStorage::GetDownloadedApplicationsArrayL( |
|
88 RPointerArray<CCaInnerEntry>& aResultArray ) |
|
89 { |
|
90 iCollectionDownloadId = GetCollectionDownloadIdL(); |
|
91 CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC(); |
|
92 downloadedQuery->SetParentId( iCollectionDownloadId ); |
|
93 GetEntriesL( downloadedQuery, aResultArray ); |
|
94 CleanupStack::PopAndDestroy( downloadedQuery ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CCASqLiteStorage::GetDownloadedApplicationsArrayL() |
|
99 // |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CCaSqLiteStorage::GetDownloadedApplicationsArrayL( |
|
103 RArray<TInt>& aResultArray ) |
|
104 { |
|
105 iCollectionDownloadId = GetCollectionDownloadIdL(); |
|
106 CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC(); |
|
107 downloadedQuery->SetParentId( iCollectionDownloadId ); |
|
108 GetEntriesIdsL( downloadedQuery, aResultArray ); |
|
109 CleanupStack::PopAndDestroy( downloadedQuery ); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CCASqLiteStorage::RestoreDownloadedApplications() |
|
114 // |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CCaSqLiteStorage::SetDownloadedApplicationsArrayL( |
|
118 RPointerArray<CCaInnerEntry>& aResultArray ) |
|
119 { |
|
120 //remove all entries from downloaded collection |
|
121 RArray<TInt> entryIds; |
|
122 CleanupClosePushL( entryIds ); |
|
123 GetDownloadedApplicationsArrayL( entryIds ); |
|
124 |
|
125 TCaOperationParams params; |
|
126 params.iOperationType = TCaOperationParams::ERemove; |
|
127 params.iGroupId = iCollectionDownloadId; |
|
128 params.iBeforeEntryId = 0; // Not Used |
|
129 ExecuteOrganizeL( entryIds, params ); |
|
130 CleanupStack::PopAndDestroy( &entryIds ); |
|
131 |
|
132 //get current downloaded applications list |
|
133 for( TInt i = aResultArray.Count() - 1; i >= 0; i-- ) |
|
134 { |
|
135 CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC(); |
|
136 RArray<TInt> entryIds; |
|
137 CleanupClosePushL( entryIds ); |
|
138 entryIds.AppendL( aResultArray[i]->GetId() ); |
|
139 downloadedQuery->SetIdsL( entryIds ); |
|
140 |
|
141 RArray<TInt> resultEntryIds; |
|
142 CleanupClosePushL( resultEntryIds ); |
|
143 GetEntriesIdsL( downloadedQuery, resultEntryIds ); |
|
144 if( !resultEntryIds.Count() ) |
|
145 { |
|
146 //its in case of application that was installed after backup |
|
147 aResultArray[i]->SetId(0); |
|
148 } |
|
149 //there could be some icon added to db aster backup |
|
150 //( after update or installation of applicatiotion ) |
|
151 aResultArray[i]->SetIconId(0); |
|
152 |
|
153 CleanupStack::PopAndDestroy( &resultEntryIds ); |
|
154 CleanupStack::PopAndDestroy( &entryIds ); |
|
155 CleanupStack::PopAndDestroy( downloadedQuery ); |
|
156 } |
|
157 |
|
158 //add applications to downloaded collection |
|
159 for( TInt i = 0; i < aResultArray.Count(); i++ ) |
|
160 { |
|
161 AddL( aResultArray[i] ); |
|
162 } |
|
163 params.iOperationType = TCaOperationParams::EAppend; |
|
164 ExecuteOrganizeL( aResultArray, params ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // |
|
169 // --------------------------------------------------------- |
|
170 // |
|
171 void CCaSqLiteStorage::ExecuteOrganizeL( |
|
172 const RPointerArray<CCaInnerEntry> & aResultArray, |
|
173 TCaOperationParams params) |
|
174 { |
|
175 RArray<TInt> restoredEntryIds; |
|
176 CleanupClosePushL(restoredEntryIds); |
|
177 for( TInt i = 0; i < aResultArray.Count(); i++ ) |
|
178 { |
|
179 restoredEntryIds.AppendL( aResultArray[i]->GetId() ); |
|
180 } |
|
181 ExecuteOrganizeL( restoredEntryIds, params ); |
|
182 CleanupStack::PopAndDestroy( &restoredEntryIds ); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 TInt CCaSqLiteStorage::GetCollectionDownloadIdL() |
|
190 { |
|
191 TInt downloadId( KErrNotFound ); |
|
192 RPointerArray<CCaInnerEntry> resultArray; |
|
193 CleanupResetAndDestroyPushL( resultArray ); |
|
194 CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC(); |
|
195 CDesC16ArrayFlat* appType = |
|
196 new ( ELeave ) CDesC16ArrayFlat( KGranularityOne ); |
|
197 CleanupStack::PushL( appType ); |
|
198 appType->AppendL( KCaTypeCollectionDownload ); |
|
199 allAppQuery->SetEntryTypeNames( appType ); |
|
200 CleanupStack::Pop( appType ); |
|
201 GetEntriesL( allAppQuery, resultArray ); |
|
202 CleanupStack::PopAndDestroy( allAppQuery ); |
|
203 if( resultArray.Count() ) |
|
204 { |
|
205 downloadId = resultArray[0]->GetId(); |
|
206 } |
|
207 CleanupStack::PopAndDestroy( &resultArray ); |
|
208 return downloadId; |
77 } |
209 } |
78 |
210 |
79 // --------------------------------------------------------------------------- |
211 // --------------------------------------------------------------------------- |
80 // CCASqLiteStorage::NewL() |
212 // CCASqLiteStorage::NewL() |
81 // |
213 // |
109 &KSqlDbConfig ) ); |
241 &KSqlDbConfig ) ); |
110 } |
242 } |
111 } |
243 } |
112 |
244 |
113 // --------------------------------------------------------------------------- |
245 // --------------------------------------------------------------------------- |
114 // |
246 // |
115 // |
247 // |
116 // --------------------------------------------------------------------------- |
248 // --------------------------------------------------------------------------- |
117 // |
249 // |
118 void CCaSqLiteStorage::SaveDatabaseL() |
250 void CCaSqLiteStorage::SaveDatabaseL() |
119 { |
251 { |
120 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) ) |
252 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) ) |
121 { |
253 { |
122 iSqlDb.Close(); |
254 iSqlDb.Close(); |
123 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
255 User::LeaveIfError( BaflUtils::CopyFile( |
124 iPrivatePathCDriveDb, iPrivatePathCDriveDbBackup ) ); |
256 iRfs, iPrivatePathCDriveDb, iPrivatePathCDriveDbBackup ) ); |
125 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
257 User::LeaveIfError( iSqlDb.Open( |
126 &KSqlDbConfig ) ); |
258 iPrivatePathCDriveDb, &KSqlDbConfig ) ); |
127 } |
259 } |
128 } |
260 } |
129 |
261 |
130 // --------------------------------------------------------------------------- |
262 // --------------------------------------------------------------------------- |
131 // |
263 // |
132 // |
264 // |
133 // --------------------------------------------------------------------------- |
265 // --------------------------------------------------------------------------- |
134 // |
266 // |
135 void CCaSqLiteStorage::RestoreDatabaseL() |
267 void CCaSqLiteStorage::RestoreDatabaseL() |
136 { |
268 { |
137 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDbBackup ) ) ) |
269 if( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDbBackup ) ) |
138 { |
270 { |
|
271 RPointerArray<CCaInnerEntry> resultArray; |
|
272 CleanupResetAndDestroyPushL( resultArray ); |
|
273 //get current downloaded applications list |
|
274 GetDownloadedApplicationsArrayL( resultArray ); |
|
275 |
139 iSqlDb.Close(); |
276 iSqlDb.Close(); |
140 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
277 User::LeaveIfError( BaflUtils::CopyFile( |
141 iPrivatePathCDriveDbBackup, iPrivatePathCDriveDb ) ); |
278 iRfs, iPrivatePathCDriveDbBackup, iPrivatePathCDriveDb ) ); |
142 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
279 User::LeaveIfError( iSqlDb.Open( |
143 &KSqlDbConfig ) ); |
280 iPrivatePathCDriveDb, &KSqlDbConfig ) ); |
144 } |
281 |
|
282 //set current downloaded applications list to backuped |
|
283 //downloaded collection |
|
284 SetDownloadedApplicationsArrayL( resultArray ); |
|
285 CleanupStack::PopAndDestroy( &resultArray ); |
|
286 } |
|
287 SetDBPropertyL( KCaDbPropRestore, KCaDbPropNoRestoreVal ); |
145 } |
288 } |
146 |
289 |
147 // --------------------------------------------------------------------------- |
290 // --------------------------------------------------------------------------- |
148 // CCASqLiteStorage::NewL() |
291 // CCASqLiteStorage::NewL() |
149 // |
292 // |