summaryrefslogtreecommitdiff
path: root/shared/shadow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared/shadow.cpp')
-rw-r--r--shared/shadow.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/shared/shadow.cpp b/shared/shadow.cpp
index b38103de..39f21d2a 100644
--- a/shared/shadow.cpp
+++ b/shared/shadow.cpp
@@ -14,6 +14,7 @@
#include "build_info.h"
#include "ShadowCopy\shadow.h"
#include "string_conv.h"
+#include "Loki/ScopeGuard.h"
using shadow::ShadowCopy;
using shadow::WaitingForShadow;
@@ -41,17 +42,17 @@ bool newerThanXP()
bool runningWOW64() //test if process is running under WOW64 (reference http://msdn.microsoft.com/en-us/library/ms684139(VS.85).aspx)
{
//dynamically load windows API function
- typedef BOOL (WINAPI *IsWow64ProcessFunc)(
+ typedef BOOL (WINAPI *IsWow64ProcessFun)(
HANDLE hProcess,
PBOOL Wow64Process);
- static const IsWow64ProcessFunc isWow64Process =
- util::loadDllFunction<IsWow64ProcessFunc>(L"kernel32.dll", "IsWow64Process");
+ static const IsWow64ProcessFun isWow64Process =
+ util::getDllFun<IsWow64ProcessFun>(L"kernel32.dll", "IsWow64Process");
if (isWow64Process)
{
BOOL isWow64 = FALSE;
- if ((*isWow64Process)(::GetCurrentProcess(), &isWow64))
+ if (isWow64Process(::GetCurrentProcess(), &isWow64))
return isWow64 == TRUE;
}
@@ -86,7 +87,6 @@ const std::wstring& getShadowDllName()
//#############################################################################################################
ShadowCopy::ShadowCopy(WaitingForShadow* callback) : callback_(callback) {}
-ShadowCopy::~ShadowCopy() {} //std::auto_ptr: keep non-inline
//#############################################################################################################
@@ -94,16 +94,15 @@ class ShadowCopy::ShadowVolume
{
public:
ShadowVolume(const Zstring& volumeNameFormatted) : //throw(FileError)
- realVol(volumeNameFormatted),
- backupHandle(NULL)
+ backupHandle(0)
{
using namespace shadow;
if (!createShadowCopy)
- createShadowCopy = util::loadDllFunction<CreateShadowCopyFct>(getShadowDllName(), createShadowCopyFctName);
+ createShadowCopy = util::getDllFun<CreateShadowCopyFct>(getShadowDllName(), createShadowCopyFctName);
if (!releaseShadowCopy)
- releaseShadowCopy = util::loadDllFunction<ReleaseShadowCopyFct>(getShadowDllName(), releaseShadowCopyFctName);
+ releaseShadowCopy = util::getDllFun<ReleaseShadowCopyFct>(getShadowDllName(), releaseShadowCopyFctName);
//check if shadow copy dll was loaded correctly
if ( createShadowCopy == NULL ||
@@ -138,7 +137,7 @@ public:
~ShadowVolume()
{
- releaseShadowCopy(backupHandle);
+ releaseShadowCopy(backupHandle); //fast! no performance optimization necessary
}
Zstring getShadowVolume() const //trailing path separator
@@ -146,11 +145,6 @@ public:
return shadowVol;
}
- Zstring getRealVolume() const //trailing path separator
- {
- return realVol;
- }
-
private:
ShadowVolume(const ShadowVolume&);
ShadowVolume& operator=(const ShadowVolume&);
@@ -159,9 +153,8 @@ private:
static shadow::ReleaseShadowCopyFct releaseShadowCopy;
Zstring shadowVol;
- const Zstring realVol;
- void* backupHandle;
+ ShadowHandle backupHandle;
};
@@ -195,9 +188,14 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile)
throw FileError(msg);
}
- if (!shadowVol.get() || shadowVol->getRealVolume() != volumeNameFormatted)
- shadowVol.reset(new ShadowVolume(volumeNameFormatted)); //throw (FileError)
+ //get or create instance of shadow volume
+ VolNameShadowMap::const_iterator iter = shadowVol.find(volumeNameFormatted);
+ if (iter == shadowVol.end())
+ {
+ boost::shared_ptr<ShadowVolume> newEntry(new ShadowVolume(volumeNameFormatted));
+ iter = shadowVol.insert(std::make_pair(volumeNameFormatted, newEntry)).first;
+ }
//return filename alias on shadow copy volume
- return shadowVol->getShadowVolume() + Zstring(inputFile.c_str() + pos + volumeNameFormatted.length());
+ return iter->second->getShadowVolume() + Zstring(inputFile.c_str() + pos + volumeNameFormatted.length());
}
bgstack15