summaryrefslogtreecommitdiff
path: root/zen/IFileOperation/file_op.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zen/IFileOperation/file_op.cpp')
-rw-r--r--zen/IFileOperation/file_op.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/zen/IFileOperation/file_op.cpp b/zen/IFileOperation/file_op.cpp
index b3990ee0..8816b502 100644
--- a/zen/IFileOperation/file_op.cpp
+++ b/zen/IFileOperation/file_op.cpp
@@ -14,6 +14,7 @@
#include <zen/com_error.h>
#include <zen/scope_guard.h>
#include <zen/stl_tools.h>
+#include <zen/file_handling.h>
#include <boost/thread/tss.hpp>
@@ -98,12 +99,18 @@ public:
if (psiItem)
{
LPWSTR itemPath = nullptr;
- HRESULT hr = psiItem->GetDisplayName(SIGDN_FILESYSPATH, &itemPath);
- if (FAILED(hr))
- return hr;
- ZEN_ON_SCOPE_EXIT(::CoTaskMemFree(itemPath));
-
- currentItem = itemPath;
+ if (SUCCEEDED(psiItem->GetDisplayName(SIGDN_FILESYSPATH, &itemPath))) //will fail for long file paths > MAX_PATH!
+ {
+ ZEN_ON_SCOPE_EXIT(::CoTaskMemFree(itemPath));
+ currentItem = itemPath;
+ }
+ else if (SUCCEEDED(psiItem->GetDisplayName(SIGDN_NORMALDISPLAY, &itemPath))) //short name only; should work even for long file paths!
+ {
+ ZEN_ON_SCOPE_EXIT(::CoTaskMemFree(itemPath));
+ currentItem = itemPath;
+ }
+ else
+ currentItem = L"<unknown file>"; //give some indication that file name determination failed (rather than leaving the name empty!)
}
//"Returns S_OK if successful, or an error value otherwise. In the case of an error value, the delete operation
//and all subsequent operations pending from the call to IFileOperation are canceled."
@@ -222,7 +229,12 @@ void moveToRecycleBin(const wchar_t* fileNames[], //throw ComError
{
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || //file not existing anymore
hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))
- continue;
+ {
+ //make sure the file really is not there: Win32 by default strips trailing spaces, so we might end up here in error!
+ //on the other hand, shell layer does not support \\?\ prefix to prevent this!
+ if (!somethingExists(fileNames[i]))
+ continue;
+ }
throw ComError(std::wstring(L"Error calling \"SHCreateItemFromParsingName\" for file:\n") + L"\'" + fileNames[i] + L"\'.", hr);
}
@@ -231,7 +243,7 @@ void moveToRecycleBin(const wchar_t* fileNames[], //throw ComError
++operationCount;
}
- if (operationCount == 0) //calling PerformOperations() without anything to do would yielt E_UNEXPECTED
+ if (operationCount == 0) //calling PerformOperations() without anything to do would yield E_UNEXPECTED
return;
//perform planned operations
bgstack15