Revert changes to CFileOperationJob that were made on false assumptions.
authorJonathan Marshall <jmarshall@never.you.mind>
Tue, 4 Jun 2013 21:57:22 +0000 (09:57 +1200)
committerJonathan Marshall <jmarshall@never.you.mind>
Tue, 4 Jun 2013 21:59:11 +0000 (09:59 +1200)
This reverts commit 1542c3328361f949fe3644f6d260316f8d4de189.
This reverts commit 77c15c4dda8490d43648b7e095f9614858fd94aa.

xbmc/utils/FileOperationJob.cpp

index 3e6345f..e95baa1 100644 (file)
@@ -151,61 +151,57 @@ bool CFileOperationJob::DoProcess(FileAction action, CFileItemList & items, cons
   for (int iItem = 0; iItem < items.Size(); ++iItem)
   {
     CFileItemPtr pItem = items[iItem];
-    if (!pItem->IsSelected())
-      continue;
-
-    if (pItem->m_bIsFolder)
-    {
-      // In ActionReplace mode all subdirectories will be removed by the below
-      // DoProcessFolder(ActionDelete) call as well, so ActionCopy is enough when
-      // processing those
-      FileAction subdirAction = (action == ActionReplace) ? ActionCopy : action;
-      // Create folder on destination drive
-      if (action != ActionDelete && action != ActionDeleteFolder)
-        DoProcessFile(ActionCreateFolder, strDestFile, "", fileOperations, totalTime);
-      if (action == ActionReplace && CDirectory::Exists(strDestFile))
-        DoProcessFolder(ActionDelete, strDestFile, "", fileOperations, totalTime);
-      if (!DoProcessFolder(subdirAction, pItem->GetPath(), strDestFile, fileOperations, totalTime))
-        return false;
-      if (action == ActionDelete || action == ActionDeleteFolder)
-        DoProcessFile(ActionDeleteFolder, pItem->GetPath(), "", fileOperations, totalTime);
-    }
-    else if (strDestFile.IsEmpty())
-    {
-      DoProcessFile(action, pItem->GetPath(), "", fileOperations, totalTime);
-    }
-    else if (URIUtils::IsUPnP(items.GetPath()) || URIUtils::IsUPnP(pItem->GetPath()))
+    if (pItem->IsSelected())
     {
-      // Get filename from label instead of path when it is UPnP
-      CStdString strNewDest = pItem->GetLabel();
+      CStdString strNoSlash = pItem->GetPath();
+      URIUtils::RemoveSlashAtEnd(strNoSlash);
+      CStdString strFileName = URIUtils::GetFileName(strNoSlash);
 
-      if (URIUtils::GetExtension(strNewDest).IsEmpty())
+      // URL Decode for cases where source uses URL encoding and target does not 
+      if ( URIUtils::ProtocolHasEncodedFilename(CURL(pItem->GetPath()).GetProtocol() )
+       && !URIUtils::ProtocolHasEncodedFilename(CURL(strDestFile).GetProtocol() ) )
+        CURL::Decode(strFileName);
+
+      // special case for upnp
+      if (URIUtils::IsUPnP(items.GetPath()) || URIUtils::IsUPnP(pItem->GetPath()))
       {
-        // FIXME: for now we only work well if the url has the extension
-        // we should map the content type to the extension otherwise
-        strNewDest += URIUtils::GetExtension(pItem->GetPath());
-      }
+        // get filename from label instead of path
+        strFileName = pItem->GetLabel();
 
-      strNewDest = CUtil::MakeLegalFileName(strNewDest);
-      strNewDest = URIUtils::AddFileToFolder(strDestFile, strNewDest);
-      DoProcessFile(action, pItem->GetPath(), strNewDest, fileOperations, totalTime);
-    }
-    else // Non UPnP item with a destination
-    {
-      CStdString strNewDest = pItem->GetPath();
-      URIUtils::RemoveSlashAtEnd(strNewDest);
-      strNewDest = URIUtils::GetFileName(strNewDest);
+        if(!pItem->m_bIsFolder && URIUtils::GetExtension(strFileName).length() == 0)
+        {
+          // FIXME: for now we only work well if the url has the extension
+          // we should map the content type to the extension otherwise
+          strFileName += URIUtils::GetExtension(pItem->GetPath());
+        }
+
+        strFileName = CUtil::MakeLegalFileName(strFileName);
+      }
 
-      // URL decode for cases where source uses URL encoding and target does not
-      if (URIUtils::ProtocolHasEncodedFilename(CURL(pItem->GetPath()).GetProtocol()) &&
-          !URIUtils::ProtocolHasEncodedFilename(CURL(strNewDest).GetProtocol()))
-        CURL::Decode(strNewDest);
+      CStdString strnewDestFile;
+      if(!strDestFile.IsEmpty()) // only do this if we have a destination
+        strnewDestFile = URIUtils::AddFileToFolder(strDestFile, strFileName);
 
-      strNewDest = URIUtils::AddFileToFolder(strDestFile, strNewDest);
-      DoProcessFile(action, pItem->GetPath(), strNewDest, fileOperations, totalTime);
+      if (pItem->m_bIsFolder)
+      {
+        // in ActionReplace mode all subdirectories will be removed by the below
+        // DoProcessFolder(ActionDelete) call as well, so ActionCopy is enough when
+        // processing those
+        FileAction subdirAction = (action == ActionReplace) ? ActionCopy : action;
+        // create folder on dest. drive
+        if (action != ActionDelete && action != ActionDeleteFolder)
+          DoProcessFile(ActionCreateFolder, strnewDestFile, "", fileOperations, totalTime);
+        if (action == ActionReplace && CDirectory::Exists(strnewDestFile))
+          DoProcessFolder(ActionDelete, strnewDestFile, "", fileOperations, totalTime);
+        if (!DoProcessFolder(subdirAction, pItem->GetPath(), strnewDestFile, fileOperations, totalTime))
+          return false;
+        if (action == ActionDelete || action == ActionDeleteFolder)
+          DoProcessFile(ActionDeleteFolder, pItem->GetPath(), "", fileOperations, totalTime);
+      }
+      else
+        DoProcessFile(action, pItem->GetPath(), strnewDestFile, fileOperations, totalTime);
     }
   }
-
   return true;
 }