diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:19:14 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:19:14 +0200 |
commit | 01eb8253196672c969a39587e90b49321a182428 (patch) | |
tree | 4a3b71d7913de519744466c9227fda6461c4f0b5 /lib/shadow.cpp | |
parent | 5.0 (diff) | |
download | FreeFileSync-01eb8253196672c969a39587e90b49321a182428.tar.gz FreeFileSync-01eb8253196672c969a39587e90b49321a182428.tar.bz2 FreeFileSync-01eb8253196672c969a39587e90b49321a182428.zip |
5.1
Diffstat (limited to 'lib/shadow.cpp')
-rw-r--r-- | lib/shadow.cpp | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/lib/shadow.cpp b/lib/shadow.cpp index d00aa2f3..0a34ae5a 100644 --- a/lib/shadow.cpp +++ b/lib/shadow.cpp @@ -20,7 +20,6 @@ namespace { 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* IsWow64ProcessFun)(HANDLE hProcess, PBOOL Wow64Process); const SysDllFun<IsWow64ProcessFun> isWow64Process(L"kernel32.dll", "IsWow64Process"); @@ -47,41 +46,36 @@ public: getShadowVolume (getDllName(), getShadowVolumeFctName), backupHandle(nullptr) { - //check if shadow copy dll was loaded correctly - if (!createShadowCopy || !releaseShadowCopy || !getShadowVolume) - throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" + - _("Could not load a required DLL:") + L" \"" + getDllName() + L"\""); - //VSS does not support running under WOW64 except for Windows XP and Windows Server 2003 //(Reference: http://msdn.microsoft.com/en-us/library/aa384627(VS.85).aspx) if (runningWOW64()) throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" + _("Making shadow copies on WOW64 is not supported. Please use FreeFileSync 64-bit version.")); + + //check if shadow copy dll was loaded correctly + if (!createShadowCopy || !releaseShadowCopy || !getShadowVolume) + throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" + + replaceCpy(_("Cannot load file %x."), L"%x", std::wstring(L"\"") + getDllName() + L"\"")); + //--------------------------------------------------------------------------------------------------------- //start shadow volume copy service: - wchar_t errorMessage[1000]; + const unsigned int BUFFER_SIZE = 10000; + std::vector<wchar_t> msgBuffer(BUFFER_SIZE); backupHandle = createShadowCopy(volumeNameFormatted.c_str(), - errorMessage, - 1000); + &msgBuffer[0], BUFFER_SIZE); if (!backupHandle) throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" + - L"(" + errorMessage + L" Volume: \"" + volumeNameFormatted + L"\")"); + &msgBuffer[0] + L" Volume: \"" + volumeNameFormatted + L"\""); - wchar_t shadowVolName[1000]; - getShadowVolume(backupHandle, shadowVolName, 1000); - shadowVol = Zstring(shadowVolName) + FILE_NAME_SEPARATOR; //shadowVolName NEVER has a trailing backslash + std::vector<wchar_t> volBuffer(BUFFER_SIZE); + getShadowVolume(backupHandle, &volBuffer[0], BUFFER_SIZE); + shadowVol = Zstring(&volBuffer[0]) + FILE_NAME_SEPARATOR; //shadowVolName NEVER has a trailing backslash } - ~ShadowVolume() - { - releaseShadowCopy(backupHandle); //fast! no performance optimization necessary - } + ~ShadowVolume() { releaseShadowCopy(backupHandle); } //fast! no performance optimization necessary - Zstring getShadowVolumeName() const //trailing path separator - { - return shadowVol; - } + Zstring getShadowVolumeName() const { return shadowVol; } //with trailing path separator private: ShadowVolume(const ShadowVolume&); @@ -100,14 +94,13 @@ private: Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile) { - wchar_t volumeNameRaw[1000]; - + std::vector<wchar_t> volBuffer(1000); if (!::GetVolumePathName(inputFile.c_str(), //__in LPCTSTR lpszFileName, - volumeNameRaw, //__out LPTSTR lpszVolumePathName, - 1000)) //__in DWORD cchBufferLength - throw FileError(_("Could not determine volume name for file:") + L"\n\"" + inputFile + L"\""); + &volBuffer[0], //__out LPTSTR lpszVolumePathName, + static_cast<DWORD>(volBuffer.size()))) //__in DWORD cchBufferLength + throw FileError(_("Cannot determine volume name for file:") + L"\n\"" + inputFile + L"\""); - Zstring volumeNameFormatted = volumeNameRaw; + Zstring volumeNameFormatted = &volBuffer[0]; if (!endsWith(volumeNameFormatted, FILE_NAME_SEPARATOR)) volumeNameFormatted += FILE_NAME_SEPARATOR; @@ -115,7 +108,7 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile) const size_t pos = inputFile.find(volumeNameFormatted); //inputFile needs NOT to begin with volumeNameFormatted: consider for example \\?\ prefix! if (pos == Zstring::npos) { - std::wstring msg = _("Volume name %x not part of filename %y!"); + std::wstring msg = _("Volume name %x not part of file name %y!"); replace(msg, L"%x", std::wstring(L"\"") + volumeNameFormatted + L"\"", false); replace(msg, L"%y", std::wstring(L"\"") + inputFile + L"\"", false); throw FileError(msg); @@ -125,7 +118,7 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile) VolNameShadowMap::const_iterator iter = shadowVol.find(volumeNameFormatted); if (iter == shadowVol.end()) { - std::shared_ptr<ShadowVolume> newEntry(new ShadowVolume(volumeNameFormatted)); + auto newEntry = std::make_shared<ShadowVolume>(volumeNameFormatted); iter = shadowVol.insert(std::make_pair(volumeNameFormatted, newEntry)).first; } |