From 6fbf5e8f64a3064a8d59623154ad42f5590c180d Mon Sep 17 00:00:00 2001 From: Anssi Hannula Date: Sun, 10 Oct 2010 20:22:18 +0300 Subject: [PATCH 4/7] added: ActionReplace action type to CFileOperationJob Add new action type ActionReplace to CFileOperationJob. This is the same as the ActionCopy operation with one exception: when copying directories, the destination directory is emptied first. This is useful when e.g. installing a new version of an addon. If any files have been dropped from the new version, we don't want to leave them in the addon directory. --- xbmc/utils/FileOperationJob.cpp | 6 +++++- xbmc/utils/FileOperationJob.h | 1 + 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/xbmc/utils/FileOperationJob.cpp b/xbmc/utils/FileOperationJob.cpp index a52e6037..e22e213 100644 --- a/xbmc/utils/FileOperationJob.cpp +++ b/xbmc/utils/FileOperationJob.cpp @@ -67,7 +67,7 @@ bool CFileOperationJob::DoProcessFile(FileAction action, const CStdString& strFi { int64_t time = 1; - if (action == ActionCopy || (action == ActionMove && !CanBeRenamed(strFileA, strFileB))) + if (action == ActionCopy || action == ActionReplace || (action == ActionMove && !CanBeRenamed(strFileA, strFileB))) { struct __stat64 data; if(CFile::Stat(strFileA, &data) == 0) @@ -149,6 +149,8 @@ bool CFileOperationJob::DoProcess(FileAction action, CFileItemList & items, cons // create folder on dest. drive if (action != ActionDelete) DoProcessFile(ActionCreateFolder, strnewDestFile, "", fileOperations, totalTime); + if (action == ActionReplace) + DoProcessFolder(ActionDelete, strnewDestFile, "", fileOperations, totalTime); if (!DoProcessFolder(action, pItem->m_strPath, strnewDestFile, fileOperations, totalTime)) return false; if (action == ActionDelete) @@ -181,6 +183,7 @@ bool CFileOperationJob::CFileOperation::ExecuteOperation(CFileOperationJob *base switch (m_action) { case ActionCopy: + case ActionReplace: base->m_currentOperation = g_localizeStrings.Get(115); break; case ActionMove: @@ -206,6 +209,7 @@ bool CFileOperationJob::CFileOperation::ExecuteOperation(CFileOperationJob *base switch (m_action) { case ActionCopy: + case ActionReplace: { CLog::Log(LOGDEBUG,"FileManager: copy %s->%s\n", m_strFileA.c_str(), m_strFileB.c_str()); diff --git a/xbmc/utils/FileOperationJob.h b/xbmc/utils/FileOperationJob.h index ff449ce..b331b88 100644 --- a/xbmc/utils/FileOperationJob.h +++ b/xbmc/utils/FileOperationJob.h @@ -33,6 +33,7 @@ public: ActionCopy = 1, ActionMove, ActionDelete, + ActionReplace, ///< Copy, emptying any existing destination directories first ActionCreateFolder, ActionDeleteFolder, }; -- 1.7.3