summaryrefslogtreecommitdiff
path: root/library/Recycler_Vista
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:05:30 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:05:30 +0200
commitc0fce877c478ddbf71a1b651c789e5ea00a00144 (patch)
treede01b0ae8fd296bd24fbca54a80f2f0ba071d461 /library/Recycler_Vista
parent3.3 (diff)
downloadFreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.tar.gz
FreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.tar.bz2
FreeFileSync-c0fce877c478ddbf71a1b651c789e5ea00a00144.zip
3.4
Diffstat (limited to 'library/Recycler_Vista')
-rw-r--r--library/Recycler_Vista/Recycler_Vista.vcproj409
-rw-r--r--library/Recycler_Vista/dllmain.cpp27
-rw-r--r--library/Recycler_Vista/recycler.cpp148
-rw-r--r--library/Recycler_Vista/recycler.h30
4 files changed, 614 insertions, 0 deletions
diff --git a/library/Recycler_Vista/Recycler_Vista.vcproj b/library/Recycler_Vista/Recycler_Vista.vcproj
new file mode 100644
index 00000000..65ab6609
--- /dev/null
+++ b/library/Recycler_Vista/Recycler_Vista.vcproj
@@ -0,0 +1,409 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="Vista Recycler"
+ ProjectGUID="{70394AEF-5897-4911-AFA1-82EAF0581EFA}"
+ RootNamespace="ShadowDll"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ IntermediateDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ ConfigurationType="2"
+ CharacterSet="1"
+ BuildLogFile="$(IntDir)\Build.html"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="_DEBUG;_WINDOWS;_USRDLL;RECYCLER_DLL_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ SuppressStartupBanner="false"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Recycler_$(PlatformName).dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="false"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(IntDir)$(TargetName).pdb"
+ SubSystem="2"
+ ProfileGuidedDatabase=""
+ ImportLibrary="$(IntDir)$(TargetName).lib"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ IntermediateDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ ConfigurationType="2"
+ CharacterSet="1"
+ BuildLogFile="$(IntDir)\Build.html"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="_DEBUG;_WINDOWS;_USRDLL;RECYCLER_DLL_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ SuppressStartupBanner="false"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Recycler_$(PlatformName).dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="false"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(IntDir)$(TargetName).pdb"
+ SubSystem="2"
+ ProfileGuidedDatabase=""
+ ImportLibrary="$(IntDir)$(TargetName).lib"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ IntermediateDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ BuildLogFile="$(IntDir)\Build.html"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="NDEBUG;_WINDOWS;_USRDLL;RECYCLER_DLL_EXPORTS"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ SuppressStartupBanner="false"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Recycler_$(PlatformName).dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="false"
+ GenerateDebugInformation="false"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ ProfileGuidedDatabase=""
+ ImportLibrary="$(IntDir)$(TargetName).lib"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ IntermediateDirectory="OBJ\$(ProjectName)_$(ConfigurationName)_$(PlatformName)\"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ BuildLogFile="$(IntDir)\Build.html"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="NDEBUG;_WINDOWS;_USRDLL;RECYCLER_DLL_EXPORTS"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ SuppressStartupBanner="false"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="Recycler_$(PlatformName).dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="false"
+ GenerateDebugInformation="false"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ LinkTimeCodeGeneration="1"
+ ProfileGuidedDatabase=""
+ ImportLibrary="$(IntDir)$(TargetName).lib"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Quelldateien"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\dllmain.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|x64"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|x64"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Headerdateien"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\recycler.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\recycler.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/library/Recycler_Vista/dllmain.cpp b/library/Recycler_Vista/dllmain.cpp
new file mode 100644
index 00000000..7db39bff
--- /dev/null
+++ b/library/Recycler_Vista/dllmain.cpp
@@ -0,0 +1,27 @@
+// **************************************************************************
+// * 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) *
+// **************************************************************************
+//
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+
+BOOL APIENTRY DllMain( HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved
+ )
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+
diff --git a/library/Recycler_Vista/recycler.cpp b/library/Recycler_Vista/recycler.cpp
new file mode 100644
index 00000000..7858267b
--- /dev/null
+++ b/library/Recycler_Vista/recycler.cpp
@@ -0,0 +1,148 @@
+// **************************************************************************
+// * 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"
+
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+#include <Shellapi.h> // Included for shell constants such as FO_* values
+#include <shobjidl.h> // Required for necessary shell dependencies
+
+#include <algorithm>
+#include <string>
+#include <cstdio>
+#include <comdef.h>
+
+
+void writeString(const wchar_t* input, wchar_t* output, size_t outputBufferLen)
+{
+ const size_t newSize = min(wcslen(input) + 1, outputBufferLen); //including null-termination
+ memcpy(output, input, newSize * sizeof(wchar_t));
+ output[newSize-1] = 0; //if output buffer is too small...
+}
+
+
+std::wstring numberToHexString(const long number)
+{
+ wchar_t result[100];
+ swprintf(result, 100, L"0x%08x", number);
+ return std::wstring(result);
+}
+
+
+void writeErrorMsg(const wchar_t* input, HRESULT hr, wchar_t* output, size_t outputBufferLen)
+{
+ std::wstring formattedMsg(input);
+ formattedMsg += L" (";
+ formattedMsg += numberToHexString(hr);
+ formattedMsg += L": ";
+ formattedMsg += _com_error(hr).ErrorMessage();
+ formattedMsg += L")";
+
+ writeString(formattedMsg.c_str(), output, outputBufferLen);
+}
+
+
+//IShellItem resource management
+template <class T>
+class ReleaseAtExit
+{
+public:
+ ReleaseAtExit(T*& item) : item_(item) {}
+ ~ReleaseAtExit()
+ {
+ if (item_ != NULL)
+ item_->Release();
+ }
+private:
+ T*& item_;
+};
+
+
+bool Utility::moveToRecycleBin(const wchar_t* fileNames[],
+ size_t fileNo, //size of fileNames array
+ wchar_t* errorMessage,
+ size_t errorBufferLen)
+{
+ HRESULT hr;
+
+ // Create the IFileOperation interface
+ IFileOperation* pfo = NULL;
+ ReleaseAtExit<IFileOperation> dummy(pfo);
+ hr = CoCreateInstance(CLSID_FileOperation,
+ NULL,
+ CLSCTX_ALL,
+ IID_PPV_ARGS(&pfo));
+ if (FAILED(hr))
+ {
+ writeErrorMsg(L"Error calling \"CoCreateInstance\".", hr, errorMessage, errorBufferLen);
+ return false;
+ }
+
+ // Set the operation flags. Turn off all UI
+ // from being shown to the user during the
+ // operation. This includes error, confirmation
+ // and progress dialogs.
+ hr = pfo->SetOperationFlags(FOF_ALLOWUNDO |
+ FOF_NOCONFIRMATION |
+ FOF_SILENT |
+ FOF_NOERRORUI);
+ if (FAILED(hr))
+ {
+ writeErrorMsg(L"Error calling \"SetOperationFlags\".", hr, errorMessage, errorBufferLen);
+ return false;
+ }
+
+ for (size_t i = 0; i < fileNo; ++i)
+ {
+ //create file/folder item object
+ IShellItem* psiFile = NULL;
+ ReleaseAtExit<IShellItem> dummy2(psiFile);
+ hr = SHCreateItemFromParsingName(fileNames[i],
+ NULL,
+ IID_PPV_ARGS(&psiFile));
+ if (FAILED(hr))
+ {
+ std::wstring message(L"Error calling \"SHCreateItemFromParsingName\" for file ");
+ message += std::wstring(L"\"") + fileNames[i] + L"\".";
+ writeErrorMsg(message.c_str(), hr, errorMessage, errorBufferLen);
+ return false;
+ }
+
+ hr = pfo->DeleteItem(psiFile, NULL);
+ if (FAILED(hr))
+ {
+ writeErrorMsg(L"Error calling \"DeleteItem\".", hr, errorMessage, errorBufferLen);
+ return false;
+ }
+ }
+
+ //perform actual operations
+ hr = pfo->PerformOperations();
+ if (FAILED(hr))
+ {
+ writeErrorMsg(L"Error calling \"PerformOperations\".", hr, errorMessage, errorBufferLen);
+ return false;
+ }
+
+ //check if errors occured: if FOFX_EARLYFAILURE is not used, PerformOperations() can return with success despite errors!
+ BOOL pfAnyOperationsAborted = FALSE;
+ hr = pfo->GetAnyOperationsAborted(&pfAnyOperationsAborted);
+ if (FAILED(hr))
+ {
+ writeErrorMsg(L"Error calling \"GetAnyOperationsAborted\".", hr, errorMessage, errorBufferLen);
+ return false;
+ }
+
+
+ if (pfAnyOperationsAborted == TRUE)
+ {
+ writeString(L"Operation did not complete successfully.", errorMessage, errorBufferLen);
+ return false;
+ }
+
+ return true;
+}
diff --git a/library/Recycler_Vista/recycler.h b/library/Recycler_Vista/recycler.h
new file mode 100644
index 00000000..697221c3
--- /dev/null
+++ b/library/Recycler_Vista/recycler.h
@@ -0,0 +1,30 @@
+// **************************************************************************
+// * 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) *
+// **************************************************************************
+//
+#ifndef RECYCLER_DLL_H
+#define RECYCLER_DLL_H
+
+#ifdef RECYCLER_DLL_EXPORTS
+#define RECYCLER_DLL_API extern "C" __declspec(dllexport)
+#else
+#define RECYCLER_DLL_API extern "C" __declspec(dllimport)
+#endif
+
+
+namespace Utility
+{
+//COM needs to be initialized before calling any of these functions! CoInitializeEx/CoUninitialize
+
+RECYCLER_DLL_API
+bool moveToRecycleBin(const wchar_t* fileNames[],
+ size_t fileNo, //size of fileNames array
+ wchar_t* errorMessage,
+ size_t errorBufferLen);
+}
+
+
+
+#endif //RECYCLER_DLL_H
bgstack15