summaryrefslogtreecommitdiff
path: root/shared/recycler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared/recycler.cpp')
-rw-r--r--shared/recycler.cpp102
1 files changed, 90 insertions, 12 deletions
diff --git a/shared/recycler.cpp b/shared/recycler.cpp
index b3bb87dd..4b5a4639 100644
--- a/shared/recycler.cpp
+++ b/shared/recycler.cpp
@@ -1,13 +1,38 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+//
#include "recycler.h"
-#include "dllLoader.h"
+#include "stringConv.h"
#include <wx/intl.h>
+#include <stdexcept>
+
+#ifdef FFS_WIN
+#include "dllLoader.h"
#include <wx/msw/wrapwin.h> //includes "windows.h"
#include "buildInfo.h"
#include "staticAssert.h"
#include <algorithm>
#include <functional>
-//#include "../shared/longPathPrefix.h"
+#include <vector>
+#include "longPathPrefix.h"
+
+#elif defined FFS_LINUX
+#include <sys/stat.h>
+
+#ifdef RECYCLER_GIO
+#include <gio/gio.h>
+#include <boost/shared_ptr.hpp>
+#endif
+#endif
+
+
+namespace
+{
+#ifdef FFS_WIN
const std::wstring& getRecyclerDllName()
{
static const std::wstring filename(
@@ -49,16 +74,10 @@ IFileOperation - multiple files 2,1s
Nevertheless, let's use IFileOperation for better error reporting!
*/
-void FreeFileSync::moveToWindowsRecycler(const Zstring& fileToDelete) //throw (FileError)
+void moveToWindowsRecycler(const std::vector<Zstring>& filesToDelete) //throw (FileError)
{
- std::vector<Zstring> fileNames;
- fileNames.push_back(fileToDelete);
- moveToWindowsRecycler(fileNames); //throw (FileError)
-}
-
+ using FreeFileSync::FileError;
-void FreeFileSync::moveToWindowsRecycler(const std::vector<Zstring>& filesToDelete) //throw (FileError)
-{
if (filesToDelete.empty())
return;
@@ -93,8 +112,7 @@ void FreeFileSync::moveToWindowsRecycler(const std::vector<Zstring>& filesToDele
errorMessage,
2000))
{
- throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + fileNames[0] + wxT("\"") + //report first file only... better than nothing
- + wxT("\n\n") +
+ 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(")"));
}
}
@@ -125,4 +143,64 @@ void FreeFileSync::moveToWindowsRecycler(const std::vector<Zstring>& filesToDele
}
}
}
+#endif
+}
+
+void FreeFileSync::moveToRecycleBin(const Zstring& fileToDelete) //throw (FileError)
+{
+#ifdef FFS_WIN
+ const Zstring filenameFmt = applyLongPathPrefix(fileToDelete);
+ if (::GetFileAttributes(filenameFmt.c_str()) == INVALID_FILE_ATTRIBUTES)
+ return; //neither file nor any other object with that name existing: no error situation, manual deletion relies on it!
+
+ std::vector<Zstring> fileNames;
+ fileNames.push_back(fileToDelete);
+ ::moveToWindowsRecycler(fileNames); //throw (FileError)
+
+#elif defined FFS_LINUX
+ struct stat fileInfo;
+ if (::lstat(fileToDelete.c_str(), &fileInfo) != 0)
+ return; //neither file nor any other object with that name existing: no error situation, manual deletion relies on it!
+
+#ifdef RECYCLER_GIO
+ boost::shared_ptr<GFile> fileObj(g_file_new_for_path(fileToDelete.c_str()), &g_object_unref);
+ GError* error = NULL;
+ if (g_file_trash(fileObj.get(), NULL, &error) == FALSE)
+ {
+ if (!error)
+ throw std::runtime_error("Recycle Bin failed but did not provide error information!");
+
+ boost::shared_ptr<GError> errorObj(error, &g_error_free);
+
+ //assemble error message
+ const wxString errorMessage = wxString(wxT("Error Code ")) + wxString::Format(wxT("%i"), errorObj->code) +
+ + wxT(", ") + wxString::FromUTF8(g_quark_to_string(errorObj->domain)) + wxT(": ") + wxString::FromUTF8(errorObj->message);
+ throw FileError(wxString(_("Error moving to Recycle Bin:")) + wxT("\n\"") + zToWx(fileToDelete) + wxT("\"\n\n") +
+ wxT("(") + errorMessage + wxT(")"));
+ }
+
+#elif defined RECYCLER_NONE
+ throw std::logic_error("No Recycler for this Linux version available at the moment!"); //user will never arrive here: recycler option cannot be activated in this case!
+#endif
+
+#endif
+}
+
+
+bool FreeFileSync::recycleBinExists()
+{
+#ifdef FFS_WIN
+ return true;
+#elif defined FFS_LINUX
+
+#ifdef RECYCLER_GIO
+ return true;
+#elif defined RECYCLER_NONE
+ return false;
+#else
+you have to choose a recycler!
+#endif
+
+#endif
+}
bgstack15