summaryrefslogtreecommitdiff
path: root/shared/recycler.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:56 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:56 +0200
commit98ecf620f7de377dc8ae9ad7fbd1e3b24477e138 (patch)
treefaadc6d8822c20cd3bc6f50b2a98e6c580585949 /shared/recycler.cpp
parent3.16 (diff)
downloadFreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.gz
FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.bz2
FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.zip
3.17
Diffstat (limited to 'shared/recycler.cpp')
-rw-r--r--shared/recycler.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/shared/recycler.cpp b/shared/recycler.cpp
index 4fedf01f..32de3f33 100644
--- a/shared/recycler.cpp
+++ b/shared/recycler.cpp
@@ -73,7 +73,7 @@ Nevertheless, let's use IFileOperation for better error reporting!
void moveToWindowsRecycler(const std::vector<Zstring>& filesToDelete) //throw (FileError)
{
- using ffs3::FileError;
+ using zen::FileError;
if (filesToDelete.empty())
return;
@@ -97,21 +97,21 @@ void moveToWindowsRecycler(const std::vector<Zstring>& filesToDelete) //throw (
getLastError = util::getDllFun<GetLastErrorFct>(getRecyclerDllName().c_str(), getLastErrorFctName);
if (moveToRecycler == NULL || getLastError == NULL)
- throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + fileNames[0] + wxT("\"\n\n") + //report first file only... better than nothing
- wxString(_("Could not load a required DLL:")) + wxT(" \"") + getRecyclerDllName().c_str() + wxT("\""));
+ throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + fileNames[0] + wxT("\"") + //report first file only... better than nothing
+ wxT("\n\n") + wxString(_("Could not load a required DLL:")) + wxT(" \"") + getRecyclerDllName().c_str() + wxT("\""));
//#warning moving long file paths to recycler does not work! clarify!
// std::vector<Zstring> temp;
// std::transform(filesToDelete.begin(), filesToDelete.end(),
- // std::back_inserter(temp), std::ptr_fun(ffs3::removeLongPathPrefix)); //::IFileOperation() can't handle \\?\-prefix!
+ // std::back_inserter(temp), std::ptr_fun(zen::removeLongPathPrefix)); //::IFileOperation() can't handle \\?\-prefix!
if (!moveToRecycler(&fileNames[0], //array must not be empty
fileNames.size()))
{
wchar_t errorMessage[2000];
getLastError(errorMessage, 2000);
- throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + fileNames[0] + wxT("\"\n\n") + //report first file only... better than nothing
- wxT("(") + errorMessage + wxT(")"));
+ throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + fileNames[0] + wxT("\"") + //report first file only... better than nothing
+ wxT("\n\n") + wxT("(") + errorMessage + wxT(")"));
}
}
else //regular recycle bin usage: available since XP
@@ -146,19 +146,24 @@ void moveToWindowsRecycler(const std::vector<Zstring>& filesToDelete) //throw (
}
-bool ffs3::moveToRecycleBin(const Zstring& fileToDelete) //throw (FileError)
+bool zen::moveToRecycleBin(const Zstring& fileToDelete) //throw (FileError)
{
#ifdef FFS_WIN
const Zstring filenameFmt = applyLongPathPrefix(fileToDelete);
- if (::GetFileAttributes(filenameFmt.c_str()) == INVALID_FILE_ATTRIBUTES)
+
+ const DWORD attr = ::GetFileAttributes(filenameFmt.c_str());
+ if (attr == INVALID_FILE_ATTRIBUTES)
return false; //neither file nor any other object with that name existing: no error situation, manual deletion relies on it!
+ //::SetFileAttributes(filenameFmt.c_str(), FILE_ATTRIBUTE_NORMAL);
+
+ //both SHFileOperation and useIFileOperation are not able to delete a folder named "System Volume Information" with normal attributes but shamelessly report success
std::vector<Zstring> fileNames;
fileNames.push_back(fileToDelete);
::moveToWindowsRecycler(fileNames); //throw (FileError)
#elif defined FFS_LINUX
- struct stat fileInfo;
+ struct stat fileInfo = {};
if (::lstat(fileToDelete.c_str(), &fileInfo) != 0)
return false; //neither file nor any other object with that name existing: no error situation, manual deletion relies on it!
@@ -168,8 +173,8 @@ bool ffs3::moveToRecycleBin(const Zstring& fileToDelete) //throw (FileError)
try
{
if (!fileObj->trash())
- throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + zToWx(fileToDelete) + wxT("\"\n\n") +
- wxT("(") + wxT("unknown error") + wxT(")"));
+ throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + zToWx(fileToDelete) + wxT("\"") +
+ wxT("\n\n") + wxT("(") + wxT("unknown error") + wxT(")"));
}
catch (const Glib::Error& errorObj)
{
@@ -177,15 +182,15 @@ bool ffs3::moveToRecycleBin(const Zstring& fileToDelete) //throw (FileError)
const wxString errorMessage = wxString(wxT("Glib Error Code ")) + wxString::Format(wxT("%i"), errorObj.code()) + wxT(", ") +
wxString::FromUTF8(g_quark_to_string(errorObj.domain())) + wxT(": ") + wxString::FromUTF8(errorObj.what().c_str());
- throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + zToWx(fileToDelete) + wxT("\"\n\n") +
- wxT("(") + errorMessage + wxT(")"));
+ throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + zToWx(fileToDelete) + wxT("\"") +
+ wxT("\n\n") + wxT("(") + errorMessage + wxT(")"));
}
#endif
-return true;
+ return true;
}
-bool ffs3::recycleBinExists()
+bool zen::recycleBinExists()
{
#ifdef FFS_WIN
return true;
bgstack15