summaryrefslogtreecommitdiff
path: root/lib/shadow.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
commitd2854834e18443876c8f75e0a7f3b88d1d549fc4 (patch)
treee967b628081e50abc7c34cd264e6586271c7e728 /lib/shadow.cpp
parent4.1 (diff)
downloadFreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.gz
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.bz2
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.zip
4.2
Diffstat (limited to 'lib/shadow.cpp')
-rw-r--r--lib/shadow.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/shadow.cpp b/lib/shadow.cpp
index 73a2e8f7..9bc17aff 100644
--- a/lib/shadow.cpp
+++ b/lib/shadow.cpp
@@ -44,33 +44,32 @@ public:
ShadowVolume(const Zstring& volumeNameFormatted) : //throw(FileError)
createShadowCopy (getDllName(), createShadowCopyFctName),
releaseShadowCopy(getDllName(), releaseShadowCopyFctName),
- backupHandle(0)
+ getShadowVolume (getDllName(), getShadowVolumeFctName),
+ backupHandle(nullptr)
{
//check if shadow copy dll was loaded correctly
- if (!createShadowCopy || !releaseShadowCopy)
- throw FileError(_("Error accessing Volume Shadow Copy Service!") + "\n" +
- _("Could not load a required DLL:") + " \"" + getDllName() + "\"");
+ 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!") + "\n" +
+ throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" +
_("Making shadow copies on WOW64 is not supported. Please use FreeFileSync 64-bit version."));
//---------------------------------------------------------------------------------------------------------
//start shadow volume copy service:
- wchar_t shadowVolName[1000];
wchar_t errorMessage[1000];
+ backupHandle = createShadowCopy(volumeNameFormatted.c_str(),
+ errorMessage,
+ 1000);
+ if (!backupHandle)
+ throw FileError(_("Error accessing Volume Shadow Copy Service!") + L"\n" +
+ L"(" + errorMessage + L" Volume: \"" + volumeNameFormatted + L"\")");
- if (!createShadowCopy(volumeNameFormatted.c_str(),
- shadowVolName,
- 1000,
- &backupHandle,
- errorMessage,
- 1000))
- throw FileError(_("Error accessing Volume Shadow Copy Service!") + "\n" +
- "(" + errorMessage + " Volume: \"" + volumeNameFormatted + "\")");
-
+ wchar_t shadowVolName[1000];
+ getShadowVolume(backupHandle, shadowVolName, 1000);
shadowVol = Zstring(shadowVolName) + FILE_NAME_SEPARATOR; //shadowVolName NEVER has a trailing backslash
}
@@ -79,7 +78,7 @@ public:
releaseShadowCopy(backupHandle); //fast! no performance optimization necessary
}
- Zstring getShadowVolume() const //trailing path separator
+ Zstring getShadowVolumeName() const //trailing path separator
{
return shadowVol;
}
@@ -90,6 +89,7 @@ private:
const DllFun<CreateShadowCopyFct> createShadowCopy;
const DllFun<ReleaseShadowCopyFct> releaseShadowCopy;
+ const DllFun<GetShadowVolumeFct> getShadowVolume;
Zstring shadowVol;
@@ -105,7 +105,7 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile)
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:") + "\n\"" + inputFile + "\"");
+ throw FileError(_("Could not determine volume name for file:") + L"\n\"" + inputFile + L"\"");
Zstring volumeNameFormatted = volumeNameRaw;
if (!endsWith(volumeNameFormatted, FILE_NAME_SEPARATOR))
@@ -116,8 +116,8 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile)
if (pos == Zstring::npos)
{
std::wstring msg = _("Volume name %x not part of filename %y!");
- replace(msg, L"%x", std::wstring(L"\"") + volumeNameFormatted + "\"", false);
- replace(msg, L"%y", std::wstring(L"\"") + inputFile + "\"", false);
+ replace(msg, L"%x", std::wstring(L"\"") + volumeNameFormatted + L"\"", false);
+ replace(msg, L"%y", std::wstring(L"\"") + inputFile + L"\"", false);
throw FileError(msg);
}
@@ -130,5 +130,5 @@ Zstring ShadowCopy::makeShadowCopy(const Zstring& inputFile)
}
//return filename alias on shadow copy volume
- return iter->second->getShadowVolume() + Zstring(inputFile.c_str() + pos + volumeNameFormatted.length());
+ return iter->second->getShadowVolumeName() + Zstring(inputFile.c_str() + pos + volumeNameFormatted.length());
}
bgstack15