30 #include <apgcli.h> |
31 #include <apgcli.h> |
31 #include <apaserverapp.h> |
32 #include <apaserverapp.h> |
32 #include <sysutil.h> |
33 #include <sysutil.h> |
33 #include <centralrepository.h> |
34 #include <centralrepository.h> |
34 |
35 |
35 #include "oma2agentmanager.h" |
36 #include "Oma2AgentManager.h" |
36 #include "oma2agentattributes.h" |
37 #include "Oma2AgentAttributes.h" |
37 #include "oma1dcf.h" |
38 #include "Oma1Dcf.h" |
38 #include "oma2dcf.h" |
39 #include "oma2dcf.h" |
39 #include "drmrightsclient.h" |
40 #include "DRMRightsClient.h" |
40 |
41 |
41 #include "drmutilityinternalcrkeys.h" // Cenrep extension for OmaBased |
42 #include "DrmUtilityInternalcrkeys.h" // Cenrep extension for OmaBased |
42 |
43 |
43 using namespace ContentAccess; |
44 using namespace ContentAccess; |
44 |
45 |
45 |
46 |
46 const TInt KMinimumOma1DcfLength = 16; |
47 const TInt KMinimumOma1DcfLength = 16; |
115 void COma2AgentManager::ConstructL() |
116 void COma2AgentManager::ConstructL() |
116 { |
117 { |
117 User::LeaveIfError(iFs.Connect()); |
118 User::LeaveIfError(iFs.Connect()); |
118 User::LeaveIfError(iFs.ShareAuto()); |
119 User::LeaveIfError(iFs.ShareAuto()); |
119 iFileManager = CFileMan::NewL(iFs); |
120 iFileManager = CFileMan::NewL(iFs); |
120 |
121 |
121 TInt err( KErrNone ); |
122 TInt err( KErrNone ); |
122 |
123 |
123 TRAP(err, FetchOmaBasedInfoL() ); |
124 TRAP(err, FetchOmaBasedInfoL() ); |
124 if( err) |
125 if( err) |
125 { |
126 { |
126 if( iOmaBasedMimeType ) |
127 if( iOmaBasedMimeType ) |
127 { |
128 { |
128 delete iOmaBasedMimeType; |
129 delete iOmaBasedMimeType; |
129 } |
130 } |
130 iOmaBasedMimeType = NULL; |
131 iOmaBasedMimeType = NULL; |
131 } |
132 } |
132 |
133 |
133 } |
134 } |
134 |
135 |
135 // ----------------------------------------------------------------------------- |
136 // ----------------------------------------------------------------------------- |
136 // COma2AgentManager::FetchOmaBasedInfoL |
137 // COma2AgentManager::FetchOmaBasedInfoL |
137 // ----------------------------------------------------------------------------- |
138 // ----------------------------------------------------------------------------- |
139 void COma2AgentManager::FetchOmaBasedInfoL() |
140 void COma2AgentManager::FetchOmaBasedInfoL() |
140 { |
141 { |
141 TInt err = KErrNone; |
142 TInt err = KErrNone; |
142 CRepository* repository( NULL ); |
143 CRepository* repository( NULL ); |
143 RBuf bOmaBasedMimeType; |
144 RBuf bOmaBasedMimeType; |
144 |
145 |
145 CleanupClosePushL(bOmaBasedMimeType); |
146 CleanupClosePushL(bOmaBasedMimeType); |
146 bOmaBasedMimeType.CreateL( KCenRepDataLength ); |
147 bOmaBasedMimeType.CreateL( KCenRepDataLength ); |
147 |
148 |
148 TRAP( err, repository = CRepository::NewL( KCRUidOmaBased ) ); |
149 TRAP( err, repository = CRepository::NewL( KCRUidOmaBased ) ); |
149 if ( !err ) |
150 if ( !err ) |
150 { |
151 { |
151 CleanupStack::PushL( repository ); |
152 CleanupStack::PushL( repository ); |
152 |
153 |
153 err = repository->Get( KOmaBasedMimeType, bOmaBasedMimeType ); |
154 err = repository->Get( KOmaBasedMimeType, bOmaBasedMimeType ); |
154 if( !err ) |
155 if( !err ) |
155 { |
156 { |
156 iOmaBasedMimeType = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bOmaBasedMimeType ); |
157 iOmaBasedMimeType = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bOmaBasedMimeType ); |
157 } |
158 } |
158 CleanupStack::PopAndDestroy( repository ); |
159 CleanupStack::PopAndDestroy( repository ); |
159 } |
160 } |
160 |
161 |
161 CleanupStack::PopAndDestroy(); |
162 CleanupStack::PopAndDestroy(); |
162 |
163 |
163 User::LeaveIfError( err ); |
164 User::LeaveIfError( err ); |
164 } |
165 } |
165 |
166 |
166 // ----------------------------------------------------------------------------- |
167 // ----------------------------------------------------------------------------- |
167 // COma2AgentManager::NewL |
168 // COma2AgentManager::NewL |
168 // Two-phased constructor. |
169 // Two-phased constructor. |
225 TInt result = KErrNone; |
226 TInt result = KErrNone; |
226 |
227 |
227 TInt err = KErrNone; |
228 TInt err = KErrNone; |
228 TBool retval = KErrNone; |
229 TBool retval = KErrNone; |
229 |
230 |
230 |
231 |
231 // Check the destination drive letter |
232 // Check the destination drive letter |
232 result = iFs.CharToDrive(drive,driveNumber); |
233 result = iFs.CharToDrive(drive,driveNumber); |
233 |
234 |
234 if( result ) |
235 if( result ) |
235 { |
236 { |
236 return result; |
237 return result; |
237 } |
238 } |
238 |
239 |
239 // open the file to read the size |
240 // open the file to read the size |
240 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
241 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
241 |
242 |
242 if( result ) |
243 if( result ) |
243 { |
244 { |
244 return result; |
245 return result; |
245 } |
246 } |
246 |
247 |
247 // read the size |
248 // read the size |
248 result = file.Size( size ); |
249 result = file.Size( size ); |
249 |
250 |
250 // close the file |
251 // close the file |
251 file.Close(); |
252 file.Close(); |
252 |
253 |
253 if( result ) |
254 if( result ) |
254 { |
255 { |
255 return result; |
256 return result; |
256 } |
257 } |
257 |
258 |
258 // check that the drive has enough space for the copy operation |
259 // check that the drive has enough space for the copy operation |
259 |
260 |
260 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
261 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
261 size, |
262 size, |
262 driveNumber ) ) |
263 driveNumber ) ) |
263 if( retval ) |
264 if( retval ) |
264 { |
265 { |
265 return KErrDiskFull; |
266 return KErrDiskFull; |
266 } |
267 } |
267 |
268 |
268 |
269 |
269 return iFileManager->Copy( aSource, aDestination); |
270 return iFileManager->Copy( aSource, aDestination); |
270 } |
271 } |
271 |
272 |
272 |
273 |
273 // ----------------------------------------------------------------------------- |
274 // ----------------------------------------------------------------------------- |
274 // CWmDrmAgentManager::CopyFile |
275 // CWmDrmAgentManager::CopyFile |
275 // |
276 // |
276 // ----------------------------------------------------------------------------- |
277 // ----------------------------------------------------------------------------- |
277 // |
278 // |
278 TInt COma2AgentManager::CopyFile(RFile& aSource, |
279 TInt COma2AgentManager::CopyFile(RFile& aSource, |
279 const TDesC& aDestination) |
280 const TDesC& aDestination) |
280 { |
281 { |
281 TInt driveNumber = 0; |
282 TInt driveNumber = 0; |
282 TChar drive( aDestination[0] ); |
283 TChar drive( aDestination[0] ); |
283 TInt size = 0; |
284 TInt size = 0; |
284 TInt result = KErrNone; |
285 TInt result = KErrNone; |
285 RFile output; |
286 RFile output; |
286 TFileName fileName; |
287 TFileName fileName; |
287 |
288 |
288 TInt err = KErrNone; |
289 TInt err = KErrNone; |
289 TBool retval = KErrNone; |
290 TBool retval = KErrNone; |
290 |
291 |
291 |
292 |
292 // Same file, do not even try to copy |
293 // Same file, do not even try to copy |
293 // And since they are the same don't return an error |
294 // And since they are the same don't return an error |
294 aSource.FullName( fileName ); |
295 aSource.FullName( fileName ); |
295 |
296 |
296 if( !aDestination.CompareF( fileName ) ) |
297 if( !aDestination.CompareF( fileName ) ) |
297 { |
298 { |
298 return KErrNone; |
299 return KErrNone; |
299 } |
300 } |
300 |
301 |
301 // Check the destination drive letter |
302 // Check the destination drive letter |
302 result = iFs.CharToDrive(drive,driveNumber); |
303 result = iFs.CharToDrive(drive,driveNumber); |
303 |
304 |
304 if( result ) |
305 if( result ) |
305 { |
306 { |
306 return result; |
307 return result; |
307 } |
308 } |
308 |
309 |
309 // read the size |
310 // read the size |
310 result = aSource.Size( size ); |
311 result = aSource.Size( size ); |
311 |
312 |
312 if( result ) |
313 if( result ) |
313 { |
314 { |
314 return result; |
315 return result; |
315 } |
316 } |
316 |
317 |
317 // check that the drive has enough space for the copy operation |
318 // check that the drive has enough space for the copy operation |
318 |
319 |
319 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
320 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
320 size, |
321 size, |
321 driveNumber ) ) |
322 driveNumber ) ) |
322 if( retval ) |
323 if( retval ) |
323 |
324 |
324 { |
325 { |
325 return KErrDiskFull; |
326 return KErrDiskFull; |
326 } |
327 } |
327 |
328 |
328 // Perform the copy: |
329 // Perform the copy: |
329 |
330 |
330 // Rewind just in case: |
331 // Rewind just in case: |
331 size = 0; |
332 size = 0; |
332 result = aSource.Seek(ESeekStart, size); |
333 result = aSource.Seek(ESeekStart, size); |
333 |
334 |
334 if( !result ) |
335 if( !result ) |
335 { |
336 { |
336 result = iFileManager->Copy(aSource, aDestination); |
337 result = iFileManager->Copy(aSource, aDestination); |
337 } |
338 } |
338 |
339 |
339 return result; |
340 return result; |
340 } |
341 } |
341 |
342 |
342 // ----------------------------------------------------------------------------- |
343 // ----------------------------------------------------------------------------- |
343 // COma2AgentManager::RenameFile |
344 // COma2AgentManager::RenameFile |
344 // ----------------------------------------------------------------------------- |
345 // ----------------------------------------------------------------------------- |
345 // |
346 // |
353 TInt size = 0; |
354 TInt size = 0; |
354 |
355 |
355 TInt err = KErrNone; |
356 TInt err = KErrNone; |
356 TBool retval = KErrNone; |
357 TBool retval = KErrNone; |
357 |
358 |
358 |
359 |
359 TInt result( iFileManager->Rename(aSource, aDestination) ); |
360 TInt result( iFileManager->Rename(aSource, aDestination) ); |
360 // If the files are on a different drive, Rename will fail |
361 // If the files are on a different drive, Rename will fail |
361 // Therefore we simulate the Move by doing a Copy, followed by Delete |
362 // Therefore we simulate the Move by doing a Copy, followed by Delete |
362 if ( result != KErrNone ) |
363 if ( result != KErrNone ) |
363 { |
364 { |
364 // Check the destination drive letter |
365 // Check the destination drive letter |
365 result = iFs.CharToDrive(drive,driveNumber); |
366 result = iFs.CharToDrive(drive,driveNumber); |
366 |
367 |
367 if( result ) |
368 if( result ) |
368 { |
369 { |
369 return result; |
370 return result; |
370 } |
371 } |
371 |
372 |
372 // open the file to read the size |
373 // open the file to read the size |
373 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
374 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
374 |
375 |
375 if( result ) |
376 if( result ) |
376 { |
377 { |
377 return result; |
378 return result; |
378 } |
379 } |
379 |
380 |
380 // read the size |
381 // read the size |
381 result = file.Size( size ); |
382 result = file.Size( size ); |
382 |
383 |
383 // close the file |
384 // close the file |
384 file.Close(); |
385 file.Close(); |
385 |
386 |
386 if( result ) |
387 if( result ) |
387 { |
388 { |
388 return result; |
389 return result; |
389 } |
390 } |
390 |
391 |
391 // check that the drive has enough space for the copy operation |
392 // check that the drive has enough space for the copy operation |
392 |
393 |
393 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
394 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
394 size, |
395 size, |
395 driveNumber ) ) |
396 driveNumber ) ) |
396 if( retval ) |
397 if( retval ) |
397 |
398 |
398 { |
399 { |
399 return KErrDiskFull; |
400 return KErrDiskFull; |
400 } |
401 } |
401 |
402 |
402 |
403 |
403 result = iFileManager->Copy(aSource,aDestination); |
404 result = iFileManager->Copy(aSource,aDestination); |
404 if (result == KErrNone) |
405 if (result == KErrNone) |
405 { |
406 { |
406 // If the copy was successful try and delete the original |
407 // If the copy was successful try and delete the original |
407 result = iFileManager->Delete(aSource); |
408 result = iFileManager->Delete(aSource); |
607 TRAP(r, dcf = CDcfCommon::NewL(aUri)); |
608 TRAP(r, dcf = CDcfCommon::NewL(aUri)); |
608 if (iNotifier != NULL && dcf != NULL) |
609 if (iNotifier != NULL && dcf != NULL) |
609 { |
610 { |
610 iStatus = &aStatus; |
611 iStatus = &aStatus; |
611 iWatchedEvents = aEventMask; |
612 iWatchedEvents = aEventMask; |
612 TRAP_IGNORE( iWatchedId = dcf->iContentID->AllocL() ); |
613 TRAP_IGNORE( iWatchedId = dcf->iContentID->AllocL() ); |
613 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
614 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
614 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
615 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
615 *iStatus = KRequestPending; |
616 *iStatus = KRequestPending; |
616 delete dcf; |
617 delete dcf; |
617 } |
618 } |