diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:42 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:42 +0200 |
commit | c32707148292d104c66276b43796d6057c8c7a5d (patch) | |
tree | bb83513f4aff24153e21a4ec92e34e4c27651b1f /shared/shadow.cpp | |
parent | 3.9 (diff) | |
download | FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.gz FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.bz2 FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.zip |
3.10
Diffstat (limited to 'shared/shadow.cpp')
-rw-r--r-- | shared/shadow.cpp | 38 |
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()); } |