diff options
Diffstat (limited to 'shared/ShadowCopy/shadow.cpp')
-rw-r--r-- | shared/ShadowCopy/shadow.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/shared/ShadowCopy/shadow.cpp b/shared/ShadowCopy/shadow.cpp index 2e739146..a5c280e8 100644 --- a/shared/ShadowCopy/shadow.cpp +++ b/shared/ShadowCopy/shadow.cpp @@ -5,11 +5,15 @@ // ************************************************************************** // #include "shadow.h" +#include <algorithm> +#include <string> +#include <comdef.h> +#include "../com_ptr.h" +#include "../com_error.h" +#include "../c_dll.h" #define WIN32_LEAN_AND_MEAN #include "windows.h" -#include "../com_ptr.h" -#include "../com_error.h" #ifdef USE_SHADOW_XP #include "xp/inc/vss.h" @@ -24,41 +28,32 @@ adapt! #endif -#include <algorithm> -#include <string> -#include <cstdio> -#include <comdef.h> +using namespace c_dll; -//typedef GUID VSS_ID; - -void writeString(const wchar_t* input, wchar_t* output, unsigned int outputBufferLen) +namespace { - 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... -} - +typedef HandleProvider<shadow::ShadowHandle, util::ComPtr<IVssBackupComponents> > HandleShadowMap; void writeErrorMsg(const wchar_t* input, HRESULT hr, wchar_t* output, unsigned int outputBufferLen) { - writeString(Util::generateErrorMsg(input, hr).c_str(), output, outputBufferLen); + writeString(util::generateErrorMsg(input, hr).c_str(), output, outputBufferLen); +} } - bool shadow::createShadowCopy(const wchar_t* volumeName, wchar_t* shadowVolName, unsigned int shadowBufferLen, - void** backupHandle, + ShadowHandle* handle, wchar_t* errorMessage, unsigned int errorBufferLen) { - using Util::ComPtr; - using Util::generateErrorMsg; + using util::ComPtr; + using util::generateErrorMsg; //MessageBox(0, L"backup err", L"", 0); */ - *backupHandle = NULL; + *handle = 0; HRESULT hr = NULL; ComPtr<IVssBackupComponents> backupComp; @@ -171,14 +166,13 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, VssFreeSnapshotProperties(&props); - *backupHandle = backupComp.release(); //release ownership + *handle = HandleShadowMap::instance().insert(backupComp); return true; } -void shadow::releaseShadowCopy(void* backupHandle) +void shadow::releaseShadowCopy(ShadowHandle handle) { - if (backupHandle != NULL) - static_cast<IVssBackupComponents*>(backupHandle)->Release(); + HandleShadowMap::instance().remove(handle); } |