/** A helper function of CopyObjectL. @param aNewFileName the new full filename after copy. @return objectHandle of new copy of object. */ TUint32 CMTPImageDpCopyObject::CopyFileL(const TDesC& aOldFileName, const TDesC& aNewFileName) { OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_COPYFILEL_ENTRY ); TCleanupItem anItem(FailRecover, reinterpret_cast<TAny*>(this)); CleanupStack::PushL(anItem); GetPreviousPropertiesL(aOldFileName); LEAVEIFERROR(iFileMan->Copy(aOldFileName, *iDest), OstTraceExt3( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_COPYFILEL, "Copy %S to %S failed! error code %d", aOldFileName, *iDest, munged_err)); iRollbackActionL.AppendL(RollBackFromFsL); SetPreviousPropertiesL(aNewFileName); iFramework.ObjectMgr().InsertObjectL(*iTargetObjectInfo); //check object whether it is a new image object if (MTPImageDpUtilits::IsNewPicture(*iTargetObjectInfo)) { //increate new pictures count iDataProvider.IncreaseNewPictures(1); } CleanupStack::Pop(this); OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_COPYFILEL_EXIT ); return iTargetObjectInfo->Uint(CMTPObjectMetaData::EHandle); }
/** A helper function of MoveObjectL. @param aNewFolderName the new file folder name after the folder is moved. */ void CMTPMoveObject::MoveFolderL() { OstTraceFunctionEntry0( CMTPMOVEOBJECT_MOVEFOLDERL_ENTRY ); RBuf oldFolderName; oldFolderName.CreateL(KMaxFileName); oldFolderName.CleanupClosePushL(); oldFolderName = iObjectInfo->DesC(CMTPObjectMetaData::ESuid); iPathToMove = oldFolderName.AllocL(); if (iObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId()) { GetPreviousPropertiesL(oldFolderName); // Remove backslash. oldFolderName.SetLength(oldFolderName.Length() - 1); SetPreviousPropertiesL(*iNewRootFolder); _LIT(KBackSlash, "\\"); oldFolderName.Append(KBackSlash); iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, *iNewRootFolder); iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); } CleanupStack::PopAndDestroy(); // oldFolderName. OstTraceFunctionExit0( CMTPMOVEOBJECT_MOVEFOLDERL_EXIT ); }
// ----------------------------------------------------------------------------- // CMoveObject::SetPropertiesL // Set the object properties in the object property store. // ----------------------------------------------------------------------------- // void CMoveObject::SetPropertiesL( const TDesC& aNewFileName ) { PRINT1( _L( "MM MTP => CMoveObject::SetPropertiesL, aNewFileName = %S" ), &aNewFileName ); TUint32 formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode ); if ( formatCode == EMTPFormatCodeAbstractAudioVideoPlaylist ) { // This is used to keep the same behavior in mass storage and device file manager. PRINT( _L( "MM MTP <> CMoveObject::SetPropertiesL Playlist file do not update the MPX DB" ) ); iDpConfig.GetWrapperL().DeleteDummyFile( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) ); iDpConfig.GetWrapperL().AddDummyFileL( aNewFileName ); } if (iSameStorage) { iDpConfig.GetWrapperL().RenameObjectL( *iObjectInfo, aNewFileName ); iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewFileName ); iObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); iObjectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo ); } else // if the two object in different storage, we should delete the old one and insert new one { iDpConfig.GetWrapperL().DeleteObjectL( *iObjectInfo ); HBufC* oldFileName = iObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocLC(); // + oldFileName iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewFileName ); iObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); iObjectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); iDpConfig.GetWrapperL().AddObjectL( *iObjectInfo ); if ( formatCode == EMTPFormatCodeAbstractAudioVideoPlaylist || formatCode == EMTPFormatCodeAbstractAudioAlbum ) { MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr(); CDesCArray* references = referenceMgr.ReferencesLC( aNewFileName ); // + references iDpConfig.GetWrapperL().SetReferenceL( *iObjectInfo, *references ); CleanupStack::PopAndDestroy( references ); // - references } CleanupStack::PopAndDestroy( oldFileName ); // - oldFileName // Only leave when getting proplist element from data received by fw. // It should not happen after ReceiveDataL in which construction of proplist already succeed. SetPreviousPropertiesL(); } PRINT( _L( "MM MTP <= CMoveObject::SetPropertiesL" ) ); }
/** A helper function of MoveObjectL. @param aNewFileName the new file name after the object is moved. */ void CMTPMoveObject::MoveFileL(const TDesC& aNewFileName) { OstTraceFunctionEntry0( CMTPMOVEOBJECT_MOVEFILEL_ENTRY ); const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); GetPreviousPropertiesL(suid); if(iFramework.StorageMgr().DriveNumber(iObjectInfo->Uint(CMTPObjectMetaData::EStorageId)) == iFramework.StorageMgr().DriveNumber(iStorageId)) //Move file to the same storage { LEAVEIFERROR(iFileMan->Move(suid, *iDest), OstTraceExt2( TRACE_ERROR, CMTPMOVEOBJECT_MOVEFILEL, "move %S to %S failed!", suid, *iDest )); SetPreviousPropertiesL(aNewFileName); iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName); iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); SendResponseL(EMTPRespCodeOK); } else //Move file between different storages { delete iNewFileName; iNewFileName = NULL; iNewFileName = aNewFileName.AllocL(); // Store the new file name LEAVEIFERROR(iFileMan->Move(suid, *iDest, CFileMan::EOverWrite, iStatus), OstTraceExt2( TRACE_ERROR, DUP1_CMTPMOVEOBJECT_MOVEFILEL, "move %S to %S failed!", suid, *iDest)); if ( !IsActive() ) { SetActive(); } delete iTimer; iTimer = NULL; iTimer = CPeriodic::NewL(EPriorityStandard); TTimeIntervalMicroSeconds32 KMoveObjectIntervalNone = 0; iTimer->Start(TTimeIntervalMicroSeconds32(KMoveObjectTimeOut), KMoveObjectIntervalNone, TCallBack(CMTPMoveObject::OnTimeoutL, this)); } OstTraceFunctionExit0( CMTPMOVEOBJECT_MOVEFILEL_EXIT ); }
/** CMTPMoveObject::RunL */ void CMTPMoveObject::RunL() { OstTraceFunctionEntry0( CMTPMOVEOBJECT_RUNL_ENTRY ); LEAVEIFERROR(iStatus.Int(), OstTrace1( TRACE_ERROR, DUP2_CMTPMOVEOBJECT_RUNL, "wrong istatus %d", iStatus.Int())); SetPreviousPropertiesL(*iNewFileName); CMTPFSEntryCache& aCache = iDpSingletons.MovingBigFileCache(); // Check to see if we are moving a big file if(aCache.IsOnGoing()) { OstTrace0( TRACE_NORMAL, CMTPMOVEOBJECT_RUNL, "RunL - Big file move complete" ); aCache.SetOnGoing(EFalse); aCache.SetTargetHandle(KMTPHandleNone); } else { //Cancel the timer if(iTimer) { if(iTimer->IsActive()) { iTimer->Cancel(); } delete iTimer; iTimer = NULL; } iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, *iNewFileName); iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); OstTrace0( TRACE_NORMAL, DUP1_CMTPMOVEOBJECT_RUNL, "RunL, sending response with respond code OK for a normal file move" ); SendResponseL(EMTPRespCodeOK); } OstTraceFunctionExit0( CMTPMOVEOBJECT_RUNL_EXIT ); }