2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file: MfFileManageWorkerThread.cpp
19 * @brief: This file contains the implementation of FileManageWorkerThread class, which manages file operations like
20 * Copy, Move, Delete, Create and other utilities.
23 #include "MfFileManageWorkerThread.h"
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Base::Runtime;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Content;
31 using namespace Tizen::Io;
33 int FileManageWorkerThread::__fileManagedCounter = 0;
34 unsigned long FileManageWorkerThread::E_THREAD_CANCEL = 1000;
36 FileManageWorkerThread::FileManageWorkerThread(void)
37 : __pFolderEntryPM(null)
38 , __pListOfFiles(null)
40 __operationId = OPERATIONID_MANAGE_MIN;
41 __threadRunningState = THREAD_RUNNING_STATE_ALIVE;
42 __fileExistingOperationId = FILE_EXISTING_OPERATIONID_NONE;
43 __fileManagingingResult = FILE_MANAGING_RESULT_NONE;
46 FileManageWorkerThread::~FileManageWorkerThread(void)
48 if (__pFolderEntryPM != null)
50 delete __pFolderEntryPM;
54 FileManageWorkerThread&
55 FileManageWorkerThread::operator =(const FileManageWorkerThread& fileManageWorkerThread)
60 FileManageWorkerThread::FileManageWorkerThread(const FileManageWorkerThread& fileManageWorkerThread)
66 FileManageWorkerThread::Construct(void)
70 r = Thread::Construct(THREAD_TYPE_WORKER);
71 //r = EventDrivenThread::Construct(THREAD_TYPE_WORKER);
73 __pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
74 r = __pFolderEntryPM->Construct();
75 AppAssert(__pFolderEntryPM != null)
77 AppLogDebug("Exit %s", GetErrorMessage(r));
82 FileManageWorkerThread::CreateFolder(const String& destPath, const String& folderName)
88 filePath.Append(destPath);
89 filePath.Append(folderName);
91 r = Directory::Create(filePath, false);
92 AppLogDebug("Exit %s", GetErrorMessage(r));
97 FileManageWorkerThread::DeleteFile(const String& filePath)
100 result r = E_SUCCESS;
101 FileAttributes fileAttrib;
102 File::GetAttributes(filePath, fileAttrib);
104 if (fileAttrib.IsDirectory())
106 r = Directory::Remove(filePath, true);
110 r = File::Remove(filePath);
113 TryCatch(r == E_SUCCESS, , "file deletion failed");
115 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_SUCCESS;
116 AppLogDebug("Exit %s", GetErrorMessage(r));
120 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_FAILED;
121 AppLogDebug("Exit %s", GetErrorMessage(r));
126 FileManageWorkerThread::CopyFile(String sourcePath, String destPath)
128 AppLogDebug("Entry");
129 result r = E_SUCCESS;
130 ArrayList* pBackUpContentList = null;
131 DirectoryEntry* pDirStr = null;
132 DirectoryEntry* pDirStrTemp = null;
133 ArrayList* pTempContentList = null;
136 FileAttributes fileAttrib;
137 File::GetAttributes(sourcePath, fileAttrib);
139 if (fileAttrib.IsDirectory())
141 sourcePath.Append(L"/");
142 __pFolderEntryPM->SetFolderEntryPath(sourcePath);
143 pTempContentList = __pFolderEntryPM->GetFolderEntryList();
144 TryCatch(pTempContentList != null, , "Failed to allocate memory to original content list");
146 pBackUpContentList = new (std::nothrow) ArrayList();
147 pBackUpContentList->Construct();
149 for (int count = 0; count < pTempContentList->GetCount(); count++)
151 pDirStrTemp = static_cast< DirectoryEntry* >(pTempContentList->GetAt(count));
152 TryCatch(pDirStrTemp != null, , "Failed to allocate memory to pDirStrTemp");
154 pDirStr = new (std::nothrow) DirectoryEntry(*pDirStrTemp);
155 TryCatch(pDirStr != null, , "Failed to allocate memory to pdirstr");
156 pBackUpContentList->Add(pDirStr);
159 r = Directory::Create(destPath, false);
160 TryCatch(r == E_SUCCESS, , "dir already exist");
162 destPath.Append(L"/");
163 for (int count = 0; count < pBackUpContentList->GetCount(); count++)
165 tempDestPath.Clear();
166 tempDestPath.Append(destPath);
168 DirectoryEntry* pDirStr = null;
169 pDirStr = static_cast< DirectoryEntry* >(pBackUpContentList->GetAt(count));
170 tempDestPath.Append(pDirStr->GetFileName());
171 if (!pDirStr->IsDirectory())
173 tempDestPath.Append(L".");
174 tempDestPath.Append(pDirStr->GetFileExtension());
177 File::GetAttributes(pDirStr->GetFullFilePath(), fileAttrib);
178 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
180 r = CopyFile(pDirStr->GetFullFilePath(), tempDestPath);
184 pBackUpContentList->RemoveAll(true);
185 delete pBackUpContentList;
186 pBackUpContentList = null;
193 pBackUpContentList->RemoveAll(true);
194 delete pBackUpContentList;
195 pBackUpContentList = null;
200 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
202 //r = File::Copy(sourcePath, destPath, true);
203 r = Copy(sourcePath, destPath);
204 TryCatch(r == E_SUCCESS, , " file Copy Failed");
206 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
208 r = UpdateContentDB(destPath);
221 AppLogDebug("Exit %s", GetErrorMessage(r));
225 if (pBackUpContentList != null)
227 pBackUpContentList->RemoveAll(true);
228 delete pBackUpContentList;
229 pBackUpContentList = null;
232 AppLogDebug("Exit %s", GetErrorMessage(r));
237 FileManageWorkerThread::MoveFile(String sourcePath, String destPath)
239 AppLogDebug("Entry");
240 result r = E_SUCCESS;
242 FileAttributes fileAttrib;
243 File::GetAttributes(sourcePath, fileAttrib);
245 ArrayList* pBackUpContentList = null;
246 ArrayList* pTempContentList = null;
247 DirectoryEntry* pDirStr = null;
248 DirectoryEntry* pDirStrTemp = null;
251 if (fileAttrib.IsDirectory())
253 sourcePath.Append(L"/");
254 __pFolderEntryPM->SetFolderEntryPath(sourcePath);
255 pTempContentList = __pFolderEntryPM->GetFolderEntryList();
256 TryCatch(pTempContentList != null, , "Failed to allocate memory to original content list");
258 pBackUpContentList = new (std::nothrow) ArrayList();
259 pBackUpContentList->Construct();
261 for (int count = 0; count < pTempContentList->GetCount(); count++)
263 pDirStrTemp = static_cast< DirectoryEntry* >(pTempContentList->GetAt(count));
264 pDirStr = new (std::nothrow) DirectoryEntry(*pDirStrTemp);
265 TryCatch(pDirStr != null, , "Failed to allocate memory to pdirstr");
266 pBackUpContentList->Add(pDirStr);
269 r = Directory::Create(destPath, false);
270 TryCatch(r == E_SUCCESS, , "dir Creation Failed");
272 destPath.Append(L"/");
273 for (int count = 0; count < pBackUpContentList->GetCount(); count++)
275 tempDestPath.Clear();
276 tempDestPath.Append(destPath);
277 DirectoryEntry* pDirStr = null;
278 pDirStr = static_cast< DirectoryEntry* >(pBackUpContentList->GetAt(count));
279 tempDestPath.Append(pDirStr->GetFileName());
280 if (!pDirStr->IsDirectory())
282 tempDestPath.Append(L".");
283 tempDestPath.Append(pDirStr->GetFileExtension());
286 File::GetAttributes(pDirStr->GetFullFilePath(), fileAttrib);
287 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
289 r = MoveFile(pDirStr->GetFullFilePath(), tempDestPath);
293 pBackUpContentList->RemoveAll(true);
294 delete pBackUpContentList;
295 pBackUpContentList = null;
301 r = DeleteFile(sourcePath);
302 TryCatch(r == E_SUCCESS, , "Directory Deletion Failed");
304 pBackUpContentList->RemoveAll(true);
305 delete pBackUpContentList;
306 pBackUpContentList = null;
311 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
313 //r = File::Copy(sourcePath, destPath, true);
314 r = Copy(sourcePath, destPath);
315 TryCatch(r == E_SUCCESS, , " file already exist");
316 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
318 r = UpdateContentDB(destPath);
319 r = DeleteFileContentDB(sourcePath);
320 TryCatch(r == E_SUCCESS || r == E_THREAD_CANCEL,,"MOve file Failed");
334 AppLogDebug("Exit %s", GetErrorMessage(r));
338 if (pBackUpContentList != null)
340 pBackUpContentList->RemoveAll(true);
341 delete pBackUpContentList;
342 pBackUpContentList = null;
345 AppLogDebug("Exit %s", GetErrorMessage(r));
350 FileManageWorkerThread::CheckFileDuplicity(void)
352 //return File::IsFileExist(filePath);
354 DirectoryEntry* pDir = null;
355 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
356 while (pMapEnum->MoveNext() == E_SUCCESS)
358 pDir = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
361 filePath.Append(__currentRootPath);
362 if (pDir->IsDirectory())
364 filePath.Append(pDir->GetFileName());
368 filePath.Append(pDir->GetFileName());
369 filePath.Append(L".");
370 filePath.Append(pDir->GetFileExtension());
372 res = File::IsFileExist(filePath);
384 FileManageWorkerThread::DeleteFolderEntry(void)
386 AppLogDebug("Entry");
387 result r = E_SUCCESS;
388 DirectoryEntry* pDir = null;
389 ArrayList* pArg = null;
390 Integer* pFileManagedCounter = null;
391 Integer* pTotalFileCount = null;
392 Integer* pFileManagingResult = null;
393 Integer* pFolderEntryDeleteIndex = null;
394 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
396 ArrayList* pDeletedFolderEntry = null;
397 pDeletedFolderEntry = new (std::nothrow) ArrayList();
398 pDeletedFolderEntry->Construct();
401 if (pMapEnum != null)
403 while (pMapEnum->MoveNext() == E_SUCCESS)
405 pDir = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
406 TryCatch(pDir != null, , "directory retrieval falied");
408 r = DeleteFileContentDB(pDir->GetFullFilePath());
409 TryCatch(r == E_SUCCESS || r == E_THREAD_CANCEL, , " delete file failed");
411 if(r == E_THREAD_CANCEL)
416 pFolderEntryDeleteIndex = static_cast< Integer* >(pMapEnum->GetKey());
417 pDeletedFolderEntry->Add((new Integer(pFolderEntryDeleteIndex->ToInt())));
422 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
424 pArg = new (std::nothrow) ArrayList();
427 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
428 //pFolderEntryDeleteIndex = new (std::nothrow) Integer(0);
429 pFileManagedCounter = new (std::nothrow) Integer(count);
430 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
432 pArg->Add(pFileManagingResult);
433 //pArg->Add(pFolderEntryDeleteIndex);
434 pArg->Add(pFileManagedCounter);
435 pArg->Add(pTotalFileCount);
437 Application::GetInstance()->SendUserEvent(ID_DELETE_COMPLETE, pArg);
438 //Application::GetInstance()->SendUserEvent(ID_DELETE_COMPLETE, pArg);
444 SortArrayList(pDeletedFolderEntry);
447 for (int i = pDeletedFolderEntry->GetCount() - 1; i >= 0; i--)
449 Integer* PIndex = (Integer*) pDeletedFolderEntry->GetAt(i);
451 __fileManagingingResult = FILE_MANAGING_REFRESH_LIST;
453 pArg = new (std::nothrow) ArrayList();
456 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
457 pFolderEntryDeleteIndex = new (std::nothrow) Integer(PIndex->ToInt());
458 //pFileManagedCounter = new (std::nothrow) Integer(count++);
459 //pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
461 pArg->Add(pFileManagingResult);
462 pArg->Add(pFolderEntryDeleteIndex);
463 //pArg->Add(pFileManagedCounter);
464 //pArg->Add(pTotalFileCount);
466 Application::GetInstance()->SendUserEvent(ID_DELETE_COMPLETE, pArg);
469 if (pDeletedFolderEntry != null)
471 pDeletedFolderEntry->RemoveAll(true);
472 delete pDeletedFolderEntry;
473 pDeletedFolderEntry = null;
476 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_SUCCESS;
477 AppLogDebug("Exit %s", GetErrorMessage(r));
482 SortArrayList(pDeletedFolderEntry);
484 for (int i = pDeletedFolderEntry->GetCount() - 1; i >= 0; i--)
486 Integer* PIndex = (Integer*) pDeletedFolderEntry->GetAt(i);
488 __fileManagingingResult = FILE_MANAGING_REFRESH_LIST;
490 pArg = new (std::nothrow) ArrayList();
493 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
494 pFolderEntryDeleteIndex = new (std::nothrow) Integer(PIndex->ToInt());
495 //pFileManagedCounter = new (std::nothrow) Integer(count++);
496 //pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
498 pArg->Add(pFileManagingResult);
499 pArg->Add(pFolderEntryDeleteIndex);
500 //pArg->Add(pFileManagedCounter);
501 //pArg->Add(pTotalFileCount);
503 Application::GetInstance()->SendUserEvent(ID_DELETE_COMPLETE, pArg);
505 if (pDeletedFolderEntry != null)
507 pDeletedFolderEntry->RemoveAll(true);
508 delete pDeletedFolderEntry;
509 pDeletedFolderEntry = null;
512 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_FAILED;
513 AppLogDebug("Exit %s", GetErrorMessage(r));
518 FileManageWorkerThread::OnStart(void)
524 FileManageWorkerThread::OnStop(void)
526 //empty implementation
530 FileManageWorkerThread::Run(void)
532 AppLogDebug("Entry");
533 ArrayList* pArg = null;
534 result r = E_SUCCESS;
535 Integer* pFileProcessingResult = null;
536 __threadRunningState = THREAD_RUNNING_STATE_ALIVE;
538 switch (__operationId)
540 case OPERATIONID_MANAGE_DELETING:
542 if (__pListOfFiles == null)
544 //DeleteFile(__filePath);
545 r = DeleteFileContentDB(__filePath);
546 if(r == E_THREAD_CANCEL)
548 __fileManagingingResult = FILE_MANAGING_RESULT_THREAD_STOP;
556 pArg = new (std::nothrow) ArrayList();
558 pFileProcessingResult = new (std::nothrow) Integer(__fileManagingingResult);
559 pArg->Add(pFileProcessingResult);
560 Application::GetInstance()->SendUserEvent(ID_FILE_RENAME_COMPLETE, pArg);
564 case OPERATIONID_MANAGE_COPYING:
566 if (__pListOfFiles != null)
568 CopyFolderEntry(__fileExistingOperationId);
572 __fileManagingingResult = FILE_MANAGING_RESULT_COPYING_FAILED;
575 pArg = new (std::nothrow) ArrayList;
577 pFileProcessingResult = new (std::nothrow) Integer(__fileManagingingResult);
578 pArg->Add(pFileProcessingResult);
579 pArg->Add(&__duplicateFileName);
580 Application::GetInstance()->SendUserEvent(ID_COPY_COMPLETE, pArg);
585 case OPERATIONID_MANAGE_MOVING:
587 if (__pListOfFiles != null)
589 MoveFolderEntry(__fileExistingOperationId);
593 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_FAILED;
596 pArg = new (std::nothrow) ArrayList();
598 pFileProcessingResult = new (std::nothrow) Integer(__fileManagingingResult);
599 pArg->Add(pFileProcessingResult);
600 pArg->Add(&__duplicateFileName);
601 Application::GetInstance()->SendUserEvent(ID_MOVING_COMPLETE, pArg);
605 case OPERATIONID_MANAGE_CREATE_FOLDER:
607 //empty implementation
611 case OPERATIONID_MANAGE_RENAME:
614 pArg = new (std::nothrow) ArrayList();
616 pFileProcessingResult = new (std::nothrow) Integer(__fileManagingingResult);
617 pArg->Add(pFileProcessingResult);
618 //pArg->Add(&__duplicateFileName);
619 Application::GetInstance()->SendUserEvent(ID_MOVING_COMPLETE, pArg);
624 //empty implementation
634 FileManageWorkerThread::SetNameConflictOperationId(FileManaging& fileManagingStruct)
636 AppLogDebug("Entry");
637 __pListOfFiles = fileManagingStruct.GetListOfFiles();
638 __operationId = fileManagingStruct.GetOperationId();
639 __currentRootPath = fileManagingStruct.GetCurrentRootPath();
640 __filePath = fileManagingStruct.GetFilePath();
641 __renameFilePath = fileManagingStruct.GetNewFilePath();
642 __fileExistingOperationId = fileManagingStruct.GetFileExistingOperationId();
647 FileManageWorkerThread::CopyFolderEntry(FileExistingOperationId fileExistingOperationId)
649 AppLogDebug("Entry");
650 result r = E_SUCCESS;
651 DirectoryEntry* pDirStr = null;
653 ArrayList* pArg = null;
654 Integer* pFileManagedCounter = null;
655 Integer* pTotalFileCount = null;
656 Integer* pFileManagingResult = null;
657 String* pRenameFilePath = null;
658 ArrayList* renameFileList = null;
659 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
661 __fileManagedCounter = 0;
663 if (__pListOfFiles->GetCount() > 0)
665 switch (fileExistingOperationId)
667 case FILE_EXISTING_OPERATIONID_NONE:
669 if (!CheckForLegalDestination())
671 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
675 if (CheckFileDuplicity() == true)
677 __fileManagingingResult = FILE_MANAGING_RESULT_DUPLICITY;
685 case FILE_EXISTING_OPERATIONID_RENAME:
687 AppLogDebug("FILE_EXISTING_OPERATIONID_RENAME");
688 renameFileList = GetListOfRenameFilesN();
689 TryCatch(renameFileList != null, , "Failed to allocate memory to rename file list");
691 while (pMapEnum->MoveNext() == E_SUCCESS)
693 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
696 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
698 __fileManagedCounter++;
699 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
701 pArg = new (std::nothrow) ArrayList();
703 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
704 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
705 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
706 pArg->Add(pFileManagingResult);
707 pArg->Add(pFileManagedCounter);
708 pArg->Add(pTotalFileCount);
709 Application::GetInstance()->SendUserEvent(ID_COPY_COMPLETE, pArg);
711 pRenameFilePath = static_cast< String* >(renameFileList->GetAt(counter));
712 r = CopyFile(pDirStr->GetFullFilePath(), *pRenameFilePath);
713 TryCatch(r == E_SUCCESS, , "Failed to Copy File");
714 //r = UpdateContentDB(*pRenameFilePath);
715 //TryCatch(r == E_SUCCESS, , "Content db update failed");
719 __fileManagingingResult = FILE_MANAGING_RESULT_COPYING_SUCCESS;
720 __fileManagedCounter = 0;
727 if (renameFileList != null)
729 renameFileList->RemoveAll(true);
730 delete renameFileList;
731 renameFileList = null;
736 case FILE_EXISTING_OPERATIONID_REPLACE:
738 while (pMapEnum->MoveNext() == E_SUCCESS)
740 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
744 destPath.Append(__currentRootPath);
745 destPath.Append(pDirStr->GetFileName());
746 if (!pDirStr->IsDirectory())
748 destPath.Append(L".");
749 destPath.Append(pDirStr->GetFileExtension());
752 __fileManagedCounter++;
753 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
755 pArg = new (std::nothrow) ArrayList();
757 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
758 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
759 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
760 pArg->Add(pFileManagingResult);
761 pArg->Add(pFileManagedCounter);
762 pArg->Add(pTotalFileCount);
763 Application::GetInstance()->SendUserEvent(ID_COPY_COMPLETE, pArg);
765 AppLogDebug("full file path is %ls", pDirStr->GetFullFilePath().GetPointer());
766 AppLogDebug("dest path is %ls", destPath.GetPointer());
769 tempDestStr.Append(destPath);
770 //tempDestStr.Append(L"/");
771 if(pDirStr->IsDirectory())
773 tempDestStr.Append(L"/");
775 AppLogDebug("temp dest str is %ls",tempDestStr.GetPointer());
777 if(pDirStr->GetFullFilePath() == tempDestStr)
779 //AppLogDebug("hello");
784 if (pDirStr->GetFullFilePath().StartsWith(tempDestStr, 0))
786 AppLogDebug("case exist");
787 String modifiedDestPath;
788 modifiedDestPath.Append(destPath);
790 Tizen::System::SystemTime::GetCurrentTime(t);
791 modifiedDestPath.Append(t.GetDay());
792 modifiedDestPath.Append(t.GetMonth());
793 modifiedDestPath.Append(t.GetYear());
794 modifiedDestPath.Append(t.GetHour());
795 modifiedDestPath.Append(t.GetMinute());
796 modifiedDestPath.Append(t.GetSecond());
798 String modifiedSourcePath;
799 modifiedSourcePath.Append(modifiedDestPath);
800 modifiedSourcePath.Append(L"/");
802 pDirStr->GetFullFilePath().SubString(destPath.GetLength() + 1, pDirStr->GetFullFilePath().GetLength() - destPath.GetLength() - 1, tempStr);
803 modifiedSourcePath.Append(tempStr);
805 AppLogDebug("modified source path is %ls", modifiedSourcePath.GetPointer());
807 r = Directory::Rename(destPath, modifiedDestPath);
808 TryCatch(r == E_SUCCESS, , "Rename Failed");
809 AppLogDebug("r %s", GetErrorMessage(r));
810 r = CopyFile(modifiedSourcePath, destPath);
811 TryCatch(r == E_SUCCESS, , "Failed To Copy File");
812 //r = UpdateContentDB(destPath);
813 //TryCatch(r == E_SUCCESS, , "update db content failed");
814 r = DeleteFile(modifiedDestPath);
815 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND, , "Delete Failed");
819 if (!pDirStr->GetFullFilePath().StartsWith(destPath, 0))
821 /*r = DeleteFile(destPath);
822 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND,,"Delete Failed");
823 r = CopyFile(pDirStr->GetFullFilePath(), destPath);
824 TryCatch(r == E_SUCCESS,,"Failed To Copy File");*/
826 r = DeleteFileContentDB(destPath);
827 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND, , "Delete Failed");
828 r = CopyFile(pDirStr->GetFullFilePath(), destPath);
829 TryCatch(r == E_SUCCESS, , "copy failed");
830 //r = UpdateContentDB(destPath);
831 //TryCatch(r == E_SUCCESS, , "update db content failed");
840 case FILE_EXISTING_OPERATIONID_CANCEL:
853 while (pMapEnum->MoveNext() == E_SUCCESS)
855 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
857 destPath.Append(__currentRootPath);
858 destPath.Append(pDirStr->GetFileName());
859 if (pDirStr->IsDirectory() == false)
861 destPath.Append(L".");
862 destPath.Append(pDirStr->GetFileExtension());
864 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
866 __fileManagedCounter++;
868 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
869 pArg = new (std::nothrow) ArrayList();
871 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
872 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
873 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
874 pArg->Add(pFileManagingResult);
875 pArg->Add(pFileManagedCounter);
876 pArg->Add(pTotalFileCount);
877 Application::GetInstance()->SendUserEvent(ID_COPY_COMPLETE, pArg);
880 r = CopyFile(pDirStr->GetFullFilePath(), destPath);
881 TryCatch(r == E_SUCCESS, , "Copy File Failed");
882 //r = UpdateContentDB(destPath);
883 //TryCatch(r == E_SUCCESS, , "update db Copy File Failed");
885 //r = Copy(pDirStr->GetFullFilePath(), destPath);
890 __fileManagingingResult = FILE_MANAGING_RESULT_COPYING_SUCCESS;
891 __fileManagedCounter = 0;
898 __fileManagingingResult = FILE_MANAGING_RESULT_COPYING_SUCCESS;
899 __fileManagedCounter = 0;
900 AppLogDebug("Exit %s", GetErrorMessage(r));
907 if (r == E_STORAGE_FULL)
909 __fileManagingingResult = FILE_MANAGING_RESULT_STORAGE_FULL;
913 __fileManagingingResult = FILE_MANAGING_RESULT_COPYING_FAILED;
915 //r = DeleteFile(destPath);
916 if (renameFileList != null)
918 renameFileList->RemoveAll(true);
919 delete renameFileList;
920 renameFileList = null;
923 /*pArg = new (std::nothrow) ArrayList();
925 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
926 pArg->Add(pFileManagingResult);
927 Application::GetInstance()->SendUserEvent(ID_FILE_MANAGING_FAILED, pArg);*/
928 AppLogDebug("Exit %s", GetErrorMessage(r));
934 FileManageWorkerThread::MoveFolderEntry(FileExistingOperationId fileExistingOperationId)
936 AppLogDebug("Entry");
937 result r = E_SUCCESS;
938 DirectoryEntry* pDirStr = null;
940 ArrayList* pArg = null;
941 Integer* pFileManagedCounter = null;
942 Integer* pTotalFileCount = null;
943 Integer* pFileManagingResult = null;
944 String* pRenameFilePath;
945 ArrayList* renameFileList = null;
946 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
948 __fileManagedCounter = 0;
950 if (__pListOfFiles->GetCount() > 0)
952 switch (fileExistingOperationId)
954 case FILE_EXISTING_OPERATIONID_NONE:
956 if (IsSourceSameAsDestination())
958 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
962 if (CheckFileDuplicity() == true)
964 __fileManagingingResult = FILE_MANAGING_RESULT_DUPLICITY;
972 case FILE_EXISTING_OPERATIONID_RENAME:
974 renameFileList = GetListOfRenameFilesN();
975 TryCatch(renameFileList != null, , "Failed to allocate memory to rename file list");
977 while (pMapEnum->MoveNext() == E_SUCCESS)
979 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
982 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
984 __fileManagedCounter++;
985 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
987 pArg = new (std::nothrow) ArrayList();
989 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
990 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
991 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
992 pArg->Add(pFileManagingResult);
993 pArg->Add(pFileManagedCounter);
994 pArg->Add(pTotalFileCount);
995 Application::GetInstance()->SendUserEvent(ID_MOVING_COMPLETE, pArg);
997 pRenameFilePath = static_cast< String* >(renameFileList->GetAt(counter));
999 r = MoveFile(pDirStr->GetFullFilePath(), *pRenameFilePath);
1000 TryCatch(r == E_SUCCESS || r == E_THREAD_CANCEL,,"Move File Failed");
1002 if(r == E_THREAD_CANCEL)
1004 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_SUCCESS;
1005 __fileManagedCounter = 0;
1009 /*r = CopyFile(pDirStr->GetFullFilePath(), *pRenameFilePath);
1010 r = UpdateContentDB(*pRenameFilePath);
1011 //TryCatch(r == E_SUCCESS, , "move File Failed");
1012 r = DeleteFileContentDB(pDirStr->GetFullFilePath());
1013 TryCatch(r == E_SUCCESS, , "Delete source failed");*/
1017 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_SUCCESS;
1018 __fileManagedCounter = 0;
1025 if (renameFileList != null)
1027 renameFileList->RemoveAll(true);
1028 delete renameFileList;
1029 renameFileList = null;
1034 case FILE_EXISTING_OPERATIONID_REPLACE:
1036 while (pMapEnum->MoveNext() == E_SUCCESS)
1038 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1039 if (pDirStr != null)
1042 destPath.Append(__currentRootPath);
1043 destPath.Append(pDirStr->GetFileName());
1044 if (!pDirStr->IsDirectory())
1046 destPath.Append(L".");
1047 destPath.Append(pDirStr->GetFileExtension());
1050 __fileManagedCounter++;
1051 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
1053 pArg = new (std::nothrow) ArrayList();
1055 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
1056 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
1057 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
1058 pArg->Add(pFileManagingResult);
1059 pArg->Add(pFileManagedCounter);
1060 pArg->Add(pTotalFileCount);
1061 Application::GetInstance()->SendUserEvent(ID_MOVING_COMPLETE, pArg);
1064 tempDestStr.Append(destPath);
1065 tempDestStr.Append(L"/");
1066 if (pDirStr->GetFullFilePath().StartsWith(tempDestStr, 0))
1068 AppLogDebug("case exist");
1069 String modifiedDestPath;
1070 modifiedDestPath.Append(destPath);
1072 Tizen::System::SystemTime::GetCurrentTime(t);
1073 modifiedDestPath.Append(t.GetDay());
1074 modifiedDestPath.Append(t.GetMonth());
1075 modifiedDestPath.Append(t.GetYear());
1076 modifiedDestPath.Append(t.GetHour());
1077 modifiedDestPath.Append(t.GetMinute());
1078 modifiedDestPath.Append(t.GetSecond());
1080 String modifiedSourcePath;
1081 modifiedSourcePath.Append(modifiedDestPath);
1082 modifiedSourcePath.Append(L"/");
1084 pDirStr->GetFullFilePath().SubString(destPath.GetLength() + 1, pDirStr->GetFullFilePath().GetLength() - destPath.GetLength() - 1, tempStr);
1085 modifiedSourcePath.Append(tempStr);
1087 AppLogDebug("modified source path is %ls", modifiedSourcePath.GetPointer());
1089 r = Directory::Rename(destPath, modifiedDestPath);
1090 TryCatch(r == E_SUCCESS, , "Rename Failed");
1091 AppLogDebug("r %s", GetErrorMessage(r));
1092 r = MoveFile(modifiedSourcePath, destPath);
1093 TryCatch(r == E_SUCCESS, , "Move File Failed");
1094 r = DeleteFile(modifiedDestPath);
1095 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND, , "Delete Failed");
1100 /*r = DeleteFile(destPath);
1101 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND,,"Delete Failed");
1102 r = MoveFile(pDirStr->GetFullFilePath(), destPath);
1103 TryCatch(r == E_SUCCESS,,"Move File Failed");*/
1105 r = DeleteFileContentDB(destPath);
1106 TryCatch(r == E_SUCCESS || r == E_FILE_NOT_FOUND, , "Delete same file failed");
1107 r = CopyFile(pDirStr->GetFullFilePath(), destPath);
1108 r = UpdateContentDB(destPath);
1109 //TryCatch(r == E_SUCCESS, , "move File Failed");
1110 r = DeleteFileContentDB(pDirStr->GetFullFilePath());
1111 TryCatch(r == E_SUCCESS, , "Delete source failed");
1119 case FILE_EXISTING_OPERATIONID_CANCEL:
1132 while (pMapEnum->MoveNext() == E_SUCCESS)
1134 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1136 destPath.Append(__currentRootPath);
1137 destPath.Append(pDirStr->GetFileName());
1138 if (pDirStr->IsDirectory() == false)
1140 destPath.Append(L".");
1141 destPath.Append(pDirStr->GetFileExtension());
1143 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
1146 __fileManagedCounter++;
1148 __fileManagingingResult = FILE_MANAGING_RESULT_CURRENT_STATUS;
1149 pArg = new (std::nothrow) ArrayList();
1151 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
1152 pFileManagedCounter = new (std::nothrow) Integer(__fileManagedCounter);
1153 pTotalFileCount = new (std::nothrow) Integer(__pListOfFiles->GetCount());
1154 pArg->Add(pFileManagingResult);
1155 pArg->Add(pFileManagedCounter);
1156 pArg->Add(pTotalFileCount);
1157 Application::GetInstance()->SendUserEvent(ID_MOVING_COMPLETE, pArg);
1159 r = MoveFile(pDirStr->GetFullFilePath(), destPath);
1160 TryCatch(r == E_SUCCESS || r == E_THREAD_CANCEL, , "move File Failed");
1162 if(r == E_THREAD_CANCEL)
1164 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_SUCCESS;
1165 __fileManagedCounter = 0;
1169 /*r = CopyFile(pDirStr->GetFullFilePath(), destPath);
1170 TryCatch(r == E_SUCCESS, , "Copy file failed");
1171 r = UpdateContentDB(destPath);
1172 //TryCatch(r == E_SUCCESS, , "move File Failed");
1173 r = DeleteFileContentDB(pDirStr->GetFullFilePath());
1174 TryCatch(r == E_SUCCESS, , "Delete source failed");*/
1179 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_SUCCESS;
1180 __fileManagedCounter = 0;
1187 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_SUCCESS;
1188 __fileManagedCounter = 0;
1189 AppLogDebug("Exit %s", GetErrorMessage(r));
1194 if (r == E_STORAGE_FULL)
1196 __fileManagingingResult = FILE_MANAGING_RESULT_STORAGE_FULL;
1200 __fileManagingingResult = FILE_MANAGING_RESULT_MOVING_FAILED;
1203 if (renameFileList != null)
1205 renameFileList->RemoveAll(true);
1206 delete renameFileList;
1207 renameFileList = null;
1210 //__fileManagingingResult = FILE_MANAGING_RESULT_MOVING_FAILED;
1211 pArg = new (std::nothrow) ArrayList();
1213 pFileManagingResult = new (std::nothrow) Integer(__fileManagingingResult);
1214 pArg->Add(pFileManagingResult);
1215 Application::GetInstance()->SendUserEvent(ID_FILE_MANAGING_FAILED, pArg);
1216 AppLogDebug("Exit %s", GetErrorMessage(r));
1223 FileManageWorkerThread::IsSourceSameAsDestination(void)
1225 AppLogDebug("Entry");
1226 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
1228 DirectoryEntry* pDirStr = null;
1230 if (__pListOfFiles->GetCount() > 0)
1232 while (pMapEnum->MoveNext() == E_SUCCESS)
1234 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1235 if (pDirStr != null)
1238 if (pDirStr->IsDirectory())
1240 destPath.Append(__currentRootPath);
1241 destPath.Append(pDirStr->GetFileName());
1242 destPath.Append(L"/");
1244 /*if (__currentRootPath.StartsWith(pDirStr->GetFullFilePath(), 0))
1246 AppLogDebug("hello");
1247 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
1259 destPath.Append(__currentRootPath);
1260 destPath.Append(pDirStr->GetFileName());
1261 destPath.Append(L".");
1262 destPath.Append(pDirStr->GetFileExtension());
1265 if (destPath == pDirStr->GetFullFilePath() || __currentRootPath.StartsWith(pDirStr->GetFullFilePath(), 0))
1267 AppLogDebug("hello");
1268 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
1282 AppLogDebug("Exit");
1288 FileManageWorkerThread::GenerateNewName(DirectoryEntry* pSourceDirStr)
1290 AppLogDebug("Entry");
1291 IMapEnumerator* pMapEnum = null;
1292 pMapEnum = __pListOfFiles->GetMapEnumeratorN();
1295 DirectoryEntry* pDirStr = null;
1298 rename.Append(pSourceDirStr->GetFileName());
1299 rename.Append(L"_");
1300 rename.Append(count);
1302 while (pMapEnum->MoveNext() == E_SUCCESS)
1304 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1306 filePath.Append(__currentRootPath);
1307 filePath.Append(rename);
1308 if (pDirStr != null)
1310 if (pDirStr->IsDirectory() == false)
1312 filePath.Append(L".");
1313 filePath.Append(pDirStr->GetFileExtension());
1316 if (rename == pDirStr->GetFileName() || CheckFileDuplicity())
1320 rename.Append(pSourceDirStr->GetFileName());
1321 rename.Append(L"_");
1322 rename.Append(count);
1332 AppLogDebug("Exit");
1337 FileManageWorkerThread::StopThread(void)
1339 __threadRunningState = THREAD_RUNNING_STATE_STOP;
1343 FileManageWorkerThread::GetListOfRenameFilesN(void)
1346 AppLogDebug("Enter");
1347 ArrayList* pRenameFileList;
1348 pRenameFileList = null;
1349 IMapEnumerator* pMapEnum = null;
1350 String* pRenameFile;
1352 pRenameFileList = new (std::nothrow) ArrayList();
1353 TryCatch(pRenameFileList != null, , "failed to allocate memory to renameFileList");
1355 pMapEnum = __pListOfFiles->GetMapEnumeratorN();
1356 while (pMapEnum->MoveNext() == E_SUCCESS)
1359 DirectoryEntry* pDirStr = null;
1360 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1361 if (pDirStr != null)
1363 String renameFileName(L"");
1364 FileAttributes fileAttrib;
1365 File::GetAttributes(pDirStr->GetFullFilePath(), fileAttrib);
1366 String fileName = pDirStr->GetFileName();
1367 if (!pDirStr->IsDirectory())
1369 fileName.Append(L".");
1370 fileName.Append(pDirStr->GetFileExtension());
1373 renameFileName.Append(__currentRootPath);
1374 renameFileName.Append(fileName);
1376 while (File::IsFileExist(renameFileName) == true || IsFileNameExist(renameFileName, pRenameFileList) == true)
1378 renameFileName.Clear();
1379 if (fileAttrib.IsDirectory())
1381 renameFileName.Append(__currentRootPath);
1382 renameFileName.Append(pDirStr->GetFileName());
1383 renameFileName.Append(L"_");
1384 renameFileName.Append(count);
1389 renameFileName.Append(__currentRootPath);
1390 renameFileName.Append(pDirStr->GetFileName());
1391 renameFileName.Append(L"_");
1392 renameFileName.Append(count);
1393 renameFileName.Append(L".");
1394 renameFileName.Append(pDirStr->GetFileExtension());
1399 pRenameFile = new (std::nothrow) String();
1400 TryCatch(pRenameFile != null, , "failed to allocate memoy to renamefile");
1402 pRenameFile->Append(renameFileName);
1403 pRenameFileList->Add(pRenameFile);
1409 for (int i = 0; i < pRenameFileList->GetCount(); i++)
1411 String* pName = (String*) pRenameFileList->GetAt(i);
1412 AppLogDebug("rename is %ls", pName->GetPointer());
1415 return pRenameFileList;
1418 if (pRenameFileList != null)
1420 pRenameFileList->RemoveAll(true);
1421 delete pRenameFileList;
1422 pRenameFileList = null;
1429 FileManageWorkerThread::CheckForLegalDestination(void)
1431 AppLogDebug("Entry");
1432 IMapEnumerator* pMapEnum = __pListOfFiles->GetMapEnumeratorN();
1434 DirectoryEntry* pDirStr = null;
1436 while (pMapEnum->MoveNext() == E_SUCCESS)
1438 pDirStr = static_cast< DirectoryEntry* >(pMapEnum->GetValue());
1439 if (pDirStr != null)
1441 if (pDirStr->IsDirectory())
1444 if (__currentRootPath.StartsWith(pDirStr->GetFullFilePath(), 0))
1446 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
1458 destPath.Append(__currentRootPath);
1459 destPath.Append(pDirStr->GetFileName());
1460 destPath.Append(L".");
1461 destPath.Append(pDirStr->GetFileExtension());
1464 /*if (destPath == pDirStr->GetFullFilePath() || __currentRootPath.StartsWith(pDirStr->GetFullFilePath(), 0))
1466 AppLogDebug("hello");
1467 __fileManagingingResult = FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION;
1478 AppLogDebug("Exit");
1484 FileManageWorkerThread::IsFileNameExist(Tizen::Base::String fileName, Tizen::Base::Collection::ArrayList* pRenameList)
1486 for (int i = 0; i < pRenameList->GetCount(); i++)
1488 String* pRenamedFileName = static_cast< String* >(pRenameList->GetAt(i));
1489 if (*pRenamedFileName == fileName)
1498 FileManageWorkerThread::SortArrayList(Tizen::Base::Collection::ArrayList* pArrList)
1500 for (int i = 0; i < pArrList->GetCount(); i++)
1502 Integer* pValue1 = (Integer*) pArrList->GetAt(i);
1503 for (int j = i + 1; j < pArrList->GetCount(); j++)
1505 Integer* pValue2 = (Integer*) pArrList->GetAt(j);
1506 if (pValue1->ToInt() > pValue2->ToInt())
1509 temp = pValue1->ToInt();
1510 *pValue1 = *pValue2;
1519 FileManageWorkerThread::GetContentTypeInfo(const String& FilePath)
1522 ContentType contentType = CONTENT_TYPE_UNKNOWN;
1523 contentType = ContentManagerUtil::CheckContentType(FilePath);
1524 AppLogDebug("Content type result is %s",GetErrorMessage(GetLastResult()));
1529 FileManageWorkerThread::DeleteFileContentDB(String filePath)
1531 AppLogDebug("Entry");
1532 result r = E_SUCCESS;
1533 ContentId contentId;
1534 ContentManager contentManager;
1535 ArrayList* pContentList = null;
1536 ArrayList* pBackUpContentList = null;
1537 DirectoryEntry* pDirStr = null;
1538 DirectoryEntry* pDirStrTemp = null;
1540 FileAttributes fileAttrib;
1541 File::GetAttributes(filePath, fileAttrib);
1543 AppLogDebug("file path is %ls", filePath.GetPointer());
1544 if (fileAttrib.IsDirectory())
1546 pBackUpContentList = new (std::nothrow) ArrayList();
1547 pBackUpContentList->Construct();
1549 AppLogDebug("source path is %ls", sourcePath.GetPointer());
1550 if(!filePath.EndsWith(L"/"))
1552 filePath.Append(L"/");
1554 __pFolderEntryPM->SetFolderEntryPath(filePath);
1555 pContentList = __pFolderEntryPM->GetFolderEntryList();
1556 TryCatch(pContentList != null, , "Failed to get content list");
1557 AppLogDebug("pcontent list count is %d", pContentList->GetCount());
1559 for (int count = 0; count < pContentList->GetCount(); count++)
1561 pDirStrTemp = static_cast< DirectoryEntry* >(pContentList->GetAt(count));
1562 TryCatch(pDirStrTemp != null, , "Failed to allocate memory to pDirStrTemp");
1563 pDirStr = new (std::nothrow) DirectoryEntry(*pDirStrTemp);
1564 TryCatch(pDirStr != null, , "Failed to allocate memory to pdirstr");
1565 pBackUpContentList->Add(pDirStr);
1568 for (int counter = 0; counter < pBackUpContentList->GetCount(); counter++)
1570 pDirStr = static_cast< DirectoryEntry* >(pBackUpContentList->GetAt(counter));
1571 AppLogDebug("dir name is %ls", pDirStr->GetFileName().GetPointer());
1573 sourcePath.Append(pDirStr->GetFullFilePath());
1575 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
1577 r = DeleteFileContentDB(sourcePath);
1581 pBackUpContentList->RemoveAll(true);
1582 delete pBackUpContentList;
1583 pBackUpContentList = null;
1584 return E_THREAD_CANCEL;
1586 //TryCatch(r == E_SUCCESS, , "content Delete failed");
1589 r = Directory::Remove(filePath, true);
1590 TryCatch(r == E_SUCCESS, , "content Delete failed");
1592 pBackUpContentList->RemoveAll(true);
1593 delete pBackUpContentList;
1594 pBackUpContentList = null;
1599 if (__threadRunningState == THREAD_RUNNING_STATE_ALIVE)
1601 contentManager.Construct();
1602 r = GetContentID(filePath, contentId);
1605 contentManager.DeleteContent(contentId);
1609 r = DeleteFile(filePath);
1614 return E_THREAD_CANCEL;
1618 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_SUCCESS;
1619 AppLogDebug("Exit");
1623 __fileManagingingResult = FILE_MANAGING_RESULT_DELETING_FAILED;
1624 AppLogDebug("Catch result %s", GetErrorMessage(r));
1625 AppLogDebug("Exit");
1631 FileManageWorkerThread::UpdateContentDB(Tizen::Base::String filePath)
1633 AppLogDebug("Entry");
1634 result r = E_SUCCESS;
1635 ContentId contentId;
1636 ArrayList* pContentList = null;
1637 DirectoryEntry* pDirStr = null;
1638 String tempFilePath;
1639 FileAttributes fileAttrib;
1640 File::GetAttributes(filePath, fileAttrib);
1641 AppLogDebug("file path is %ls", filePath.GetPointer());
1642 //AppLogDebug("dest path is %ls",destPath.GetPointer());
1644 if (fileAttrib.IsDirectory())
1646 filePath.Append(L"/");
1647 __pFolderEntryPM->SetFolderEntryPath(filePath);
1648 pContentList = __pFolderEntryPM->GetFolderEntryList();
1649 TryCatch(pContentList != null, , "Failed to get content list");
1650 AppLogDebug("pcontent list count is %d", pContentList->GetCount());
1651 for (int counter = 0; counter < pContentList->GetCount(); counter++)
1653 pDirStr = static_cast< DirectoryEntry* >(pContentList->GetAt(counter));
1654 AppLogDebug("dir name is %ls", pDirStr->GetFileName().GetPointer());
1655 tempFilePath.Clear();
1656 tempFilePath.Append(pDirStr->GetFullFilePath());
1657 r = UpdateContentDB(tempFilePath);
1658 //TryCatch(r == E_SUCCESS, , "content copy updated");
1663 r = GetContentID(filePath, contentId);
1666 AppLogDebug("Exit");
1669 r = GetLastResult();
1670 AppLogDebug("result is %s", GetErrorMessage(r));
1671 AppLogDebug("Exit");
1676 FileManageWorkerThread::GetContentID(const String& filePath, ContentId& contentId)
1679 ContentManager contentManager;
1680 //ContentId contentId;
1681 result r = E_SUCCESS;
1682 ContentType contentType;
1683 ContentInfo* contentInfo = null;
1684 contentType = CONTENT_TYPE_UNKNOWN;
1686 contentManager.Construct();
1688 contentType = GetContentTypeInfo(filePath);
1691 switch (contentType)
1693 case CONTENT_TYPE_IMAGE:
1695 AppLogDebug("CONTENT_TYPE_IMAGE");
1696 ImageContentInfo* imagecontentInfo = null;
1697 imagecontentInfo = new (std::nothrow) ImageContentInfo();
1698 String* pPath = new (std::nothrow) String(filePath);
1699 imagecontentInfo->Construct(pPath);
1701 contentInfo = imagecontentInfo;
1702 contentId = contentManager.CreateContent(*imagecontentInfo);
1703 TryCatch(GetLastResult() == E_SUCCESS, , "create content failed");
1704 delete imagecontentInfo;
1708 case CONTENT_TYPE_AUDIO:
1710 AppLogDebug("CONTENT_TYPE_AUDIO");
1711 AudioContentInfo* audiocontentInfo = null;
1712 audiocontentInfo = new (std::nothrow) AudioContentInfo();
1713 TryCatch(audiocontentInfo != null, , "memory for audio failed");
1714 String* pPath = new (std::nothrow) String(filePath);
1715 r = audiocontentInfo->Construct(pPath);
1717 contentInfo = audiocontentInfo;
1718 contentId = contentManager.CreateContent(*audiocontentInfo);
1719 TryCatch(GetLastResult() == E_SUCCESS, , "create content failed");
1720 delete audiocontentInfo;
1724 case CONTENT_TYPE_VIDEO:
1726 AppLogDebug("CONTENT_TYPE_VIDEO");
1727 VideoContentInfo* videocontentInfo = null;
1728 videocontentInfo = new (std::nothrow) VideoContentInfo();
1729 String* pPath = new (std::nothrow) String(filePath);
1730 videocontentInfo->Construct(pPath);
1732 contentInfo = videocontentInfo;
1733 contentId = contentManager.CreateContent(*videocontentInfo);
1734 TryCatch(GetLastResult() == E_SUCCESS, , "create content failed");
1735 delete videocontentInfo;
1739 case CONTENT_TYPE_OTHER:
1741 AppLogDebug("CONTENT_TYPE_OTHER");
1742 OtherContentInfo* othercontentInfo = null;
1743 othercontentInfo = new (std::nothrow) OtherContentInfo();
1744 String* pPath = new (std::nothrow) String(filePath);
1745 othercontentInfo->Construct(pPath);
1747 contentInfo = othercontentInfo;
1748 contentId = contentManager.CreateContent(*othercontentInfo);
1749 TryCatch(GetLastResult() == E_SUCCESS, , "create content failed");
1750 delete othercontentInfo;
1754 case CONTENT_TYPE_UNKNOWN:
1756 AppLogDebug("CONTENT_TYPE_UNKNOWN");
1765 AppLogDebug("Exit");
1769 r = GetLastResult();
1770 AppLogDebug("catch result %s", GetErrorMessage(r));
1771 if (contentInfo != null)
1778 AppLogDebug("catch result %s", GetErrorMessage(r));
1779 AppLogDebug("Exit");
1784 FileManageWorkerThread::RenameFolderEntry(void)
1786 result r = E_SUCCESS;
1787 FileAttributes fileAttrib;
1789 r = CopyFile(__filePath,__renameFilePath);
1790 TryCatch(r == E_SUCCESS,,"copy failed");
1792 r = DeleteFileContentDB(__filePath);
1794 File::GetAttributes(__renameFilePath, fileAttrib);
1795 if(fileAttrib.IsDirectory())
1797 __renameFilePath.Append(L"/");
1800 __fileManagingingResult = FILE_MANAGING_RENAME_SUCCESS;
1804 r = DeleteFile(__renameFilePath);
1805 __fileManagingingResult = FILE_MANAGING_RENAME_FAILED;
1806 AppLogDebug("catch result is %s",GetErrorMessage(r));
1811 FileManageWorkerThread::Copy(Tizen::Base::String& sourcePath, Tizen::Base::String& destPath)
1813 AppLogDebug("FileManageWorkerThread::Copy");
1815 const int BUFFER_SIZE_MAX = 4096;
1819 void* byteToWrite = null;
1820 byteToWrite = (void*) malloc(sizeof(char)*BUFFER_SIZE_MAX);
1822 r = sourceFIle.Construct(sourcePath, "r");
1823 TryCatch(r == E_SUCCESS, , "Failed to open source file in read mode");
1825 AppLogDebug("FileManageWorkerThread::Copy:%s", GetErrorMessage(r));
1827 r = destFile.Construct(destPath, "w+");
1828 TryCatch(r == E_SUCCESS, , "Failed to open destination file in write mode");
1830 count = sourceFIle.Read(byteToWrite, BUFFER_SIZE_MAX);
1831 AppLogDebug("FileManageWorkerThread::Copy:%d", count);
1834 if (__threadRunningState != THREAD_RUNNING_STATE_ALIVE)
1836 File::Remove(destPath);
1839 if (!IsFailed(GetLastResult()))
1841 destFile.Write(byteToWrite, BUFFER_SIZE_MAX);
1842 count = sourceFIle.Read(byteToWrite, BUFFER_SIZE_MAX);