├── .gitignore ├── CBackupState.cpp ├── CBackupState.h ├── CComException.cpp ├── CComException.h ├── CCopyAction.cpp ├── CCopyAction.h ├── CCopyFilter.cpp ├── CCopyFilter.h ├── CDeleteAction.cpp ├── CDeleteAction.h ├── CDirectoryAction.cpp ├── CDirectoryAction.h ├── CFilespecCopyFilter.cpp ├── CFilespecCopyFilter.h ├── CHoboCopyException.cpp ├── CHoboCopyException.h ├── CIncludeAllCopyFilter.cpp ├── CIncludeAllCopyFilter.h ├── CModifiedSinceCopyFilter.cpp ├── CModifiedSinceCopyFilter.h ├── COptions.cpp ├── COptions.h ├── CParseOptionsException.cpp ├── CParseOptionsException.h ├── CWriter.cpp ├── CWriter.h ├── CWriterComponent.cpp ├── CWriterComponent.h ├── Console.cpp ├── Console.h ├── HoboCopy.cpp ├── HoboCopy.sln ├── HoboCopy.vcxproj ├── HoboCopy.vcxproj.filters ├── OutputWriter.cpp ├── OutputWriter.h ├── README.md ├── Utilities.cpp ├── Utilities.h ├── app.manifest ├── build.cmd ├── build.msbuild ├── inc ├── atlrx.h ├── win2003 │ ├── vdslun.h │ ├── vdslun.idl │ ├── vsbackup.h │ ├── vscoordint.h │ ├── vscoordint.idl │ ├── vsmgmt.h │ ├── vsmgmt.idl │ ├── vsprov.h │ ├── vsprov.idl │ ├── vss.h │ ├── vss.idl │ ├── vsswprv.h │ ├── vsswprv.idl │ └── vswriter.h └── winxp │ ├── vsbackup.h │ ├── vss.h │ └── vswriter.h ├── lib ├── win2003 │ └── obj │ │ ├── amd64 │ │ ├── vss_uuid.lib │ │ └── vssapi.lib │ │ ├── i386 │ │ ├── vss_uuid.lib │ │ └── vssapi.lib │ │ └── ia64 │ │ ├── vss_uuid.lib │ │ └── vssapi.lib └── winxp │ └── obj │ └── i386 │ ├── vss_uuid.lib │ └── vssapi.lib ├── license.txt ├── stdafx.cpp ├── stdafx.h └── vcredist_x86.exe /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.user 3 | Debug-* 4 | Release-* 5 | *.sdf 6 | *.opensdf 7 | ipch 8 | x64 9 | bin 10 | -------------------------------------------------------------------------------- /CBackupState.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "CBackupState.h" -------------------------------------------------------------------------------- /CBackupState.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "CComException.h" 27 | #include "OutputWriter.h" 28 | 29 | class CBackupState 30 | { 31 | private: 32 | bool _hasLastFullBackup; 33 | bool _hasLastIncrementalBackup; 34 | SYSTEMTIME _lastFullBackup; 35 | SYSTEMTIME _lastIncrementalBackup; 36 | 37 | void AppendAttribute(CComPtr document, CComPtr parent, 38 | LPCTSTR name, LPCTSTR value) 39 | { 40 | CString message; 41 | message.AppendFormat(TEXT("Creating attribute %s"), name); 42 | OutputWriter::WriteLine(message); 43 | CComPtr pAttribute; 44 | CHECK_HRESULT(document->createAttribute(CComBSTR(name), &pAttribute)); 45 | 46 | OutputWriter::WriteLine(TEXT("Setting value of attribute.")); 47 | CHECK_HRESULT(pAttribute->put_text(CComBSTR(value))); 48 | 49 | OutputWriter::WriteLine(TEXT("Retrieving attributes from parent element.")); 50 | CComPtr pAttributes; 51 | CHECK_HRESULT(parent->get_attributes(&pAttributes)); 52 | 53 | OutputWriter::WriteLine(TEXT("Adding attribute to parent.")); 54 | CComPtr pThrowawayNode; 55 | CHECK_HRESULT(pAttributes->setNamedItem(pAttribute, &pThrowawayNode)); 56 | } 57 | 58 | bool SelectDateTimeValue(CComPtr document, 59 | LPCTSTR xpath, LPSYSTEMTIME pTime) 60 | { 61 | CString message(TEXT("Selecting node for xpath ")); 62 | message.Append(xpath); 63 | OutputWriter::WriteLine(message); 64 | CComPtr pNode; 65 | HRESULT hr = document->selectSingleNode(CComBSTR(xpath), &pNode); 66 | 67 | if (hr == S_FALSE) 68 | { 69 | OutputWriter::WriteLine(TEXT("Unable to find matching node.")); 70 | return FALSE; 71 | } 72 | else 73 | { 74 | // Cheap way of throwing an exception with the details filled in 75 | CHECK_HRESULT(hr); 76 | } 77 | 78 | OutputWriter::WriteLine(TEXT("Retrieving text value of node")); 79 | CComBSTR bstrLastFullBackup; 80 | CHECK_HRESULT(pNode->get_text(&bstrLastFullBackup)); 81 | 82 | CString lastFullBackup(bstrLastFullBackup); 83 | 84 | Utilities::ParseDateTime(lastFullBackup, TEXT("T"), pTime); 85 | 86 | CString message2(TEXT("Time value was: ")); 87 | CString dateTime; 88 | Utilities::FormatDateTime(pTime, TEXT(" "), false, dateTime); 89 | message2.Append(dateTime); 90 | OutputWriter::WriteLine(message2); 91 | 92 | return true; 93 | } 94 | 95 | public: 96 | CBackupState::CBackupState(void) 97 | { 98 | _hasLastFullBackup = false; 99 | _hasLastIncrementalBackup = false; 100 | } 101 | 102 | LPSYSTEMTIME get_LastFullBackupTime() 103 | { 104 | if (_hasLastFullBackup) 105 | { 106 | return &_lastFullBackup; 107 | } 108 | else 109 | { 110 | return NULL; 111 | } 112 | } 113 | 114 | void set_LastFullBackupTime(LPSYSTEMTIME value) 115 | { 116 | _hasLastFullBackup = true; 117 | _lastFullBackup = *value; 118 | } 119 | 120 | LPSYSTEMTIME get_LastIncrementalBackupTime() 121 | { 122 | if (_hasLastIncrementalBackup) 123 | { 124 | return &_lastIncrementalBackup; 125 | } 126 | else 127 | { 128 | return NULL; 129 | } 130 | } 131 | 132 | void set_LastIncrementalBackupTime(LPSYSTEMTIME value) 133 | { 134 | _hasLastIncrementalBackup = true; 135 | _lastIncrementalBackup = *value; 136 | } 137 | 138 | void Load(LPCTSTR path) 139 | { 140 | _hasLastFullBackup = false; 141 | _hasLastIncrementalBackup = false; 142 | 143 | OutputWriter::WriteLine(TEXT("Creating DOM document object.")); 144 | CComPtr stateDocument; 145 | CHECK_HRESULT(stateDocument.CoCreateInstance(__uuidof(DOMDocument30))); 146 | 147 | CString message; 148 | message.AppendFormat(TEXT("Loading state file from %s."), path); 149 | OutputWriter::WriteLine(message); 150 | 151 | OutputWriter::WriteLine(TEXT("Turning off validation")); 152 | CHECK_HRESULT(stateDocument->put_validateOnParse(VARIANT_FALSE)); 153 | 154 | VARIANT_BOOL isSuccessful; 155 | HRESULT hr = stateDocument->load(CComVariant(path), &isSuccessful); 156 | 157 | if (FAILED(hr)) 158 | { 159 | // A cheap way of throwing an exception with the details filled in 160 | CHECK_HRESULT(hr); 161 | } 162 | else if (hr == S_FALSE || isSuccessful == VARIANT_FALSE) 163 | { 164 | CComPtr pError; 165 | CHECK_HRESULT(stateDocument->get_parseError(&pError)); 166 | CComBSTR bstrReason; 167 | CHECK_HRESULT(pError->get_reason(&bstrReason)); 168 | CString reason(bstrReason); 169 | CString message; 170 | message.AppendFormat(TEXT("Failed to load state file from %s. Reason: %s."), path, (LPCTSTR) reason); 171 | throw new CHoboCopyException(message); 172 | } 173 | 174 | _hasLastFullBackup = SelectDateTimeValue(stateDocument, TEXT("/hoboCopyState/@lastFullBackup"), &_lastFullBackup); 175 | 176 | if (_hasLastFullBackup) 177 | { 178 | CString message; 179 | CString dateTime; 180 | Utilities::FormatDateTime(&_lastFullBackup, TEXT(" "), false, dateTime); 181 | message.AppendFormat(TEXT("Last full backup time read as %s"), dateTime); 182 | OutputWriter::WriteLine(message); 183 | } 184 | else 185 | { 186 | OutputWriter::WriteLine(TEXT("Backup file did not have last full backup time recorded.")); 187 | } 188 | 189 | _hasLastIncrementalBackup = SelectDateTimeValue(stateDocument, TEXT("/hoboCopyState/@lastIncrementalBackup"), &_lastIncrementalBackup); 190 | 191 | if (_hasLastIncrementalBackup) 192 | { 193 | CString message; 194 | CString dateTime; 195 | Utilities::FormatDateTime(&_lastIncrementalBackup, TEXT(" "), false, dateTime); 196 | message.AppendFormat(TEXT("Last incremental backup time read as %s"), dateTime); 197 | OutputWriter::WriteLine(message); 198 | } 199 | else 200 | { 201 | OutputWriter::WriteLine(TEXT("Backup file did not have last incremental backup time recorded.")); 202 | } 203 | } 204 | 205 | void Save(LPCTSTR path, BSTR backupDocument) 206 | { 207 | if (!_hasLastFullBackup) 208 | { 209 | throw new CHoboCopyException(TEXT("Could not locate last full backup time.")); 210 | } 211 | 212 | CString message; 213 | message.AppendFormat(TEXT("Saving backup document to state file %s"), path); 214 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_NORMAL); 215 | 216 | OutputWriter::WriteLine(TEXT("Backup document:")); 217 | OutputWriter::WriteLine(backupDocument); 218 | 219 | OutputWriter::WriteLine(TEXT("Creating DOM document object.")); 220 | CComPtr backupDocumentDom; 221 | //IXMLDOMDocument* backupDocumentDom; 222 | //CHECK_HRESULT(::CoCreateInstance(CLSID_DOMDocument30, NULL, CLSCTX_INPROC, IID_IXMLDOMDocument, (LPVOID*) &backupDocumentDom) 223 | CHECK_HRESULT(backupDocumentDom.CoCreateInstance(__uuidof(DOMDocument30))); 224 | 225 | OutputWriter::WriteLine(TEXT("Turning off validation")); 226 | CHECK_HRESULT(backupDocumentDom->put_validateOnParse(VARIANT_FALSE)); 227 | 228 | OutputWriter::WriteLine(TEXT("Loading backup document into DOM.")); 229 | VARIANT_BOOL worked; 230 | HRESULT hr = backupDocumentDom->loadXML(backupDocument, &worked); 231 | 232 | if (FAILED(hr)) 233 | { 234 | CString message; 235 | message.Format(TEXT("loadXML failed with HRESULT 0x%x"), hr); 236 | throw new CHoboCopyException(message); 237 | } 238 | else if (hr == S_FALSE) 239 | { 240 | CComPtr parseError; 241 | OutputWriter::WriteLine(TEXT("Retrieving parse error")); 242 | CHECK_HRESULT(backupDocumentDom->get_parseError(&parseError)); 243 | CComBSTR bstrReason; 244 | OutputWriter::WriteLine(TEXT("Retrieving reason")); 245 | CHECK_HRESULT(parseError->get_reason(&bstrReason)); 246 | CString message; 247 | message.Format(TEXT("loadXML failed to parse: %s"), bstrReason); 248 | throw new CHoboCopyException(message); 249 | } 250 | 251 | if (worked == VARIANT_FALSE) 252 | { 253 | throw new CHoboCopyException(TEXT("IXMLDOMDocument::loadXML() failed")); 254 | } 255 | 256 | OutputWriter::WriteLine(TEXT("Creating state element.")); 257 | CComPtr pStateElement; 258 | CHECK_HRESULT(backupDocumentDom->createElement(CComBSTR(TEXT("hoboCopyState")), 259 | &pStateElement)); 260 | 261 | if (_hasLastFullBackup) 262 | { 263 | OutputWriter::WriteLine(TEXT("Creating lastFullBackup attribute")); 264 | CString dateTime; 265 | Utilities::FormatDateTime(&_lastFullBackup, TEXT("T"), false, dateTime); 266 | AppendAttribute(backupDocumentDom, pStateElement, TEXT("lastFullBackup"), dateTime); 267 | } 268 | else 269 | { 270 | OutputWriter::WriteLine(TEXT("No last full backup time was present.")); 271 | } 272 | 273 | if (_hasLastIncrementalBackup) 274 | { 275 | OutputWriter::WriteLine(TEXT("Creating lastIncrementalBackup attribute")); 276 | CString dateTime; 277 | Utilities::FormatDateTime(&_lastIncrementalBackup, TEXT("T"), false, dateTime); 278 | AppendAttribute(backupDocumentDom, pStateElement, TEXT("lastIncrementalBackup"), dateTime); 279 | } 280 | else 281 | { 282 | OutputWriter::WriteLine(TEXT("No last incremental backup time was present.")); 283 | } 284 | 285 | OutputWriter::WriteLine(TEXT("Retrieving reference to backup document element.")); 286 | CComPtr pBackupDocumentElement; 287 | CHECK_HRESULT(backupDocumentDom->get_documentElement(&pBackupDocumentElement)); 288 | 289 | CComPtr pThrowawayNode; 290 | OutputWriter::WriteLine(TEXT("Removing backup document element.")); 291 | CHECK_HRESULT(backupDocumentDom->removeChild(pBackupDocumentElement, &pThrowawayNode)); 292 | pThrowawayNode.Release(); 293 | 294 | OutputWriter::WriteLine(TEXT("Adding backup document element as child of state element.")); 295 | CHECK_HRESULT(pStateElement->appendChild(pBackupDocumentElement, &pThrowawayNode)); 296 | pThrowawayNode.Release(); 297 | 298 | OutputWriter::WriteLine(TEXT("Adding state element as document element.")); 299 | CHECK_HRESULT(backupDocumentDom->appendChild(pStateElement, &pThrowawayNode)); 300 | pThrowawayNode.Release(); 301 | 302 | OutputWriter::WriteLine(TEXT("Saving backup document.")); 303 | CHECK_HRESULT(backupDocumentDom->save(CComVariant(path))); 304 | 305 | OutputWriter::WriteLine(TEXT("Successfully wrote state file"), VERBOSITY_THRESHOLD_NORMAL); 306 | 307 | } 308 | 309 | }; -------------------------------------------------------------------------------- /CComException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | 26 | #include "CComException.h" 27 | -------------------------------------------------------------------------------- /CComException.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "stdafx.h" 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | class CComException 33 | { 34 | 35 | private: 36 | HRESULT _hresult; 37 | const char* _file; 38 | int _line; 39 | 40 | public: 41 | CComException::CComException(HRESULT hresult, const char* file, int line) 42 | { 43 | _hresult = hresult; 44 | _file = file; 45 | _line = line; 46 | } 47 | 48 | HRESULT get_Hresult(void) 49 | { 50 | return _hresult; 51 | } 52 | 53 | void get_File(CString& file) 54 | { 55 | // Hack: this part is not TCHAR-aware, but this is the only place 56 | size_t length = strlen(_file); 57 | WCHAR* buffer = new WCHAR[length + 1]; 58 | ::MultiByteToWideChar(CP_ACP, 0, _file, (int) length, buffer, (int) length); 59 | buffer[length] = L'\0'; 60 | file.Empty(); 61 | file.Append(buffer); 62 | delete buffer; 63 | } 64 | 65 | int get_Line(void) 66 | { 67 | return _line; 68 | } 69 | 70 | }; -------------------------------------------------------------------------------- /CCopyAction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "CCopyAction.h" 26 | -------------------------------------------------------------------------------- /CCopyAction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "CCopyFilter.h" 27 | #include "CDirectoryAction.h" 28 | #include "OutputWriter.h" 29 | #include "CHoboCopyException.h" 30 | 31 | class CCopyAction : public CDirectoryAction 32 | { 33 | private: 34 | LONGLONG _byteCount; 35 | LPCTSTR _destination; 36 | int _directoryCount; 37 | int _fileCount; 38 | vector _filters; 39 | int _skipCount; 40 | bool _skipDenied; 41 | LPCTSTR _source; 42 | 43 | public: 44 | CCopyAction::CCopyAction(LPCTSTR source, LPCTSTR destination, bool skipDenied, vector filters) : _filters(filters) 45 | { 46 | _source = source; 47 | _destination = destination; 48 | _skipDenied = skipDenied; 49 | _fileCount = 0; 50 | _directoryCount = 0; 51 | _skipCount = 0; 52 | _byteCount = 0; 53 | } 54 | 55 | LONGLONG get_ByteCount(void) 56 | { 57 | return _byteCount; 58 | } 59 | 60 | int get_DirectoryCount(void) 61 | { 62 | return _directoryCount; 63 | } 64 | 65 | int get_FileCount(void) 66 | { 67 | return _fileCount; 68 | } 69 | 70 | int get_SkipCount(void) 71 | { 72 | return _skipCount; 73 | } 74 | 75 | void VisitDirectoryFinal(LPCTSTR path) 76 | { 77 | CString message; 78 | message.AppendFormat(TEXT("Copied directory %s"), path); 79 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_NORMAL); 80 | ++_directoryCount; 81 | } 82 | 83 | void VisitDirectoryInitial(LPCTSTR path) 84 | { 85 | CString destDir; 86 | Utilities::CombinePath(_destination, path, destDir); 87 | Utilities::CreateDirectory(destDir); 88 | CString message; 89 | message.AppendFormat(TEXT("Created directory %s"), destDir); 90 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE); 91 | } 92 | 93 | void VisitFile(LPCTSTR path) 94 | { 95 | CString sourceFile; 96 | Utilities::CombinePath(_source, path, sourceFile); 97 | 98 | CString destinationFile; 99 | Utilities::CombinePath(_destination, path, destinationFile); 100 | Utilities::FixLongFilenames(destinationFile); 101 | if (IsFileMatch(sourceFile)) 102 | { 103 | BOOL worked = ::CopyFile(sourceFile, destinationFile, false); 104 | if (!worked) 105 | { 106 | DWORD error = ::GetLastError(); 107 | 108 | if ((error == 5 || error == 32) && _skipDenied) 109 | { 110 | CString message; 111 | message.Format(TEXT("Error %d accessing file %s. Skipping."), error, sourceFile); 112 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_NORMAL); 113 | ++_skipCount; 114 | } 115 | else 116 | { 117 | CString errorMessage; 118 | Utilities::FormatErrorMessage(error, errorMessage); 119 | CString message; 120 | message.AppendFormat(TEXT("Copy of file failed with error %s on file %s"), 121 | errorMessage, sourceFile); 122 | throw new CHoboCopyException(message); 123 | } 124 | } 125 | else 126 | { 127 | CString message; 128 | message.AppendFormat(TEXT("Copied file %s to %s"), sourceFile, destinationFile); 129 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE); 130 | ++_fileCount; 131 | 132 | try 133 | { 134 | _byteCount += Utilities::GetFileSize(sourceFile); 135 | } 136 | catch (CHoboCopyException* x) 137 | { 138 | CString message; 139 | message.AppendFormat(TEXT("Unable to calculate size of file. Size calculations may be incorrect. Message was: %s"), 140 | x->get_Message()); 141 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_UNLESS_SILENT); 142 | delete x; 143 | } 144 | } 145 | } 146 | else 147 | { 148 | CString message; 149 | message.AppendFormat(TEXT("Skipping file %s because it doesn't meet filter criteria."), path); 150 | OutputWriter::WriteLine(message); 151 | ++_skipCount; 152 | } 153 | 154 | } 155 | 156 | private: 157 | bool IsFileMatch(CString& file) 158 | { 159 | for (unsigned int iFilter = 0; iFilter < _filters.size(); ++iFilter) 160 | { 161 | if (!_filters[iFilter]->IsFileMatch(file)) 162 | { 163 | return false; 164 | } 165 | } 166 | 167 | return true; 168 | 169 | } 170 | 171 | }; -------------------------------------------------------------------------------- /CCopyFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "CCopyFilter.h" -------------------------------------------------------------------------------- /CCopyFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | class CCopyFilter 27 | { 28 | private: 29 | public: 30 | virtual bool IsDirectoryMatch(LPCTSTR path) = 0; 31 | virtual bool IsFileMatch(LPCTSTR path) = 0; 32 | }; -------------------------------------------------------------------------------- /CDeleteAction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "CDirectoryAction.h" 27 | #include "CDeleteAction.h" -------------------------------------------------------------------------------- /CDeleteAction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Utilities.h" 27 | #include "OutputWriter.h" 28 | 29 | class CDeleteAction : public CDirectoryAction 30 | { 31 | private: 32 | LPCTSTR _target; 33 | 34 | public: 35 | CDeleteAction::CDeleteAction(LPCTSTR target) 36 | { 37 | _target = target; 38 | } 39 | 40 | void VisitDirectoryFinal(LPCTSTR path) 41 | { 42 | CString fullPath; 43 | Utilities::CombinePath(_target, path, fullPath); 44 | Utilities::FixLongFilenames(fullPath); 45 | 46 | BOOL bWorked = ::RemoveDirectory(fullPath); 47 | 48 | if (!bWorked) 49 | { 50 | DWORD error = ::GetLastError(); 51 | 52 | CString errorMessage; 53 | Utilities::FormatErrorMessage(error, errorMessage); 54 | CString message; 55 | message.AppendFormat(TEXT("Error %s calling RemoveDirectory on %s"), errorMessage, fullPath); 56 | throw new CHoboCopyException(message); 57 | } 58 | else 59 | { 60 | CString message; 61 | message.AppendFormat(TEXT("Deleted directory %s"), fullPath); 62 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_NORMAL); 63 | } 64 | } 65 | 66 | void VisitDirectoryInitial(LPCTSTR path) 67 | { 68 | // Do nothing 69 | } 70 | 71 | virtual void VisitFile(LPCTSTR path) 72 | { 73 | CString fullPath; 74 | Utilities::CombinePath(_target, path, fullPath); 75 | 76 | Utilities::FixLongFilenames(fullPath); 77 | 78 | BOOL bWorked = ::DeleteFile(fullPath); 79 | 80 | if (!bWorked) 81 | { 82 | DWORD error = ::GetLastError(); 83 | 84 | // Maybe it's read-only 85 | if (error == 5) 86 | { 87 | CString message; 88 | message.AppendFormat(TEXT("Permission denied when deleting file %s. Resetting read-only bit and retrying."), 89 | fullPath); 90 | OutputWriter::WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE); 91 | 92 | DWORD attributes = ::GetFileAttributes(fullPath); 93 | 94 | if (attributes == INVALID_FILE_ATTRIBUTES) 95 | { 96 | CString message; 97 | message.AppendFormat(TEXT("Failed to retrieve attributes for file %s."), fullPath); 98 | throw new CHoboCopyException(message); 99 | } 100 | 101 | attributes &= ~FILE_ATTRIBUTE_READONLY; 102 | 103 | bWorked = ::SetFileAttributes(fullPath, attributes); 104 | 105 | if (!bWorked) 106 | { 107 | CString message; 108 | message.AppendFormat(TEXT("Failed to clear read-only bit on %s"), fullPath); 109 | throw new CHoboCopyException(message); 110 | } 111 | 112 | bWorked = ::DeleteFile(fullPath); 113 | if (!bWorked) 114 | { 115 | error = ::GetLastError(); 116 | } 117 | } 118 | 119 | if (!bWorked) 120 | { 121 | CString errorMessage; 122 | Utilities::FormatErrorMessage(error, errorMessage); 123 | CString message; 124 | message.AppendFormat(TEXT("Error %s calling DeleteFile on %s"), errorMessage, path); 125 | throw new CHoboCopyException(message); 126 | } 127 | } 128 | 129 | if (bWorked) 130 | { 131 | CString message; 132 | message.AppendFormat(TEXT("Successfully deleted file %s."), fullPath); 133 | OutputWriter::WriteLine(message); 134 | } 135 | } 136 | 137 | }; -------------------------------------------------------------------------------- /CDirectoryAction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "CDirectoryAction.h" -------------------------------------------------------------------------------- /CDirectoryAction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | class CDirectoryAction 27 | { 28 | public: 29 | virtual void VisitDirectoryFinal(LPCTSTR path) = 0; 30 | virtual void VisitDirectoryInitial(LPCTSTR path) = 0; 31 | virtual void VisitFile(LPCTSTR path) = 0; 32 | }; -------------------------------------------------------------------------------- /CFilespecCopyFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "Utilities.h" 26 | #include "CHobocopyException.h" 27 | #include "CCopyFilter.h" 28 | #include "CFilespecCopyFilter.h" -------------------------------------------------------------------------------- /CFilespecCopyFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | using namespace std; 27 | 28 | class CFilespecCopyFilter : public CCopyFilter 29 | { 30 | private: 31 | vector& _filespecs; 32 | 33 | public: 34 | CFilespecCopyFilter::CFilespecCopyFilter(vector& filespecs) : _filespecs(filespecs) 35 | { 36 | } 37 | 38 | bool IsDirectoryMatch(LPCTSTR path) 39 | { 40 | return true; 41 | } 42 | bool IsFileMatch(LPCTSTR path) 43 | { 44 | // No filespecs means "match everything" 45 | if (_filespecs.size() == 0) 46 | { 47 | return true; 48 | } 49 | 50 | CString filename; 51 | Utilities::GetFileName(CString(path), filename); 52 | 53 | for (unsigned int iFilespec = 0; iFilespec < _filespecs.size(); ++iFilespec) 54 | { 55 | if (Utilities::IsMatch(filename, _filespecs[iFilespec])) 56 | { 57 | return true; 58 | } 59 | } 60 | 61 | return false; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /CHoboCopyException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "CHoboCopyException.h" -------------------------------------------------------------------------------- /CHoboCopyException.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | class CHoboCopyException 27 | { 28 | private: 29 | CString _message; 30 | 31 | public: 32 | CHoboCopyException::CHoboCopyException(LPCTSTR message) 33 | { 34 | _message.Append(message); 35 | } 36 | 37 | LPCTSTR get_Message(void) 38 | { 39 | return _message; 40 | } 41 | }; -------------------------------------------------------------------------------- /CIncludeAllCopyFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "CIncludeAllCopyFilter.h" -------------------------------------------------------------------------------- /CIncludeAllCopyFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "CCopyFilter.h" 27 | 28 | class CIncludeAllCopyFilter : public CCopyFilter 29 | { 30 | public: 31 | bool IsDirectoryMatch(LPCTSTR path) 32 | { 33 | return true; 34 | } 35 | 36 | bool IsFileMatch(LPCTSTR path) 37 | { 38 | return true; 39 | } 40 | }; -------------------------------------------------------------------------------- /CModifiedSinceCopyFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "CModifiedSinceCopyFilter.h" -------------------------------------------------------------------------------- /CModifiedSinceCopyFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Utilities.h" 27 | #include "CCopyFilter.h" 28 | 29 | class CModifiedSinceCopyFilter : public CCopyFilter 30 | { 31 | private: 32 | FILETIME _since; 33 | bool _skipDenied; 34 | 35 | public: 36 | CModifiedSinceCopyFilter(LPSYSTEMTIME since, bool skipDenied) 37 | { 38 | _skipDenied = skipDenied; 39 | BOOL worked = ::SystemTimeToFileTime(since, &_since); 40 | 41 | if (!worked) 42 | { 43 | DWORD error = ::GetLastError(); 44 | CString errorMessage; 45 | Utilities::FormatErrorMessage(error, errorMessage); 46 | CString message; 47 | message.AppendFormat(TEXT("SystemTimeToFileTime failed with error %s"), errorMessage); 48 | throw new CHoboCopyException(message); 49 | } 50 | } 51 | 52 | bool IsDirectoryMatch(LPCTSTR path) 53 | { 54 | return true; 55 | } 56 | 57 | bool IsFileMatch(LPCTSTR path) 58 | { 59 | HANDLE hFile = ::CreateFile( 60 | path, 61 | GENERIC_READ, 62 | FILE_SHARE_READ | FILE_SHARE_WRITE, 63 | NULL, 64 | OPEN_EXISTING, 65 | FILE_ATTRIBUTE_NORMAL, 66 | NULL); 67 | 68 | if (hFile == INVALID_HANDLE_VALUE) 69 | { 70 | DWORD error = ::GetLastError(); 71 | 72 | if (error == 5 && _skipDenied) 73 | { 74 | return false; 75 | } 76 | 77 | CString errorMessage; 78 | Utilities::FormatErrorMessage(error, errorMessage); 79 | CString message; 80 | message.AppendFormat(TEXT("Unable to open file %s exists. Error %s."), path, errorMessage); 81 | throw new CHoboCopyException(message); 82 | } 83 | 84 | FILETIME modified; 85 | BOOL worked = ::GetFileTime(hFile, NULL, NULL, &modified); 86 | 87 | if (!worked) 88 | { 89 | DWORD error = ::GetLastError(); 90 | 91 | if (error == 5 && _skipDenied) 92 | { 93 | ::CloseHandle(hFile); 94 | return false; 95 | } 96 | 97 | CString errorMessage; 98 | Utilities::FormatErrorMessage(error, errorMessage); 99 | CString message; 100 | message.AppendFormat(TEXT("Unable to retrieve file time from file %s. Error %s."), path, errorMessage); 101 | ::CloseHandle(hFile); 102 | throw new CHoboCopyException(message); 103 | } 104 | 105 | ::CloseHandle(hFile); 106 | 107 | int comparison = ::CompareFileTime(&_since, &modified); 108 | 109 | if (comparison == -1) 110 | { 111 | return true; 112 | } 113 | else 114 | { 115 | return false; 116 | } 117 | } 118 | }; -------------------------------------------------------------------------------- /COptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "COptions.h" -------------------------------------------------------------------------------- /COptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "CHoboCopyException.h" 25 | #include "CParseOptionsException.h" 26 | #include "Utilities.h" 27 | #include "OutputWriter.h" 28 | 29 | using namespace std; 30 | 31 | class COptions 32 | { 33 | private: 34 | bool _acceptAll; 35 | VSS_BACKUP_TYPE _backupType; 36 | bool _clearDestination; 37 | bool _debug; 38 | CString _destination; 39 | vector _filespecs; 40 | std::wregex* _ignorePattern; 41 | bool _recursive; 42 | bool _simulate; 43 | bool _skipDenied; 44 | CString _source; 45 | CString _stateFile; 46 | int _verbosityLevel; 47 | 48 | public: 49 | bool get_AcceptAll() 50 | { 51 | return _acceptAll; 52 | } 53 | VSS_BACKUP_TYPE get_BackupType() 54 | { 55 | return _backupType; 56 | } 57 | bool get_ClearDestination() 58 | { 59 | return _clearDestination; 60 | } 61 | bool get_Debug(void) 62 | { 63 | return _debug; 64 | } 65 | LPCTSTR get_Destination(void) 66 | { 67 | return _destination.GetString(); 68 | } 69 | vector& get_Filespecs(void) 70 | { 71 | return _filespecs; 72 | } 73 | wregex* get_IgnorePattern(void) 74 | { 75 | return _ignorePattern; 76 | } 77 | bool get_Recursive(void) 78 | { 79 | return _recursive; 80 | } 81 | bool get_Simulate(void) 82 | { 83 | return _simulate; 84 | } 85 | bool get_SkipDenied(void) 86 | { 87 | return _skipDenied; 88 | } 89 | LPCTSTR get_StateFile() 90 | { 91 | return NullIfEmpty(_stateFile); 92 | } 93 | LPCTSTR get_Source(void) 94 | { 95 | return _source.GetString(); 96 | } 97 | static LPCTSTR get_Usage(void) 98 | { 99 | return TEXT("Usage:\n\n") 100 | TEXT("hobocopy [/statefile=FILE] [/verbosity=LEVEL]\n") 101 | TEXT(" [ /full | /incremental ] [ /clear ] [ /skipdenied ] [ /y ]\n") 102 | TEXT(" [ /simulate ] [/recursive]\n") 103 | TEXT(" [ [ [ ... ] ]\n") 104 | TEXT("\n") 105 | TEXT("Recursively copies a directory tree from to .\n") 106 | TEXT("\n") 107 | TEXT("/statefile - Specifies a file where information about the copy will\n") 108 | TEXT(" be written. This argument is required when /incremental\n") 109 | TEXT(" is specified, as the date and time of the last copy is\n") 110 | TEXT(" read from this file to determine which files should be\n") 111 | TEXT(" copied.\n") 112 | TEXT("\n") 113 | TEXT("/verbosity - Specifies how much information HoboCopy will emit\n") 114 | TEXT(" during copy. Legal values are: 0 - almost no\n") 115 | TEXT(" information will be emitted. 1 - Only error information\n") 116 | TEXT(" will be emitted. 2 - Errors and warnings will be\n") 117 | TEXT(" emitted. 3 - Errors, warnings, and some status\n") 118 | TEXT(" information will be emitted. 4 - Lots of diagnostic\n") 119 | TEXT(" information will be emitted. The default level is 2.\n") 120 | TEXT("\n") 121 | TEXT("/full - Perform a full copy. All files will be copied\n") 122 | TEXT(" regardless of modification date.\n") 123 | TEXT("\n") 124 | TEXT("/incremental - Perform an incremental copy. Only files that have\n") 125 | TEXT(" changed since the last full copy will be copied.\n") 126 | TEXT(" Specifying this switch requires the /statefile switch\n") 127 | TEXT(" to be specified, as that's where the date of the last\n") 128 | TEXT(" full copy is read from.\n") 129 | TEXT("\n") 130 | TEXT("/clear - Recursively delete the destination directory before\n") 131 | TEXT(" copying. HoboCopy will ask for confirmation before\n") 132 | TEXT(" deleting unless the /y switch is also specified.\n") 133 | TEXT("\n") 134 | TEXT("/skipdenied - By default, if HoboCopy does not have sufficient\n") 135 | TEXT(" privilege to copy a file, the copy will fail with an\n") 136 | TEXT(" error. When the /skipdenied switch is specified,\n") 137 | TEXT(" permission errors trying to copy a source file result\n") 138 | TEXT(" in the file being skipped and the copy continuing.\n") 139 | TEXT("\n") 140 | TEXT("/y - Instructs HoboCopy to proceed as if user answered yes\n") 141 | TEXT(" to any confirmation prompts. Use with caution - in\n") 142 | TEXT(" combination with the /clear switch, this switch will\n") 143 | TEXT(" cause the destination directory to be deleted without\n") 144 | TEXT(" confirmation.\n") 145 | TEXT("\n") 146 | TEXT("/simulate - Simulates copy only - no snapshot is taken and no copy\n") 147 | TEXT(" is performed.\n") 148 | TEXT("\n") 149 | TEXT("/recursive - Copies subdirectories (including empty ones). Shortcut: /r\n") 150 | TEXT("\n") 151 | TEXT(" - The directory to copy (the source directory).\n") 152 | TEXT(" - The directory to copy to (the destination directory).\n") 153 | TEXT(" - A file (e.g. foo.txt) or filespec (e.g. *.txt) to copy.\n") 154 | TEXT(" Defaults to *.*.\n"); 155 | 156 | //TEXT("\n") 157 | //TEXT("\n") 158 | ; 159 | } 160 | int get_VerbosityLevel(void) 161 | { 162 | return _verbosityLevel; 163 | } 164 | 165 | static COptions Parse(int argc, _TCHAR* argv[]) 166 | { 167 | COptions options; 168 | 169 | options._backupType = VSS_BT_FULL; 170 | options._clearDestination = false; 171 | options._verbosityLevel = VERBOSITY_LEVEL_NORMAL; 172 | options._acceptAll = false; 173 | options._skipDenied = false; 174 | options._debug = false; 175 | options._simulate = false; 176 | options._recursive = false; 177 | options._ignorePattern = NULL; 178 | 179 | if (argc < 3) 180 | { 181 | throw new CParseOptionsException(TEXT("Wrong number of arguments.")); 182 | } 183 | 184 | for (int i = 1; i < argc; ++i) 185 | { 186 | CString arg(argv[i]); 187 | arg.MakeLower(); 188 | 189 | if (Utilities::StartsWith(arg, TEXT("/")) || Utilities::StartsWith(arg, TEXT("-"))) 190 | { 191 | arg = arg.Mid(1); 192 | 193 | if (arg.Compare(TEXT("full")) == 0) 194 | { 195 | options._backupType = VSS_BT_FULL; 196 | } 197 | else if (arg.Compare(TEXT("incremental")) == 0) 198 | { 199 | options._backupType = VSS_BT_INCREMENTAL; 200 | } 201 | else if (arg.Compare(TEXT("clear")) == 0) 202 | { 203 | options._clearDestination = true; 204 | } 205 | else if (Utilities::StartsWith(arg, TEXT("statefile="))) 206 | { 207 | options._stateFile = GetArgValue(arg); 208 | } 209 | else if (Utilities::StartsWith(arg, TEXT("verbosity="))) 210 | { 211 | options._verbosityLevel = _ttoi(GetArgValue(arg)); 212 | } 213 | else if (Utilities::StartsWith(arg, TEXT("ignorepattern="))) 214 | { 215 | throw new CParseOptionsException(CString("The ignorepattern switch is no longer supported.")); 216 | } 217 | else if (arg.Compare(TEXT("y")) == 0) 218 | { 219 | options._acceptAll = true; 220 | } 221 | else if (arg.Compare(TEXT("skipdenied")) == 0) 222 | { 223 | options._skipDenied = true; 224 | } 225 | else if (arg.Compare(TEXT("debug")) == 0) 226 | { 227 | options._debug = true; 228 | } 229 | else if (arg.Compare(TEXT("simulate")) == 0) 230 | { 231 | options._simulate = true; 232 | } 233 | else if (arg.Compare(TEXT("recursive")) == 0 || arg.Compare(TEXT("r")) == 0) 234 | { 235 | options._recursive = true; 236 | } 237 | else 238 | { 239 | CString message("Unrecognized switch: "); 240 | message.Append(arg); 241 | throw new CParseOptionsException(message); 242 | } 243 | } 244 | else 245 | { 246 | if (options._source.IsEmpty()) 247 | { 248 | options._source = argv[i]; 249 | } 250 | else if (options._destination.IsEmpty()) 251 | { 252 | options._destination = argv[i]; 253 | } 254 | else 255 | { 256 | options._filespecs.push_back(argv[i]); 257 | } 258 | } 259 | } 260 | 261 | // Normalize paths to full paths 262 | options._source = NormalizePath(options._source); 263 | options._destination = NormalizePath(options._destination); 264 | 265 | if (!options._stateFile.IsEmpty()) 266 | { 267 | options._stateFile = NormalizePath(options._stateFile); 268 | } 269 | 270 | return options; 271 | } 272 | 273 | private: 274 | static CString GetArgValue(const CString& arg) 275 | { 276 | int index = arg.Find(L'='); 277 | 278 | if (index == -1) 279 | { 280 | CString message; 281 | message.Format(TEXT("Couldn't parse the option value from %s"), 282 | arg.GetString()); 283 | throw new CParseOptionsException(message.GetString()); 284 | } 285 | 286 | return arg.Mid(index + 1); 287 | } 288 | static CString NormalizePath(LPCTSTR path) 289 | { 290 | int length = MAX_PATH; 291 | while (true) 292 | { 293 | _TCHAR* normalizedPath = new _TCHAR[length]; 294 | LPTSTR filePart; 295 | DWORD result = ::GetFullPathName(path, MAX_PATH, normalizedPath, &filePart); 296 | 297 | if (result == 0) 298 | { 299 | DWORD error = ::GetLastError(); 300 | CString errorMessage; 301 | Utilities::FormatErrorMessage(error, errorMessage); 302 | CString message; 303 | message.AppendFormat(TEXT("Error calling GetFullPathName: %s"), errorMessage); 304 | throw new CHoboCopyException(message.GetString()); 305 | } 306 | else if (result > MAX_PATH) 307 | { 308 | delete normalizedPath; 309 | length = result; 310 | } 311 | else 312 | { 313 | return normalizedPath; 314 | } 315 | } 316 | } 317 | 318 | static LPCTSTR NullIfEmpty(CString& string) 319 | { 320 | if (string.GetLength() == 0) 321 | { 322 | return NULL; 323 | } 324 | else 325 | { 326 | return string.GetString(); 327 | } 328 | 329 | } 330 | static wregex* ParseRegex(const CString& userInput) 331 | { 332 | try 333 | { 334 | return new wregex(userInput.GetString()); 335 | } 336 | catch (regex_error err) 337 | { 338 | switch (err.code()) 339 | { 340 | case regex_constants::error_badbrace: 341 | ThrowRegexParseException(TEXT("The expression contained an invlid count in a { } expression")); 342 | break; 343 | 344 | case regex_constants::error_badrepeat: 345 | ThrowRegexParseException(TEXT("A repeat expression (one of '*', '?', '+', '{' in most contexts) was not preceded by an expression")); 346 | break; 347 | 348 | case regex_constants::error_brace: 349 | ThrowRegexParseException(TEXT("The expression contained an unmatched '{' or '}'")); 350 | break; 351 | 352 | case regex_constants::error_brack: 353 | ThrowRegexParseException(TEXT("The expression contained an unmatched '[' or ']'")); 354 | break; 355 | 356 | case regex_constants::error_collate: 357 | ThrowRegexParseException(TEXT("The expression contained an invalid collating element name")); 358 | break; 359 | 360 | case regex_constants::error_complexity: 361 | ThrowRegexParseException(TEXT("An attempted match failed because it was too complex")); 362 | break; 363 | 364 | case regex_constants::error_ctype: 365 | ThrowRegexParseException(TEXT("The expression contained an invalid character class name")); 366 | break; 367 | 368 | case regex_constants::error_escape: 369 | ThrowRegexParseException(TEXT("The expression contained an invalid escape sequence")); 370 | break; 371 | 372 | case regex_constants::error_paren: 373 | ThrowRegexParseException(TEXT("The expression contained an unmatched '(' or ')'")); 374 | break; 375 | 376 | case regex_constants::error_range: 377 | ThrowRegexParseException(TEXT("The expression contained an invalid character range specifier")); 378 | break; 379 | 380 | case regex_constants::error_space: 381 | ThrowRegexParseException(TEXT("Parsing a regular expression failed because there were not enough resources available")); 382 | break; 383 | 384 | case regex_constants::error_stack: 385 | ThrowRegexParseException(TEXT("An attempted match failed because there was not enough memory available")); 386 | break; 387 | 388 | case regex_constants::error_backref: 389 | ThrowRegexParseException(TEXT("The expression contained an invalid back reference")); 390 | break; 391 | 392 | default: 393 | ThrowRegexParseException(TEXT("Parse failed")); 394 | break; 395 | } 396 | } 397 | 398 | ThrowRegexParseException(TEXT("Parse failed")); 399 | return NULL; 400 | 401 | } 402 | static void ThrowRegexParseException(const TCHAR* pszDetails) 403 | { 404 | CString message; 405 | message.Format(TEXT("Couldn't parse regular expression supplied to /ignorepattern option (%s)"), pszDetails); 406 | throw new CParseOptionsException(message); 407 | } 408 | }; 409 | -------------------------------------------------------------------------------- /CParseOptionsException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "CParseOptionsException.h" 26 | 27 | -------------------------------------------------------------------------------- /CParseOptionsException.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | class CParseOptionsException 27 | { 28 | private: 29 | CString _message; 30 | 31 | public: 32 | CParseOptionsException::CParseOptionsException(LPCTSTR message) 33 | { 34 | _message = message; 35 | } 36 | 37 | CParseOptionsException::CParseOptionsException(CString& message) 38 | { 39 | _message = message.GetString(); 40 | } 41 | 42 | LPCTSTR get_Message(void) 43 | { 44 | return _message; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /CWriter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "CWriter.h" -------------------------------------------------------------------------------- /CWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "CWriterComponent.h" 27 | 28 | using namespace std; 29 | 30 | class CWriter 31 | { 32 | private: 33 | vector _components; 34 | vector _componentTree; 35 | GUID _instanceId; 36 | CString _name; 37 | GUID _writerId; 38 | 39 | public: 40 | vector& get_Components(void) 41 | { 42 | return _components; 43 | } 44 | 45 | GUID get_InstanceId(void) 46 | { 47 | return _instanceId; 48 | } 49 | 50 | void set_InstanceId(GUID& value) 51 | { 52 | _instanceId = value; 53 | } 54 | 55 | CString& get_Name(void) 56 | { 57 | return _name; 58 | } 59 | 60 | void set_Name(CString name) 61 | { 62 | _name = name; 63 | } 64 | 65 | GUID get_WriterId(void) 66 | { 67 | return _writerId; 68 | } 69 | 70 | void set_WriterId(GUID& value) 71 | { 72 | _writerId = value; 73 | } 74 | 75 | void ComputeComponentTree(void) 76 | { 77 | for (unsigned int iComponent = 0; iComponent < _components.size(); ++iComponent) 78 | { 79 | CWriterComponent& current = _components[iComponent]; 80 | 81 | for (unsigned int iComponentParent = 0; iComponentParent < _components.size(); ++iComponentParent) 82 | { 83 | if (iComponentParent == iComponent) 84 | { 85 | continue; 86 | } 87 | 88 | CWriterComponent& potentialParent = _components[iComponentParent]; 89 | if (potentialParent.IsParentOf(current)) 90 | { 91 | current.set_Parent(&potentialParent); 92 | break; 93 | } 94 | } 95 | } 96 | 97 | } 98 | }; -------------------------------------------------------------------------------- /CWriterComponent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "CWriterComponent.h" -------------------------------------------------------------------------------- /CWriterComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | using namespace std; 27 | 28 | #include "CHoboCopyException.h" 29 | #include "Utilities.h" 30 | 31 | class CWriterComponent 32 | { 33 | private: 34 | CString _logicalPath; 35 | bool _logicalPathParsed; 36 | CString _name; 37 | CWriterComponent* _pParent; 38 | // vector _pathComponents; 39 | bool _selectableForBackup; 40 | VSS_COMPONENT_TYPE _type; 41 | int _writer; 42 | 43 | public: 44 | CWriterComponent::CWriterComponent() 45 | { 46 | _pParent = NULL; 47 | } 48 | 49 | bool get_HasSelectableAncestor(void) 50 | { 51 | if (_pParent == NULL) 52 | { 53 | return false; 54 | } 55 | 56 | if (_pParent->get_SelectableForBackup()) 57 | { 58 | return true; 59 | } 60 | 61 | return _pParent->get_HasSelectableAncestor(); 62 | } 63 | 64 | CString get_LogicalPath(void) 65 | { 66 | return _logicalPath; 67 | } 68 | 69 | void set_LogicalPath(CString logicalPath) 70 | { 71 | _logicalPath = logicalPath; 72 | _logicalPathParsed = false; 73 | } 74 | 75 | CString get_Name(void) 76 | { 77 | return _name; 78 | } 79 | 80 | void set_Name(CString value) 81 | { 82 | _name = value; 83 | } 84 | 85 | CWriterComponent* get_Parent(void) 86 | { 87 | return _pParent; 88 | } 89 | 90 | void set_Parent(CWriterComponent* value) 91 | { 92 | _pParent = value; 93 | } 94 | 95 | bool get_SelectableForBackup(void) 96 | { 97 | return _selectableForBackup; 98 | } 99 | 100 | void set_SelectableForBackup(bool selectableForBackup) 101 | { 102 | _selectableForBackup = selectableForBackup; 103 | } 104 | 105 | VSS_COMPONENT_TYPE get_Type(void) 106 | { 107 | return _type; 108 | } 109 | 110 | void set_Type(VSS_COMPONENT_TYPE value) 111 | { 112 | _type = value; 113 | } 114 | 115 | int get_Writer(void) 116 | { 117 | return _writer; 118 | } 119 | 120 | void set_Writer(int writer) 121 | { 122 | _writer = writer; 123 | } 124 | /* 125 | bool IsAncestorOf(CWriterComponent& potentialDescendant) 126 | { 127 | ParseLogicalPath(); 128 | potentialDescendant.ParseLogicalPath(); 129 | 130 | if (_pathComponents.size() >= potentialDescendant._pathComponents.size()) 131 | { 132 | return false; 133 | } 134 | 135 | for (unsigned int iPathComponent = 0; 136 | iPathComponent < _pathComponents.size(); 137 | ++iPathComponent) 138 | { 139 | if (potentialDescendant._pathComponents[iPathComponent].Compare(_pathComponents[iPathComponent]) != 0) 140 | { 141 | return false; 142 | } 143 | } 144 | 145 | return true; 146 | } 147 | */ 148 | bool IsParentOf(CWriterComponent& potentialParent) 149 | { 150 | // The other component is our parent if our logical path is equal to 151 | // their logical path plus their name. 152 | CString pathToCompare = potentialParent.get_LogicalPath(); 153 | 154 | if (pathToCompare.GetLength() > 0) 155 | { 156 | pathToCompare.Append(TEXT("\\")); 157 | } 158 | 159 | pathToCompare.Append(potentialParent.get_Name()); 160 | 161 | return get_LogicalPath().Compare(pathToCompare) == 0; 162 | } 163 | 164 | private: 165 | /* 166 | void ParseLogicalPath() 167 | { 168 | if (_logicalPathParsed) 169 | { 170 | return; 171 | } 172 | 173 | _logicalPathParsed = true; 174 | 175 | _pathComponents.clear(); 176 | 177 | _pathComponents.push_back(TEXT("")); 178 | 179 | if (_logicalPath.IsEmpty()) 180 | { 181 | return; 182 | } 183 | 184 | bool done = false; 185 | int start = 0; 186 | while (!done) 187 | { 188 | CString component = _logicalPath.Tokenize(TEXT("\\"), start); 189 | 190 | if (start == -1) 191 | { 192 | done = true; 193 | } 194 | else 195 | { 196 | _pathComponents.push_back(component); 197 | } 198 | } 199 | } 200 | */ 201 | }; -------------------------------------------------------------------------------- /Console.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "CHoboCopyException.h" 26 | #include "Utilities.h" 27 | #include "Console.h" 28 | 29 | HANDLE Console::s_hStdOut = INVALID_HANDLE_VALUE; -------------------------------------------------------------------------------- /Console.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Utilities.h" 27 | 28 | class Console 29 | { 30 | private: 31 | static HANDLE s_hStdOut; 32 | public: 33 | static HANDLE get_StandardOutput(void) 34 | { 35 | if (s_hStdOut == INVALID_HANDLE_VALUE) 36 | { 37 | HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE); 38 | 39 | if (hOut != INVALID_HANDLE_VALUE) 40 | { 41 | ::DuplicateHandle(::GetCurrentProcess(), 42 | hOut, 43 | ::GetCurrentProcess(), 44 | &s_hStdOut, 45 | 0, 46 | FALSE, 47 | DUPLICATE_SAME_ACCESS); 48 | } 49 | } 50 | return s_hStdOut; 51 | } 52 | 53 | static TCHAR ReadChar() 54 | { 55 | HANDLE hStdIn = ::GetStdHandle(STD_INPUT_HANDLE); 56 | 57 | TCHAR buffer[1]; 58 | DWORD charsRead; 59 | BOOL bWorked = ::ReadConsole(hStdIn, 60 | buffer, 61 | 1, 62 | &charsRead, 63 | NULL); 64 | 65 | if (!bWorked) 66 | { 67 | DWORD error = ::GetLastError(); 68 | CString errorMessage; 69 | Utilities::FormatErrorMessage(error, errorMessage); 70 | CString message; 71 | message.AppendFormat(TEXT("There was an error calling ReadConsole. Error %s"), errorMessage); 72 | throw new CHoboCopyException(message); 73 | } 74 | 75 | if (charsRead != 1) 76 | { 77 | throw new CHoboCopyException(TEXT("ReadConsole was unable to read a character.")); 78 | } 79 | 80 | return buffer[0]; 81 | } 82 | 83 | static void Write(LPCTSTR message) 84 | { 85 | CString messageString(message); 86 | 87 | LPCSTR narrowMessage = Utilities::ConvertToMultibyteString(message); 88 | 89 | DWORD charsWritten; 90 | BOOL bWorked = ::WriteFile(get_StandardOutput(), narrowMessage, messageString.GetLength(), &charsWritten, NULL); 91 | 92 | Utilities::Free(narrowMessage); 93 | 94 | if (!bWorked) 95 | { 96 | DWORD error = ::GetLastError(); 97 | CString errorMessage; 98 | Utilities::FormatErrorMessage(error, errorMessage); 99 | CString message; 100 | message.AppendFormat(TEXT("Unable to write to the console. %s."), errorMessage); 101 | throw new CHoboCopyException(message); 102 | } 103 | } 104 | 105 | static void WriteLine(LPCTSTR message) 106 | { 107 | Write(message); 108 | Write(TEXT("\r\n")); 109 | } 110 | }; -------------------------------------------------------------------------------- /HoboCopy.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HoboCopy", "HoboCopy.vcxproj", "{FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug-W2K3|x64 = Debug-W2K3|x64 9 | Debug-W2K3|x86 = Debug-W2K3|x86 10 | Debug-XP|x64 = Debug-XP|x64 11 | Debug-XP|x86 = Debug-XP|x86 12 | Release-W2K3|x64 = Release-W2K3|x64 13 | Release-W2K3|x86 = Release-W2K3|x86 14 | Release-x64|x64 = Release-x64|x64 15 | Release-x64|x86 = Release-x64|x86 16 | Release-XP|x64 = Release-XP|x64 17 | Release-XP|x86 = Release-XP|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-W2K3|x64.ActiveCfg = Debug-W2K3|x64 21 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-W2K3|x64.Build.0 = Debug-W2K3|x64 22 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-W2K3|x86.ActiveCfg = Debug-W2K3|Win32 23 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-W2K3|x86.Build.0 = Debug-W2K3|Win32 24 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-XP|x64.ActiveCfg = Debug-XP|x64 25 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-XP|x64.Build.0 = Debug-XP|x64 26 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-XP|x86.ActiveCfg = Debug-XP|Win32 27 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Debug-XP|x86.Build.0 = Debug-XP|Win32 28 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-W2K3|x64.ActiveCfg = Release-W2K3|x64 29 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-W2K3|x64.Build.0 = Release-W2K3|x64 30 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-W2K3|x86.ActiveCfg = Release-W2K3|Win32 31 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-W2K3|x86.Build.0 = Release-W2K3|Win32 32 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-x64|x64.ActiveCfg = Release-x64|x64 33 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-x64|x64.Build.0 = Release-x64|x64 34 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-x64|x86.ActiveCfg = Release-x64|Win32 35 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-x64|x86.Build.0 = Release-x64|Win32 36 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-XP|x64.ActiveCfg = Release-XP|x64 37 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-XP|x64.Build.0 = Release-XP|x64 38 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-XP|x86.ActiveCfg = Release-XP|Win32 39 | {FC0AD7E3-91E2-4232-8289-E1DC8F9395C6}.Release-XP|x86.Build.0 = Release-XP|Win32 40 | EndGlobalSection 41 | GlobalSection(SolutionProperties) = preSolution 42 | HideSolutionNode = FALSE 43 | EndGlobalSection 44 | EndGlobal 45 | -------------------------------------------------------------------------------- /HoboCopy.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /OutputWriter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "OutputWriter.h" 26 | 27 | VERBOSITY_LEVEL OutputWriter::s_verbosityLevel; -------------------------------------------------------------------------------- /OutputWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Console.h" 27 | 28 | using namespace std; 29 | 30 | typedef enum VERBOSITY_LEVEL 31 | { 32 | VERBOSITY_LEVEL_SILENT = 1, 33 | VERBOSITY_LEVEL_TERSE = 2, 34 | VERBOSITY_LEVEL_NORMAL = 3, 35 | VERBOSITY_LEVEL_VERBOSE = 4, 36 | } VERBOSITY_LEVEL; 37 | 38 | typedef enum VERBOSITY_THRESHOLD 39 | { 40 | VERBOSITY_THRESHOLD_ALWAYS = 1, 41 | VERBOSITY_THRESHOLD_UNLESS_SILENT = 2, 42 | VERBOSITY_THRESHOLD_NORMAL = 3, 43 | VERBOSITY_THRESHOLD_IF_VERBOSE = 4, 44 | } VERBOSITY_THRESHOLD; 45 | 46 | class OutputWriter 47 | { 48 | private: 49 | static VERBOSITY_LEVEL s_verbosityLevel; 50 | 51 | /* 52 | static LPCTSTR LogLevelToString(VERBOSITY_LEVEL level) 53 | { 54 | switch (level) 55 | { 56 | case LOG_LEVEL_FATAL: 57 | return TEXT("FATAL"); 58 | case VERBOSITY_THRESHOLD_UNLESS_SILENT: 59 | return TEXT("ERROR"); 60 | case VERBOSITY_THRESHOLD_NORMAL: 61 | return TEXT("WARN "); 62 | case VERBOSITY_THRESHOLD_NORMAL: 63 | return TEXT("INFO "); 64 | case VERBOSITY_THRESHOLD_IF_VERBOSE: 65 | return TEXT("DEBUG"); 66 | default: 67 | return TEXT("UNKWN"); 68 | } 69 | } 70 | */ 71 | public: 72 | static void WriteLine(LPCTSTR message) 73 | { 74 | WriteLine(message, VERBOSITY_THRESHOLD_IF_VERBOSE); 75 | } 76 | static void WriteLine(LPCTSTR message, VERBOSITY_THRESHOLD threshold) 77 | { 78 | if (OutputWriter::s_verbosityLevel >= threshold) 79 | { 80 | Console::WriteLine(message); 81 | } 82 | } 83 | 84 | static void SetVerbosityLevel(VERBOSITY_LEVEL verbosityLevel) 85 | { 86 | s_verbosityLevel = verbosityLevel; 87 | } 88 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STATUS 2 | 3 | Hobocopy is no longer under active development. As far as I know, it still works, but even I don't use it any more. Instead, I use a tool I wrote called [Shadowspawn](https://github.com/candera/shadowspawn) plus something like robocopy or rsync. I consider Shadowspawn the replacement for hobocopy. 4 | 5 | You are welcome to download hobocopy and use it, and I still try to answer questions, but I won't be releasing new versions. You are welcome to fork the project - the license (MIT) is very permissive. 6 | 7 | # WHAT IS HOBOCOPY? 8 | 9 | HoboCopy is a backup/copy tool. It is inspired by robocopy in both name and in 10 | functionality. It differs greatly from robocopy, however, in two respects: 11 | 12 | 1. It is not as full-featured as robocopy. 13 | 2. It uses the Volume Shadow Service (VSS) to "snapshot" the disk 14 | before copying. It then copies from the snapshot rather than the "live" disk. 15 | 16 | # INSTALLING HOBOCOPY 17 | 18 | Most users can simply unzip the file containing hobocopy.exe into the directory 19 | of your choice. However, HoboCopy uses the Visual C++ 8.0 runtime, which may 20 | not be present on some machines. If HoboCopy does not work for you, run the 21 | vcredist executable available from the same location you downloaded HoboCopy. 22 | 23 | # WHY DOES HOBCOPY USE THE VOLUME SHADOW SERVICE? 24 | 25 | Because HoboCopy copies from a VSS snapshot, it is able copy even files that 26 | are in locked by some other program. Further, certain programs (such as SQL 27 | Server 2005) are VSS-aware, and will write their state to disk in a consistent 28 | state before the snapshot is taken, allowing a sort of "live backup". Files 29 | locked by VSS-unaware programs will still be copied in a "crash consistent" 30 | state (i.e. whatever happens to be on the disk). This is generally a lot 31 | better than not being able to copy the file at all. 32 | 33 | # IS HOBOCOPY A BACKUP TOOL? 34 | 35 | Well, not exactly. It can be used that way, but it doesn't do a few things 36 | that "real" backup tools to. For example, there's currently no support for 37 | differential copies. Also, it does not currently make use of the OS support 38 | for doing backups that would allow it to do things like copy even files 39 | it does not nominally have permission to copy. 40 | 41 | The other caveat is that HoboCopy is a hobby project. Therefore, it is not 42 | recommended that anyone use it as a backup strategy for valuable information 43 | - no warranty is provided in the event that something goes wrong. 44 | 45 | That said, the author of the tool uses it to back up his own systems. 46 | 47 | # USAGE: 48 | 49 |
 50 | hobocopy [/statefile=FILE] [/verbosity=LEVEL] [ /full | /incremental ]
 51 |          [ /clear ] [ /skipdenied ] [ /y ] [ /simulate ] [/recursive]
 52 |          src dest [file [file [ ... ] ]
 53 | 
 54 | Recursively copies a directory tree from src to dest.
 55 | 
 56 | /statefile   - Specifies a file where information about the copy will
 57 |                be written. This argument is required when /incremental
 58 |                is specified, as the date and time of the last copy is
 59 |                read from this file to determine which files should be
 60 |                copied.
 61 | 
 62 | /verbosity   - Specifies how much information HoboCopy will emit
 63 |                during copy. Legal values are: 0 - almost no
 64 |                information will be emitted. 1 - Only error information
 65 |                will be emitted. 2 - Errors and warnings will be
 66 |                emitted. 3 - Errors, warnings, and some status
 67 |                information will be emitted. 4 - Lots of diagnostic
 68 |                information will be emitted. The default level is 2.
 69 | 
 70 | /full        - Perform a full copy. All files will be copied
 71 |                regardless of modification date.
 72 | 
 73 | /incremental - Perform an incremental copy. Only files that have
 74 |                changed since the last full copy will be copied.
 75 |                Specifying this switch requires the /statefile switch
 76 |                to be specified, as that's where the date of the last
 77 |                full copy is read from.
 78 | 
 79 | /clear       - Recursively delete the destination directory before
 80 |                copying. HoboCopy will ask for confirmation before
 81 |                deleting unless the /y switch is also specified.
 82 | 
 83 | /skipdenied  - By default, if HoboCopy does not have sufficient
 84 |                privilege to copy a file, the copy will fail with an
 85 |                error. When the /skipdenied switch is specified,
 86 |                permission errors trying to copy a source file result
 87 |                in the file being skipped and the copy continuing.
 88 | 
 89 | /y           - Instructs HoboCopy to proceed as if user answered yes
 90 |                to any confirmation prompts. Use with caution - in
 91 |                combination with the /clear switch, this switch will
 92 |                cause the destination directory to be deleted without
 93 |                confirmation.
 94 | 
 95 | /simulate    - Simulates copy only - no snapshot is taken and no copy
 96 |                is performed.
 97 | 
 98 | /recursive   - Copies subdirectories (including empty ones). Shortcut: /r
 99 | 
100 | src          - The directory to copy (the source directory).
101 | dest         - The directory to copy to (the destination directory).
102 | file         - A file (e.g. foo.txt) or filespec (e.g. *.txt) to copy.
103 |                Defaults to *.*.
104 | 
105 | -------------------------------------------------------------------------------- /Utilities.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "stdafx.h" 25 | #include "CHoboCopyException.h" 26 | #include "Utilities.h" -------------------------------------------------------------------------------- /Utilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | 26 | using namespace std; 27 | 28 | #include "CHoboCopyException.h" 29 | 30 | class Utilities 31 | { 32 | public: 33 | //static LPCTSTR AllocateString(CString& s) 34 | //{ 35 | // int length = s.GetLength(); 36 | // LPTSTR sz = new TCHAR[length + 1]; 37 | // s.CopyChars(sz, length, s.GetBuffer(), length); 38 | // sz[length] = TEXT('\0'); 39 | // return sz; 40 | //} 41 | static bool AreEqual(LPCTSTR wsz1, LPCTSTR wsz2) 42 | { 43 | CString s1(wsz1); 44 | CString s2(wsz2); 45 | return (s1.Compare(wsz2) == 0); 46 | } 47 | static void CombinePath(LPCTSTR wszPath1, LPCTSTR wszPath2, CString& output) 48 | { 49 | output.Empty(); 50 | output.Append(wszPath1); 51 | 52 | if (output.GetLength() > 0) 53 | { 54 | if (!EndsWith(wszPath1, MAX_PATH, TEXT('\\'))) 55 | { 56 | output.Append(TEXT("\\")); 57 | } 58 | } 59 | 60 | output.Append(wszPath2); 61 | } 62 | 63 | static LPCSTR ConvertToMultibyteString(LPCTSTR s) 64 | { 65 | CString s2(s); 66 | LPSTR mbBuffer = new CHAR[s2.GetLength() + 1]; 67 | #ifdef _UNICODE 68 | int result = ::WideCharToMultiByte(CP_OEMCP, 0, s2, s2.GetLength(), mbBuffer, s2.GetLength(), NULL, NULL); 69 | 70 | if (result == 0) 71 | { 72 | return NULL; 73 | } 74 | 75 | return mbBuffer; 76 | #else 77 | return NULL; 78 | #endif 79 | } 80 | 81 | /* Test cases: 82 | \\server\share\path\to\dir 83 | C:\path\to\dir 84 | C:\ - does nothing 85 | \\server\share - does nothing 86 | \path\to\dir - use current drive 87 | */ 88 | static void CreateDirectory(LPCTSTR directory) 89 | { 90 | vector pathComponents; 91 | CString path(directory); 92 | GetPathComponents(path, pathComponents); 93 | 94 | CString pathToCreate; 95 | unsigned int initialIndex = 0; 96 | bool isUNC = path.Left(2) == _T("\\\\"); 97 | 98 | if (isUNC) 99 | { 100 | initialIndex = 2; 101 | pathToCreate.Append(__T("\\\\")); 102 | pathToCreate.Append(pathComponents[0]); 103 | pathToCreate.AppendChar(__T('\\')); 104 | pathToCreate.Append(pathComponents[1]); 105 | pathToCreate.AppendChar(__T('\\')); 106 | } 107 | 108 | for (unsigned int iComponent = initialIndex; iComponent < pathComponents.size(); ++iComponent) 109 | { 110 | pathToCreate.Append(pathComponents[iComponent]); 111 | pathToCreate.AppendChar(TEXT('\\')); 112 | 113 | if (!DirectoryExists(pathToCreate)) 114 | { 115 | CString fixedPath(pathToCreate); 116 | FixLongFilenames(fixedPath); 117 | BOOL bWorked = ::CreateDirectory(fixedPath, NULL); 118 | 119 | if (!bWorked) 120 | { 121 | DWORD error = ::GetLastError(); 122 | CString errorMessage; 123 | FormatErrorMessage(error, errorMessage); 124 | CString message; 125 | message.AppendFormat(TEXT("Failure creating directory %s (as %s) - %s"), pathToCreate, fixedPath, errorMessage); 126 | throw new CHoboCopyException(message); 127 | } 128 | } 129 | } 130 | } 131 | static bool DirectoryExists(LPCTSTR directory) 132 | { 133 | CString fixedPath(directory); 134 | FixLongFilenames(fixedPath); 135 | 136 | WIN32_FILE_ATTRIBUTE_DATA attributes; 137 | BOOL bWorked = ::GetFileAttributesEx(fixedPath, GetFileExInfoStandard, &attributes); 138 | 139 | if (!bWorked) 140 | { 141 | DWORD error = ::GetLastError(); 142 | 143 | if (error == 2 || error == 3) 144 | { 145 | return false; 146 | } 147 | 148 | CString errorMessage; 149 | Utilities::FormatErrorMessage(error, errorMessage); 150 | CString message; 151 | message.AppendFormat(TEXT("Unable to determine if directory %s (as %s) exists. Error was %s."), 152 | directory, fixedPath, errorMessage); 153 | throw new CHoboCopyException(message); 154 | } 155 | 156 | if ((attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) 157 | { 158 | return attributes.dwFileAttributes != -1; 159 | } 160 | 161 | return false; 162 | } 163 | 164 | static bool EndsWith(LPCTSTR wsz, size_t maxLength, TCHAR wchar) 165 | { 166 | CString s(wsz); 167 | 168 | int length = s.GetLength(); 169 | 170 | if (length == 0) 171 | { 172 | return FALSE; 173 | } 174 | 175 | if (s.GetAt(length - 1) == wchar) 176 | { 177 | return TRUE; 178 | } 179 | 180 | return FALSE; 181 | } 182 | static void FixLongFilenames(CString& path) 183 | { 184 | // If it's a UNC path (i.e. starts with \\server), change it to 185 | // \\?\UNC\server\path\to\file 186 | if (Utilities::StartsWith(path, TEXT("\\\\"))) 187 | { 188 | if (!Utilities::StartsWith(path, TEXT("\\\\?\\"))) 189 | { 190 | path.Delete(0, 2); 191 | path.Insert(0, TEXT("\\\\?\\UNC\\")); 192 | } 193 | } 194 | // Otherwise, change it to \\?\X:\path\to\file 195 | else 196 | { 197 | if (!Utilities::StartsWith(path, TEXT("\\\\?\\"))) 198 | { 199 | path.Insert(0, TEXT("\\\\?\\")); 200 | } 201 | } 202 | } 203 | static void FormatDateTime(LPSYSTEMTIME utcTime, LPCTSTR separator, bool formatAsLocal, CString& output) 204 | { 205 | SYSTEMTIME displayTime; 206 | if (formatAsLocal) 207 | { 208 | if (::SystemTimeToTzSpecificLocalTime(NULL, utcTime, &displayTime) == 0) 209 | { 210 | DWORD error = ::GetLastError(); 211 | CString errorMessage; 212 | Utilities::FormatErrorMessage(error, errorMessage); 213 | CString message; 214 | message.AppendFormat(TEXT("Unable to convert UTC time to local time. Error was %s."), 215 | errorMessage); 216 | throw new CHoboCopyException(message); 217 | } 218 | } 219 | else 220 | { 221 | displayTime = *utcTime; 222 | } 223 | 224 | TCHAR datepart[11]; 225 | int result = ::GetDateFormat(LOCALE_USER_DEFAULT, 0, &displayTime, 226 | TEXT("yyyy'-'MM'-'dd"), datepart, 11); 227 | 228 | if (result != 0) 229 | { 230 | output.Append(datepart); 231 | output.Append(separator); 232 | 233 | TCHAR timepart[9]; 234 | result = ::GetTimeFormat(LOCALE_USER_DEFAULT, 0, &displayTime, 235 | TEXT("HH':'mm':'ss"), timepart, 9); 236 | 237 | if (result != 0) 238 | { 239 | output.Append(timepart); 240 | } 241 | else 242 | { 243 | DWORD error = ::GetLastError(); 244 | CString errorMessage; 245 | Utilities::FormatErrorMessage(error, errorMessage); 246 | output.Empty(); 247 | output.AppendFormat(TEXT("Unable to retrieve time. Error was %s."), errorMessage); 248 | } 249 | } 250 | else 251 | { 252 | DWORD error = ::GetLastError(); 253 | CString errorMessage; 254 | Utilities::FormatErrorMessage(error, errorMessage); 255 | output.Empty(); 256 | output.AppendFormat(TEXT("Unable to retrieve date. Error was %s."), errorMessage); 257 | } 258 | 259 | 260 | } 261 | 262 | 263 | static void FormatErrorMessage(DWORD error, CString& output) 264 | { 265 | output.Empty(); 266 | 267 | LPVOID lpMsgBuf; 268 | 269 | DWORD worked = ::FormatMessage( 270 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 271 | FORMAT_MESSAGE_FROM_SYSTEM, 272 | NULL, 273 | error, 274 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 275 | (LPTSTR) &lpMsgBuf, 276 | 0, NULL ); 277 | 278 | if (worked > 0) 279 | { 280 | CString message; 281 | message.Append((LPTSTR) lpMsgBuf); 282 | 283 | ::LocalFree(lpMsgBuf); 284 | 285 | output.Format(TEXT("%s (Error number %d)"), message, error); 286 | } 287 | else 288 | { 289 | output.Format(TEXT("Error %d"), error); 290 | } 291 | 292 | } 293 | static void Free(LPCSTR x) 294 | { 295 | delete x; 296 | } 297 | 298 | static void GetFileName(CString& path, CString& filename) 299 | { 300 | filename.Empty(); 301 | 302 | vector pathComponents; 303 | GetPathComponents(path, pathComponents); 304 | 305 | if (pathComponents.size() > 0) 306 | { 307 | filename = pathComponents[pathComponents.size() - 1]; 308 | } 309 | } 310 | 311 | static LONGLONG GetFileSize(LPCTSTR path) 312 | { 313 | HANDLE hFile = ::CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 314 | 315 | if (hFile == INVALID_HANDLE_VALUE) 316 | { 317 | DWORD error = ::GetLastError(); 318 | 319 | CString errorMessage; 320 | Utilities::FormatErrorMessage(error, errorMessage); 321 | CString message; 322 | message.AppendFormat(TEXT("Unable to open file %s to retrieve file size. Error was %s."), 323 | path, errorMessage); 324 | throw new CHoboCopyException(message); 325 | } 326 | 327 | LARGE_INTEGER size; 328 | BOOL bWorked = ::GetFileSizeEx(hFile, &size); 329 | 330 | if (!bWorked) 331 | { 332 | DWORD error = ::GetLastError(); 333 | 334 | ::CloseHandle(hFile); 335 | 336 | CString errorMessage; 337 | Utilities::FormatErrorMessage(error, errorMessage); 338 | CString message; 339 | message.AppendFormat(TEXT("Unable to retrieve file size for file %s. Error was %s."), 340 | path, errorMessage); 341 | throw new CHoboCopyException(message); 342 | } 343 | 344 | ::CloseHandle(hFile); 345 | 346 | return size.QuadPart; 347 | } 348 | 349 | static void GetPathComponents(CString& path, vector& pathComponents) 350 | { 351 | pathComponents.clear(); 352 | 353 | bool done = false; 354 | int start = 0; 355 | while (!done) 356 | { 357 | CString component = path.Tokenize(TEXT("\\"), start); 358 | 359 | if (start == -1) 360 | { 361 | done = true; 362 | } 363 | else 364 | { 365 | pathComponents.push_back(component); 366 | } 367 | } 368 | 369 | } 370 | 371 | static bool IsMatch(CString& input, CString& pattern) 372 | { 373 | // Short-circuit common cases 374 | if (pattern.Compare(TEXT("*")) == 0) 375 | { 376 | return true; 377 | } 378 | 379 | if (pattern.Compare(TEXT("*.*")) == 0) 380 | { 381 | return true; 382 | 383 | } 384 | 385 | int nStars = 0; 386 | for (int iChar = 0; iChar < pattern.GetLength(); ++iChar) 387 | { 388 | if (pattern[iChar] == TEXT('*')) 389 | { 390 | ++nStars; 391 | } 392 | } 393 | 394 | if (nStars > 1) 395 | { 396 | CString message; 397 | message.AppendFormat(TEXT("The pattern %s is illegal: only a single wildcard is supported."), pattern); 398 | throw new CHoboCopyException(message); 399 | } 400 | 401 | // No wildcard is present 402 | if (nStars == 0) 403 | { 404 | return input.CompareNoCase(pattern) == 0; 405 | } 406 | 407 | // A wildcard is present 408 | int index = pattern.Find(TEXT("*")); 409 | 410 | if (index > 0) 411 | { 412 | if (index > input.GetLength()) 413 | { 414 | return false; 415 | } 416 | 417 | CString prefix = pattern.Left(index); 418 | CString inputStart = input.Left(index); 419 | 420 | if (prefix.CompareNoCase(inputStart) != 0) 421 | { 422 | return false; 423 | } 424 | } 425 | 426 | if (index < input.GetLength() - 1) 427 | { 428 | CString suffix = pattern.Mid(index + 1); 429 | CString inputEnd = input.Right(suffix.GetLength()); 430 | 431 | if (suffix.CompareNoCase(inputEnd) != 0) 432 | { 433 | return false; 434 | } 435 | } 436 | 437 | return true; 438 | 439 | } 440 | //static void FreeString(LPCTSTR s) 441 | //{ 442 | // delete s; 443 | //} 444 | static void ParseDateTime(LPCTSTR szDateTime, LPCTSTR separator, LPSYSTEMTIME pTime) 445 | { 446 | int separatorLength = CString(separator).GetLength(); 447 | 448 | CString dateTimeString(szDateTime); 449 | pTime->wYear = _ttoi(dateTimeString.Mid(0, 4)); 450 | pTime->wMonth = _ttoi(dateTimeString.Mid(5, 2)); 451 | pTime->wDay = _ttoi(dateTimeString.Mid(8, 2)); 452 | pTime->wHour = _ttoi(dateTimeString.Mid(10 + separatorLength, 2)); 453 | pTime->wMinute = _ttoi(dateTimeString.Mid(13 + separatorLength, 2)); 454 | pTime->wSecond = _ttoi(dateTimeString.Mid(16 + separatorLength, 2)); 455 | pTime->wMilliseconds = 0; 456 | } 457 | static bool StartsWith(CString& s1, LPCTSTR s2) 458 | { 459 | CString s2a(s2); 460 | if (s1.Left(s2a.GetLength()).Compare(s2a) == 0) 461 | { 462 | return true; 463 | } 464 | 465 | return false; 466 | } 467 | 468 | }; -------------------------------------------------------------------------------- /app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | msbuild build.msbuild -------------------------------------------------------------------------------- /build.msbuild: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Configuration=Release-W2K3;Platform=x86 5 | 6 | 7 | Configuration=Release-W2K3;Platform=x64 8 | 9 | 10 | Configuration=Release-XP;Platform=x86 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /inc/win2003/vdslun.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 6.00.0366 */ 7 | /* Compiler settings for vdslun.idl: 8 | Oicf, W1, Zp8, env=Win32 (32b run) 9 | protocol : dce , ms_ext, c_ext, robust 10 | error checks: allocation ref bounds_check enum stub_data 11 | VC __declspec() decoration level: 12 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 13 | DECLSPEC_UUID(), MIDL_INTERFACE() 14 | */ 15 | //@@MIDL_FILE_HEADING( ) 16 | 17 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 18 | 19 | 20 | /* verify that the version is high enough to compile this file*/ 21 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 22 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 23 | #endif 24 | 25 | #include "rpc.h" 26 | #include "rpcndr.h" 27 | 28 | #ifndef __RPCNDR_H_VERSION__ 29 | #error this stub requires an updated version of 30 | #endif // __RPCNDR_H_VERSION__ 31 | 32 | 33 | #ifndef __vdslun_h__ 34 | #define __vdslun_h__ 35 | 36 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 37 | #pragma once 38 | #endif 39 | 40 | /* Forward Declarations */ 41 | 42 | /* header files for imported files */ 43 | #include "oaidl.h" 44 | #include "ocidl.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C"{ 48 | #endif 49 | 50 | void * __RPC_USER MIDL_user_allocate(size_t); 51 | void __RPC_USER MIDL_user_free( void * ); 52 | 53 | /* interface __MIDL_itf_vdslun_0000 */ 54 | /* [local] */ 55 | 56 | typedef 57 | enum _VDS_STORAGE_IDENTIFIER_CODE_SET 58 | { VDSStorageIdCodeSetReserved = 0, 59 | VDSStorageIdCodeSetBinary = 1, 60 | VDSStorageIdCodeSetAscii = 2 61 | } VDS_STORAGE_IDENTIFIER_CODE_SET; 62 | 63 | typedef 64 | enum _VDS_STORAGE_IDENTIFIER_TYPE 65 | { VDSStorageIdTypeVendorSpecific = 0, 66 | VDSStorageIdTypeVendorId = 1, 67 | VDSStorageIdTypeEUI64 = 2, 68 | VDSStorageIdTypeFCPHName = 3 69 | } VDS_STORAGE_IDENTIFIER_TYPE; 70 | 71 | typedef 72 | enum _VDS_STORAGE_BUS_TYPE 73 | { VDSBusTypeUnknown = 0, 74 | VDSBusTypeScsi = VDSBusTypeUnknown + 1, 75 | VDSBusTypeAtapi = VDSBusTypeScsi + 1, 76 | VDSBusTypeAta = VDSBusTypeAtapi + 1, 77 | VDSBusType1394 = VDSBusTypeAta + 1, 78 | VDSBusTypeSsa = VDSBusType1394 + 1, 79 | VDSBusTypeFibre = VDSBusTypeSsa + 1, 80 | VDSBusTypeUsb = VDSBusTypeFibre + 1, 81 | VDSBusTypeRAID = VDSBusTypeUsb + 1, 82 | VDSBusTypeIScsi = 9, 83 | VDSBusTypeMaxReserved = 0x7f 84 | } VDS_STORAGE_BUS_TYPE; 85 | 86 | typedef struct _VDS_STORAGE_IDENTIFIER 87 | { 88 | VDS_STORAGE_IDENTIFIER_CODE_SET m_CodeSet; 89 | VDS_STORAGE_IDENTIFIER_TYPE m_Type; 90 | ULONG m_cbIdentifier; 91 | /* [size_is] */ BYTE *m_rgbIdentifier; 92 | } VDS_STORAGE_IDENTIFIER; 93 | 94 | typedef struct _VDS_STORAGE_DEVICE_ID_DESCRIPTOR 95 | { 96 | ULONG m_version; 97 | ULONG m_cIdentifiers; 98 | /* [size_is] */ VDS_STORAGE_IDENTIFIER *m_rgIdentifiers; 99 | } VDS_STORAGE_DEVICE_ID_DESCRIPTOR; 100 | 101 | typedef 102 | enum _VDS_INTERCONNECT_ADDRESS_TYPE 103 | { VDS_IA_UNKNOWN = 0, 104 | VDS_IA_FCFS = VDS_IA_UNKNOWN + 1, 105 | VDS_IA_FCPH = VDS_IA_FCFS + 1, 106 | VDS_IA_FCPH3 = VDS_IA_FCPH + 1, 107 | VDS_IA_MAC = VDS_IA_FCPH3 + 1, 108 | VDS_IA_SCSI = VDS_IA_MAC + 1 109 | } VDS_INTERCONNECT_ADDRESS_TYPE; 110 | 111 | typedef struct _VDS_INTERCONNECT 112 | { 113 | VDS_INTERCONNECT_ADDRESS_TYPE m_addressType; 114 | ULONG m_cbPort; 115 | /* [size_is] */ BYTE *m_pbPort; 116 | ULONG m_cbAddress; 117 | /* [size_is] */ BYTE *m_pbAddress; 118 | } VDS_INTERCONNECT; 119 | 120 | typedef struct _VDS_LUN_INFORMATION 121 | { 122 | ULONG m_version; 123 | BYTE m_DeviceType; 124 | BYTE m_DeviceTypeModifier; 125 | BOOL m_bCommandQueueing; 126 | VDS_STORAGE_BUS_TYPE m_BusType; 127 | /* [string] */ char *m_szVendorId; 128 | /* [string] */ char *m_szProductId; 129 | /* [string] */ char *m_szProductRevision; 130 | /* [string] */ char *m_szSerialNumber; 131 | GUID m_diskSignature; 132 | VDS_STORAGE_DEVICE_ID_DESCRIPTOR m_deviceIdDescriptor; 133 | ULONG m_cInterconnects; 134 | /* [size_is] */ VDS_INTERCONNECT *m_rgInterconnects; 135 | } VDS_LUN_INFORMATION; 136 | 137 | #define VER_VDS_LUN_INFORMATION ( 1 ) 138 | 139 | 140 | 141 | extern RPC_IF_HANDLE __MIDL_itf_vdslun_0000_v0_0_c_ifspec; 142 | extern RPC_IF_HANDLE __MIDL_itf_vdslun_0000_v0_0_s_ifspec; 143 | 144 | /* Additional Prototypes for ALL interfaces */ 145 | 146 | /* end of Additional Prototypes */ 147 | 148 | #ifdef __cplusplus 149 | } 150 | #endif 151 | 152 | #endif 153 | 154 | 155 | -------------------------------------------------------------------------------- /inc/win2003/vdslun.idl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2000-2001 Microsoft Corporation 4 | // 5 | 6 | 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | // Imports 10 | // 11 | 12 | 13 | import "oaidl.idl"; 14 | import "ocidl.idl"; 15 | 16 | 17 | 18 | // mode page 83 data types from ntddstor.h 19 | typedef enum _VDS_STORAGE_IDENTIFIER_CODE_SET 20 | { 21 | VDSStorageIdCodeSetReserved = 0, 22 | VDSStorageIdCodeSetBinary = 1, 23 | VDSStorageIdCodeSetAscii = 2 24 | } VDS_STORAGE_IDENTIFIER_CODE_SET; 25 | 26 | 27 | // mode page 83 identifier types from ntddstor.h 28 | typedef enum _VDS_STORAGE_IDENTIFIER_TYPE 29 | { 30 | VDSStorageIdTypeVendorSpecific = 0, 31 | VDSStorageIdTypeVendorId = 1, 32 | VDSStorageIdTypeEUI64 = 2, 33 | VDSStorageIdTypeFCPHName = 3 34 | } VDS_STORAGE_IDENTIFIER_TYPE; 35 | 36 | 37 | // bus types from ntddstor.h 38 | typedef enum _VDS_STORAGE_BUS_TYPE 39 | { 40 | VDSBusTypeUnknown = 0x00, 41 | VDSBusTypeScsi, 42 | VDSBusTypeAtapi, 43 | VDSBusTypeAta, 44 | VDSBusType1394, 45 | VDSBusTypeSsa, 46 | VDSBusTypeFibre, 47 | VDSBusTypeUsb, 48 | VDSBusTypeRAID, 49 | VDSBusTypeIScsi = 9, // Not defined in NTDDSTOR.H 50 | VDSBusTypeMaxReserved = 0x7F 51 | } VDS_STORAGE_BUS_TYPE; 52 | 53 | 54 | // midlized STORAGE_IDENTIFIER from ntddstor.h 55 | typedef struct _VDS_STORAGE_IDENTIFIER 56 | { 57 | // whether ascii or binary data 58 | VDS_STORAGE_IDENTIFIER_CODE_SET m_CodeSet; 59 | 60 | // type of identifier 61 | VDS_STORAGE_IDENTIFIER_TYPE m_Type; 62 | 63 | // length of identifier in bytes 64 | ULONG m_cbIdentifier; 65 | 66 | // actual identintifier 67 | [size_is(m_cbIdentifier)] BYTE *m_rgbIdentifier; 68 | } VDS_STORAGE_IDENTIFIER; 69 | 70 | // mode page 83 (STORAGE_DEVICE_ID_DESCRIPTOR from ntddstor.h) 71 | typedef struct _VDS_STORAGE_DEVICE_ID_DESCRIPTOR 72 | { 73 | // version of structure 74 | ULONG m_version; 75 | 76 | // number of identifiers 77 | ULONG m_cIdentifiers; 78 | 79 | [size_is(m_cIdentifiers)] VDS_STORAGE_IDENTIFIER *m_rgIdentifiers; 80 | } VDS_STORAGE_DEVICE_ID_DESCRIPTOR; 81 | 82 | // interconnect address types 83 | typedef enum _VDS_INTERCONNECT_ADDRESS_TYPE 84 | { 85 | VDS_IA_UNKNOWN = 0, 86 | VDS_IA_FCFS, 87 | VDS_IA_FCPH, 88 | VDS_IA_FCPH3, 89 | VDS_IA_MAC, 90 | VDS_IA_SCSI 91 | } VDS_INTERCONNECT_ADDRESS_TYPE; 92 | 93 | typedef struct _VDS_INTERCONNECT 94 | { 95 | // address type 96 | VDS_INTERCONNECT_ADDRESS_TYPE m_addressType; 97 | 98 | // port that address refers to 99 | ULONG m_cbPort; 100 | 101 | // actual address of port 102 | [size_is(m_cbPort)] BYTE *m_pbPort; 103 | 104 | // size of address 105 | ULONG m_cbAddress; 106 | 107 | // address relative to the port 108 | [size_is(m_cbAddress)] BYTE *m_pbAddress; 109 | } VDS_INTERCONNECT; 110 | 111 | 112 | 113 | // information about a lun. Includes STORAGE_DEVICE_DESCRIPTOR 114 | // (from ntddstor.h) STORAGE_DEVICE_ID_DESCRIPTOR, interconnect address type, 115 | // and interconnect address. 116 | typedef struct _VDS_LUN_INFORMATION 117 | { 118 | // version of structure 119 | ULONG m_version; 120 | 121 | // The SCSI-2 device type 122 | BYTE m_DeviceType; 123 | 124 | // The SCSI-2 device type modifier (if any) - this may be zero 125 | BYTE m_DeviceTypeModifier; 126 | 127 | // Flag indicating whether the device can support mulitple outstanding 128 | // commands. The actual synchronization in this case is the responsibility 129 | // of the port driver. 130 | BOOL m_bCommandQueueing; 131 | 132 | // Contains the bus type (as defined above) of the device. It should be 133 | // used to interpret the raw device properties at the end of this structure 134 | // (if any) 135 | VDS_STORAGE_BUS_TYPE m_BusType; 136 | 137 | 138 | // vendor id string. For devices with no such ID this will be zero 139 | [string] char *m_szVendorId; 140 | 141 | // device's product id string. For devices with no such ID this will be zero 142 | [string] char *m_szProductId; 143 | 144 | // zero-terminated ascii string containing the device's 145 | // product revision string. For devices with no such string this will be 146 | // zero 147 | [string] char *m_szProductRevision; 148 | 149 | // zero-terminated ascii string containing the device's 150 | // serial number. For devices with no serial number this will be zero 151 | [string] char *m_szSerialNumber; 152 | 153 | // disk signature 154 | GUID m_diskSignature; 155 | 156 | // device id descriptor 157 | VDS_STORAGE_DEVICE_ID_DESCRIPTOR m_deviceIdDescriptor; 158 | 159 | // number of interconnects 160 | ULONG m_cInterconnects; 161 | 162 | // array of interconnects 163 | [size_is(m_cInterconnects)] VDS_INTERCONNECT *m_rgInterconnects; 164 | } VDS_LUN_INFORMATION; 165 | 166 | const ULONG VER_VDS_LUN_INFORMATION = 1; 167 | 168 | -------------------------------------------------------------------------------- /inc/win2003/vsbackup.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | vsbackup.h 8 | 9 | Abstract: 10 | 11 | Declaration of backup interfaces IVssExamineWriterMetadata and 12 | IVssBackupComponents, IVssWMComponent 13 | 14 | Brian Berkowitz [brianb] 3/13/2000 15 | 16 | 17 | TBD: 18 | 19 | Add comments. 20 | 21 | Revision History: 22 | 23 | Name Date Comments 24 | brianb 03/30/2000 Created 25 | brianb 04/18/2000 Added IVssCancelCallback 26 | brianb 05/03/2000 Changed IVssWriter::Initialize method 27 | brianb 05/16/2000 Remove cancel stuff 28 | mikejohn 05/24/2000 Changed parameters on SimulateXxxx() calls 29 | mikejohn 09/18/2000 176860: Added calling convention methods where missing 30 | ssteiner 11/10/2000 143801 MOve SimulateSnashotXxxx() calls to be hosted by VssSvc 31 | 32 | --*/ 33 | 34 | #ifndef _VSBACKUP_H_ 35 | #define _VSBACKUP_H_ 36 | 37 | 38 | const IID IID_IVssExamineWriterMetadata = // 902fcf7f-b7fd-42f8-81f1-b2e400b1e5bd 39 | { 40 | 0x902fcf7f, 41 | 0xb7fd, 42 | 0x42f8, 43 | {0x81, 0xf1, 0xb2, 0xe4, 0x00, 0xb1, 0xe5, 0xbd } 44 | }; 45 | 46 | 47 | const IID IID_IVssExamineWriterMetadataEx = // 0c0e5ec0-ca44-472b-b702-e652db1c0451 48 | { 49 | 0x0c0e5ec0, 50 | 0xca44, 51 | 0x472b, 52 | { 0xb7, 0x02, 0xe6, 0x52, 0xdb, 0x1c, 0x04, 0x51 } 53 | }; 54 | 55 | const IID IID_IVssBackupComponents = // 665c1d5f-c218-414d-a05d-7fef5f9d5c86 56 | { 57 | 0x665c1d5f, 58 | 0xc218, 59 | 0x414d, 60 | { 0xa0, 0x5d, 0x7f, 0xef, 0x5f, 0x9d, 0x5c, 0x86 } 61 | }; 62 | 63 | const IID IID_IVssBackupComponentsEx = // 963f03ad-9e4c-4a34-ac15-e4b6174e5036 64 | { 65 | 0x963f03ad, 66 | 0x9e4c, 67 | 0x4a34, 68 | { 0xac, 0x15, 0xe4, 0xb6, 0x17, 0x4e, 0x50, 0x36 } 69 | }; 70 | 71 | 72 | // description of a component 73 | typedef struct _VSS_COMPONENTINFO 74 | { 75 | VSS_COMPONENT_TYPE type; // either VSS_CT_DATABASE or VSS_CT_FILEGROUP 76 | BSTR bstrLogicalPath; // logical path to component 77 | BSTR bstrComponentName; // component name 78 | BSTR bstrCaption; // description of component 79 | BYTE *pbIcon; // icon 80 | UINT cbIcon; // icon 81 | bool bRestoreMetadata; // whether component supplies restore metadata 82 | bool bNotifyOnBackupComplete; // whether component needs to be informed if backup was successful 83 | bool bSelectable; // is component selectable 84 | bool bSelectableForRestore; // is component selectable for restore 85 | DWORD dwComponentFlags; // extra attribute flags for the component 86 | UINT cFileCount; // # of files in file group 87 | UINT cDatabases; // # of database files 88 | UINT cLogFiles; // # of log files 89 | UINT cDependencies; // # of components that this component depends on 90 | } VSS_COMPONENTINFO; 91 | 92 | typedef const VSS_COMPONENTINFO *PVSSCOMPONENTINFO; 93 | 94 | 95 | // component information 96 | class IVssWMComponent : public IUnknown 97 | { 98 | public: 99 | // get component information 100 | STDMETHOD(GetComponentInfo)(PVSSCOMPONENTINFO *ppInfo) = 0; 101 | 102 | // free component information 103 | STDMETHOD(FreeComponentInfo)(PVSSCOMPONENTINFO pInfo) = 0; 104 | 105 | // obtain a specific file in a file group 106 | STDMETHOD(GetFile) 107 | ( 108 | IN UINT iFile, 109 | OUT IVssWMFiledesc **ppFiledesc 110 | ) = 0; 111 | 112 | // obtain a specific physical database file for a database 113 | STDMETHOD(GetDatabaseFile) 114 | ( 115 | IN UINT iDBFile, 116 | OUT IVssWMFiledesc **ppFiledesc 117 | ) = 0; 118 | 119 | // obtain a specific physical log file for a database 120 | STDMETHOD(GetDatabaseLogFile) 121 | ( 122 | IN UINT iDbLogFile, 123 | OUT IVssWMFiledesc **ppFiledesc 124 | ) = 0; 125 | 126 | STDMETHOD(GetDependency) 127 | ( 128 | IN UINT iDependency, 129 | OUT IVssWMDependency **ppDependency 130 | ) = 0; 131 | }; 132 | 133 | 134 | // interface to examine writer metadata 135 | class __declspec(uuid("902fcf7f-b7fd-42f8-81f1-b2e400b1e5bd")) IVssExamineWriterMetadata : public IUnknown 136 | { 137 | public: 138 | // obtain identity of the writer 139 | STDMETHOD(GetIdentity) 140 | ( 141 | OUT VSS_ID *pidInstance, 142 | OUT VSS_ID *pidWriter, 143 | OUT BSTR *pbstrWriterName, 144 | OUT VSS_USAGE_TYPE *pUsage, 145 | OUT VSS_SOURCE_TYPE *pSource 146 | ) = 0; 147 | 148 | // obtain number of include files, exclude files, and components 149 | STDMETHOD(GetFileCounts) 150 | ( 151 | OUT UINT *pcIncludeFiles, 152 | OUT UINT *pcExcludeFiles, 153 | OUT UINT *pcComponents 154 | ) = 0; 155 | 156 | // obtain specific include files 157 | STDMETHOD(GetIncludeFile) 158 | ( 159 | IN UINT iFile, 160 | OUT IVssWMFiledesc **ppFiledesc 161 | ) = 0; 162 | 163 | // obtain specific exclude files 164 | STDMETHOD(GetExcludeFile) 165 | ( 166 | IN UINT iFile, 167 | OUT IVssWMFiledesc **ppFiledesc 168 | ) = 0; 169 | 170 | // obtain specific component 171 | STDMETHOD(GetComponent) 172 | ( 173 | IN UINT iComponent, 174 | OUT IVssWMComponent **ppComponent 175 | ) = 0; 176 | 177 | // obtain restoration method 178 | STDMETHOD(GetRestoreMethod) 179 | ( 180 | OUT VSS_RESTOREMETHOD_ENUM *pMethod, 181 | OUT BSTR *pbstrService, 182 | OUT BSTR *pbstrUserProcedure, 183 | OUT VSS_WRITERRESTORE_ENUM *pwriterRestore, 184 | OUT bool *pbRebootRequired, 185 | UINT *pcMappings 186 | ) = 0; 187 | 188 | // obtain a specific alternative location mapping 189 | STDMETHOD(GetAlternateLocationMapping) 190 | ( 191 | IN UINT iMapping, 192 | OUT IVssWMFiledesc **ppFiledesc 193 | ) = 0; 194 | 195 | // get the backup schema 196 | STDMETHOD(GetBackupSchema) 197 | ( 198 | OUT DWORD *pdwSchemaMask 199 | ) = 0; 200 | 201 | // obtain reference to actual XML document 202 | STDMETHOD(GetDocument)(IXMLDOMDocument **pDoc) = 0; 203 | 204 | // convert document to a XML string 205 | STDMETHOD(SaveAsXML)(BSTR *pbstrXML) = 0; 206 | 207 | // load document from an XML string 208 | STDMETHOD(LoadFromXML)(BSTR bstrXML) = 0; 209 | }; 210 | 211 | class __declspec(uuid("0c0e5ec0-ca44-472b-b702-e652db1c0451")) IVssExamineWriterMetadataEx : public IVssExamineWriterMetadata 212 | { 213 | public: 214 | // obtain identity of the writer 215 | STDMETHOD(GetIdentityEx) 216 | ( 217 | OUT VSS_ID *pidInstance, 218 | OUT VSS_ID *pidWriter, 219 | OUT BSTR *pbstrWriterName, 220 | OUT BSTR* pbstrInstanceName, 221 | OUT VSS_USAGE_TYPE *pUsage, 222 | OUT VSS_SOURCE_TYPE *pSource 223 | ) = 0; 224 | }; 225 | 226 | class IVssWriterComponentsExt : 227 | public IVssWriterComponents, 228 | public IUnknown 229 | { 230 | }; 231 | 232 | 233 | // backup components interface 234 | class __declspec(uuid("665c1d5f-c218-414d-a05d-7fef5f9d5c86")) IVssBackupComponents : public IUnknown 235 | { 236 | public: 237 | // get count of writer components 238 | STDMETHOD(GetWriterComponentsCount)(OUT UINT *pcComponents) = 0; 239 | 240 | // obtain a specific writer component 241 | STDMETHOD(GetWriterComponents) 242 | ( 243 | IN UINT iWriter, 244 | OUT IVssWriterComponentsExt **ppWriter 245 | ) = 0; 246 | 247 | // initialize and create BACKUP_COMPONENTS document 248 | STDMETHOD(InitializeForBackup)(IN BSTR bstrXML = NULL) = 0; 249 | 250 | // set state describing backup 251 | STDMETHOD(SetBackupState) 252 | ( 253 | IN bool bSelectComponents, 254 | IN bool bBackupBootableSystemState, 255 | IN VSS_BACKUP_TYPE backupType, 256 | IN bool bPartialFileSupport = false 257 | ) = 0; 258 | 259 | STDMETHOD(InitializeForRestore)(IN BSTR bstrXML) = 0; 260 | 261 | // set state describing restore 262 | STDMETHOD(SetRestoreState) 263 | ( 264 | VSS_RESTORE_TYPE restoreType 265 | ) = 0; 266 | 267 | // gather writer metadata 268 | STDMETHOD(GatherWriterMetadata) 269 | ( 270 | OUT IVssAsync **pAsync 271 | ) = 0; 272 | 273 | // get count of writers with metadata 274 | STDMETHOD(GetWriterMetadataCount) 275 | ( 276 | OUT UINT *pcWriters 277 | ) = 0; 278 | 279 | // get writer metadata for a specific writer 280 | STDMETHOD(GetWriterMetadata) 281 | ( 282 | IN UINT iWriter, 283 | OUT VSS_ID *pidInstance, 284 | OUT IVssExamineWriterMetadata **ppMetadata 285 | ) = 0; 286 | 287 | // free writer metadata 288 | STDMETHOD(FreeWriterMetadata)() = 0; 289 | 290 | // add a component to the BACKUP_COMPONENTS document 291 | STDMETHOD(AddComponent) 292 | ( 293 | IN VSS_ID instanceId, 294 | IN VSS_ID writerId, 295 | IN VSS_COMPONENT_TYPE ct, 296 | IN LPCWSTR wszLogicalPath, 297 | IN LPCWSTR wszComponentName 298 | ) = 0; 299 | 300 | // dispatch PrepareForBackup event to writers 301 | STDMETHOD(PrepareForBackup) 302 | ( 303 | OUT IVssAsync **ppAsync 304 | ) = 0; 305 | 306 | // abort the backup 307 | STDMETHOD(AbortBackup)() = 0; 308 | 309 | // dispatch the Identify event so writers can expose their metadata 310 | STDMETHOD(GatherWriterStatus) 311 | ( 312 | OUT IVssAsync **pAsync 313 | ) = 0; 314 | 315 | 316 | // get count of writers with status 317 | STDMETHOD(GetWriterStatusCount) 318 | ( 319 | OUT UINT *pcWriters 320 | ) = 0; 321 | 322 | STDMETHOD(FreeWriterStatus)() = 0; 323 | 324 | STDMETHOD(GetWriterStatus) 325 | ( 326 | IN UINT iWriter, 327 | OUT VSS_ID *pidInstance, 328 | OUT VSS_ID *pidWriter, 329 | OUT BSTR *pbstrWriter, 330 | OUT VSS_WRITER_STATE *pnStatus, 331 | OUT HRESULT *phResultFailure 332 | ) = 0; 333 | 334 | // indicate whether backup succeeded on a component 335 | STDMETHOD(SetBackupSucceeded) 336 | ( 337 | IN VSS_ID instanceId, 338 | IN VSS_ID writerId, 339 | IN VSS_COMPONENT_TYPE ct, 340 | IN LPCWSTR wszLogicalPath, 341 | IN LPCWSTR wszComponentName, 342 | IN bool bSucceded 343 | ) = 0; 344 | 345 | // set backup options for the writer 346 | STDMETHOD(SetBackupOptions) 347 | ( 348 | IN VSS_ID writerId, 349 | IN VSS_COMPONENT_TYPE ct, 350 | IN LPCWSTR wszLogicalPath, 351 | IN LPCWSTR wszComponentName, 352 | IN LPCWSTR wszBackupOptions 353 | ) = 0; 354 | 355 | // indicate that a given component is selected to be restored 356 | STDMETHOD(SetSelectedForRestore) 357 | ( 358 | IN VSS_ID writerId, 359 | IN VSS_COMPONENT_TYPE ct, 360 | IN LPCWSTR wszLogicalPath, 361 | IN LPCWSTR wszComponentName, 362 | IN bool bSelectedForRestore 363 | ) = 0; 364 | 365 | 366 | // set restore options for the writer 367 | STDMETHOD(SetRestoreOptions) 368 | ( 369 | IN VSS_ID writerId, 370 | IN VSS_COMPONENT_TYPE ct, 371 | IN LPCWSTR wszLogicalPath, 372 | IN LPCWSTR wszComponentName, 373 | IN LPCWSTR wszRestoreOptions 374 | ) = 0; 375 | 376 | // indicate that additional restores will follow 377 | STDMETHOD(SetAdditionalRestores) 378 | ( 379 | IN VSS_ID writerId, 380 | IN VSS_COMPONENT_TYPE ct, 381 | IN LPCWSTR wszLogicalPath, 382 | IN LPCWSTR wszComponentName, 383 | IN bool bAdditionalRestores 384 | ) = 0; 385 | 386 | 387 | // set the backup stamp that the differential or incremental 388 | // backup is based on 389 | STDMETHOD(SetPreviousBackupStamp) 390 | ( 391 | IN VSS_ID writerId, 392 | IN VSS_COMPONENT_TYPE ct, 393 | IN LPCWSTR wszLogicalPath, 394 | IN LPCWSTR wszComponentName, 395 | IN LPCWSTR wszPreviousBackupStamp 396 | ) = 0; 397 | 398 | 399 | 400 | // save BACKUP_COMPONENTS document as XML string 401 | STDMETHOD(SaveAsXML)(BSTR *pbstrXML) = 0; 402 | 403 | // signal BackupComplete event to the writers 404 | STDMETHOD(BackupComplete)(OUT IVssAsync **ppAsync) = 0; 405 | 406 | // add an alternate mapping on restore 407 | STDMETHOD(AddAlternativeLocationMapping) 408 | ( 409 | IN VSS_ID writerId, 410 | IN VSS_COMPONENT_TYPE componentType, 411 | IN LPCWSTR wszLogicalPath, 412 | IN LPCWSTR wszComponentName, 413 | IN LPCWSTR wszPath, 414 | IN LPCWSTR wszFilespec, 415 | IN bool bRecursive, 416 | IN LPCWSTR wszDestination 417 | ) = 0; 418 | 419 | // add a subcomponent to be restored 420 | STDMETHOD(AddRestoreSubcomponent) 421 | ( 422 | IN VSS_ID writerId, 423 | IN VSS_COMPONENT_TYPE componentType, 424 | IN LPCWSTR wszLogicalPath, 425 | IN LPCWSTR wszComponentName, 426 | IN LPCWSTR wszSubComponentLogicalPath, 427 | IN LPCWSTR wszSubComponentName, 428 | IN bool bRepair 429 | ) = 0; 430 | 431 | // requestor indicates whether files were successfully restored 432 | STDMETHOD(SetFileRestoreStatus) 433 | ( 434 | IN VSS_ID writerId, 435 | IN VSS_COMPONENT_TYPE ct, 436 | IN LPCWSTR wszLogicalPath, 437 | IN LPCWSTR wszComponentName, 438 | IN VSS_FILE_RESTORE_STATUS status 439 | ) = 0; 440 | 441 | // add a new location target for a file to be restored 442 | STDMETHOD(AddNewTarget) 443 | ( 444 | IN VSS_ID writerId, 445 | IN VSS_COMPONENT_TYPE ct, 446 | IN LPCWSTR wszLogicalPath, 447 | IN LPCWSTR wszComponentName, 448 | IN LPCWSTR wszPath, 449 | IN LPCWSTR wszFileName, 450 | IN bool bRecursive, 451 | IN LPCWSTR wszAlternatePath 452 | ) = 0; 453 | 454 | // add a new location for the ranges file in case it was restored to 455 | // a different location 456 | STDMETHOD(SetRangesFilePath) 457 | ( 458 | IN VSS_ID writerId, 459 | IN VSS_COMPONENT_TYPE ct, 460 | IN LPCWSTR wszLogicalPath, 461 | IN LPCWSTR wszComponentName, 462 | IN UINT iPartialFile, 463 | IN LPCWSTR wszRangesFile 464 | ) = 0; 465 | 466 | // signal PreRestore event to the writers 467 | STDMETHOD(PreRestore)(OUT IVssAsync **ppAsync) = 0; 468 | 469 | // signal PostRestore event to the writers 470 | STDMETHOD(PostRestore)(OUT IVssAsync **ppAsync) = 0; 471 | 472 | // Called to set the context for subsequent snapshot-related operations 473 | STDMETHOD(SetContext) 474 | ( 475 | IN LONG lContext 476 | ) = 0; 477 | 478 | // start a snapshot set 479 | STDMETHOD(StartSnapshotSet) 480 | ( 481 | OUT VSS_ID *pSnapshotSetId 482 | ) = 0; 483 | 484 | // add a volume to a snapshot set 485 | STDMETHOD(AddToSnapshotSet) 486 | ( 487 | IN VSS_PWSZ pwszVolumeName, 488 | IN VSS_ID ProviderId, 489 | OUT VSS_ID *pidSnapshot 490 | ) = 0; 491 | 492 | // create the snapshot set 493 | STDMETHOD(DoSnapshotSet) 494 | ( 495 | OUT IVssAsync** ppAsync 496 | ) = 0; 497 | 498 | STDMETHOD(DeleteSnapshots) 499 | ( 500 | IN VSS_ID SourceObjectId, 501 | IN VSS_OBJECT_TYPE eSourceObjectType, 502 | IN BOOL bForceDelete, 503 | IN LONG* plDeletedSnapshots, 504 | IN VSS_ID* pNondeletedSnapshotID 505 | ) = 0; 506 | 507 | STDMETHOD(ImportSnapshots) 508 | ( 509 | OUT IVssAsync** ppAsync 510 | ) = 0; 511 | 512 | STDMETHOD(BreakSnapshotSet) 513 | ( 514 | IN VSS_ID SnapshotSetId 515 | ) = 0; 516 | 517 | STDMETHOD(GetSnapshotProperties) 518 | ( 519 | IN VSS_ID SnapshotId, 520 | OUT VSS_SNAPSHOT_PROP *pProp 521 | ) = 0; 522 | 523 | STDMETHOD(Query) 524 | ( 525 | IN VSS_ID QueriedObjectId, 526 | IN VSS_OBJECT_TYPE eQueriedObjectType, 527 | IN VSS_OBJECT_TYPE eReturnedObjectsType, 528 | IN IVssEnumObject **ppEnum 529 | ) = 0; 530 | 531 | STDMETHOD(IsVolumeSupported) 532 | ( 533 | IN VSS_ID ProviderId, 534 | IN VSS_PWSZ pwszVolumeName, 535 | IN BOOL * pbSupportedByThisProvider 536 | ) = 0; 537 | 538 | STDMETHOD(DisableWriterClasses) 539 | ( 540 | IN const VSS_ID *rgWriterClassId, 541 | IN UINT cClassId 542 | ) = 0; 543 | 544 | STDMETHOD(EnableWriterClasses) 545 | ( 546 | IN const VSS_ID *rgWriterClassId, 547 | IN UINT cClassId 548 | ) = 0; 549 | 550 | STDMETHOD(DisableWriterInstances) 551 | ( 552 | IN const VSS_ID *rgWriterInstanceId, 553 | IN UINT cInstanceId 554 | ) = 0; 555 | 556 | // called to expose a snapshot 557 | STDMETHOD(ExposeSnapshot) 558 | ( 559 | IN VSS_ID SnapshotId, 560 | IN VSS_PWSZ wszPathFromRoot, 561 | IN LONG lAttributes, 562 | IN VSS_PWSZ wszExpose, 563 | OUT VSS_PWSZ *pwszExposed 564 | ) = 0; 565 | 566 | STDMETHOD(RevertToSnapshot) 567 | ( 568 | IN VSS_ID SnapshotId, 569 | IN BOOL bForceDismount 570 | ) = 0; 571 | 572 | STDMETHOD(QueryRevertStatus) 573 | ( 574 | IN VSS_PWSZ pwszVolume, 575 | OUT IVssAsync **ppAsync 576 | ) = 0; 577 | 578 | }; 579 | 580 | class __declspec(uuid("963f03ad-9e4c-4a34-ac15-e4b6174e5036")) IVssBackupComponentsEx : public IVssBackupComponents 581 | { 582 | public: 583 | // get writer metadata for a specific writer 584 | STDMETHOD(GetWriterMetadataEx) 585 | ( 586 | IN UINT iWriter, 587 | OUT VSS_ID *pidInstance, 588 | OUT IVssExamineWriterMetadataEx **ppMetadata 589 | ) = 0; 590 | 591 | // indicate that a given component is selected to be restored 592 | STDMETHOD(SetSelectedForRestoreEx) 593 | ( 594 | IN VSS_ID writerId, 595 | IN VSS_COMPONENT_TYPE ct, 596 | IN LPCWSTR wszLogicalPath, 597 | IN LPCWSTR wszComponentName, 598 | IN bool bSelectedForRestore, 599 | IN VSS_ID instanceId = GUID_NULL 600 | ) = 0; 601 | 602 | }; 603 | 604 | __declspec(dllexport) HRESULT STDAPICALLTYPE CreateVssBackupComponents( 605 | OUT IVssBackupComponents **ppBackup 606 | ); 607 | 608 | __declspec(dllexport) HRESULT STDAPICALLTYPE CreateVssExamineWriterMetadata ( 609 | IN BSTR bstrXML, 610 | OUT IVssExamineWriterMetadata **ppMetadata 611 | ); 612 | 613 | #define VSS_SW_BOOTABLE_STATE (1 << 0) 614 | 615 | __declspec(dllexport) HRESULT APIENTRY SimulateSnapshotFreeze ( 616 | IN GUID guidSnapshotSetId, 617 | IN ULONG ulOptionFlags, 618 | IN ULONG ulVolumeCount, 619 | IN LPWSTR *ppwszVolumeNamesArray, 620 | OUT IVssAsync **ppAsync 621 | ); 622 | 623 | __declspec(dllexport) HRESULT APIENTRY SimulateSnapshotThaw( 624 | IN GUID guidSnapshotSetId 625 | ); 626 | 627 | __declspec(dllexport) HRESULT APIENTRY IsVolumeSnapshotted( 628 | IN VSS_PWSZ pwszVolumeName, 629 | OUT BOOL *pbSnapshotsPresent, 630 | OUT LONG *plSnapshotCapability 631 | ); 632 | 633 | ///////////////////////////////////////////////////////////////////// 634 | // Life-management methods for structure members 635 | 636 | __declspec(dllexport) void APIENTRY VssFreeSnapshotProperties( 637 | IN VSS_SNAPSHOT_PROP* pProp 638 | ); 639 | 640 | 641 | /// 642 | 643 | 644 | #endif // _VSBACKUP_H_ 645 | -------------------------------------------------------------------------------- /inc/win2003/vscoordint.idl: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2000 Microsoft Corporation 4 | // 5 | 6 | 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | // Imports 10 | // 11 | 12 | 13 | import "oaidl.idl"; 14 | import "ocidl.idl"; 15 | import "vss.idl"; 16 | 17 | 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | // Interfaces 21 | // 22 | 23 | 24 | [ 25 | object, 26 | uuid(da9f41d4-1a5d-41d0-a614-6dfd78df5d05), 27 | helpstring("IVssCoordinator interface"), 28 | pointer_default(unique) 29 | ] 30 | interface IVssCoordinator : IUnknown 31 | { 32 | [helpstring("method SetContext")] 33 | HRESULT SetContext( 34 | [in] LONG lContext 35 | ); 36 | 37 | [helpstring("method StartSnapshotSet")] 38 | HRESULT StartSnapshotSet( 39 | [out] VSS_ID* pSnapshotSetId 40 | ); 41 | 42 | [helpstring("method AddToSnapshotSet")] 43 | HRESULT AddToSnapshotSet( 44 | [in] VSS_PWSZ pwszVolumeName, 45 | [in] VSS_ID ProviderId, 46 | [out] VSS_ID *pSnapshotId 47 | ); 48 | 49 | [helpstring("method DoSnapshotSet")] 50 | HRESULT DoSnapshotSet( 51 | [in] IDispatch *pWriterCallback, 52 | [out] IVssAsync** ppAsync 53 | ); 54 | 55 | [helpstring("method GetSnapshotProperties")] 56 | HRESULT GetSnapshotProperties( 57 | [in] VSS_ID SnapshotId, 58 | [out] VSS_SNAPSHOT_PROP *pProp 59 | ); 60 | 61 | [helpstring("method ExposeSnapshot")] 62 | HRESULT ExposeSnapshot( 63 | [in] VSS_ID SnapshotId, 64 | [in] VSS_PWSZ wszPathFromRoot, 65 | [in] LONG lAttributes, 66 | [in] VSS_PWSZ wszExpose, 67 | [out] VSS_PWSZ *pwszExposed 68 | ); 69 | 70 | [helpstring("method ImportSnapshots")] 71 | HRESULT ImportSnapshots( 72 | [in] BSTR bstrXMLSnapshotSet, 73 | [out] IVssAsync** ppAsync 74 | ); 75 | 76 | [helpstring("method Query")] 77 | HRESULT Query( 78 | [in] VSS_ID QueriedObjectId, 79 | [in] VSS_OBJECT_TYPE eQueriedObjectType, 80 | [in] VSS_OBJECT_TYPE eReturnedObjectsType, 81 | [out] IVssEnumObject **ppEnum 82 | ); 83 | 84 | [helpstring("method DeleteSnapshots")] 85 | HRESULT DeleteSnapshots( 86 | [in] VSS_ID SourceObjectId, 87 | [in] VSS_OBJECT_TYPE eSourceObjectType, 88 | [in] BOOL bForceDelete, 89 | [out] LONG* plDeletedSnapshots, 90 | [out] VSS_ID* pNondeletedSnapshotID 91 | ); 92 | 93 | [helpstring("method BreakSnapshotSet")] 94 | HRESULT BreakSnapshotSet( 95 | [in] VSS_ID SnapshotSetId 96 | ); 97 | 98 | [helpstring("method RevertToSnapshot")] 99 | HRESULT RevertToSnapshot( 100 | [in] VSS_ID SnapshotId, 101 | [in] BOOL bForceDismount 102 | ); 103 | 104 | [helpstring("method QueryRevertStatus")] 105 | HRESULT QueryRevertStatus( 106 | [in] VSS_PWSZ pwszVolume, 107 | [out] IVssAsync **ppAsync 108 | ); 109 | 110 | [helpstring("method IsVolumeSupported")] 111 | HRESULT IsVolumeSupported( 112 | [in] VSS_ID ProviderId, 113 | [in] VSS_PWSZ pwszVolumeName, 114 | [out] BOOL * pbSupportedByThisProvider 115 | ); 116 | 117 | [helpstring("method IsVolumeSnapshotted")] 118 | HRESULT IsVolumeSnapshotted( 119 | [in] VSS_ID ProviderId, 120 | [in] VSS_PWSZ pwszVolumeName, 121 | [out] BOOL * pbSnapshotsPresent, 122 | [out] LONG * plSnapshotCompatibility 123 | ); 124 | 125 | [helpstring("method SetWriterInstances")] 126 | HRESULT SetWriterInstances( 127 | [in] LONG lWriterInstanceIdCount, 128 | [in, unique, size_is(lWriterInstanceIdCount)] 129 | VSS_ID *rgWriterInstanceId 130 | ); 131 | }; 132 | 133 | [ 134 | object, 135 | uuid(BF5AEED7-92BA-4484-97BE-EF7DA4825680), 136 | helpstring("IVssRemoteCoordinator interface"), 137 | pointer_default(unique) 138 | ] 139 | interface IVssRemoteCoordinator : IUnknown 140 | { 141 | [helpstring("method SetContext")] 142 | HRESULT SetContext( 143 | [in] LONG lContext 144 | ); 145 | 146 | [helpstring("method StartSnapshotSet")] 147 | HRESULT StartSnapshotSet( 148 | [in] VSS_PWSZ pwszMachineName, 149 | [in] VSS_ID SnapshotSetId 150 | ); 151 | 152 | [helpstring("method AddToSnapshotSet")] 153 | HRESULT AddToSnapshotSet( 154 | [in] VSS_PWSZ pwszShareName, 155 | [in] VSS_ID ProviderId, 156 | [out] VSS_ID *pSnapshotId 157 | ); 158 | 159 | [helpstring("method EndPrepareAllSnapshots")] 160 | HRESULT EndprepareAllSnapshots( 161 | ); 162 | 163 | [helpstring("method DoSnapshotSet")] 164 | HRESULT DoSnapshotSet( 165 | [in] LONG lTotalSnapshotsCount, 166 | [out] IVssAsync** ppAsync 167 | ); 168 | 169 | [helpstring("method GetSnapshotProperties")] 170 | HRESULT GetSnapshotProperties( 171 | [in] VSS_ID SnapshotId, 172 | [out] VSS_SNAPSHOT_PROP *pProp 173 | ); 174 | 175 | [helpstring("method ExposeSnapshot")] 176 | HRESULT ExposeSnapshot( 177 | [in] VSS_ID SnapshotId, 178 | [in] VSS_PWSZ wszPathFromRoot, 179 | [in] LONG lContext, 180 | [in] VSS_PWSZ wszExpose, 181 | [out] VSS_PWSZ *pwszExposed 182 | ); 183 | 184 | [helpstring("method Query")] 185 | HRESULT Query( 186 | [in] VSS_PWSZ pwszObjectName, 187 | [in] VSS_ID QueriedObjectId, 188 | [in] VSS_OBJECT_TYPE eQueriedObjectType, 189 | [in] VSS_OBJECT_TYPE eReturnedObjectsType, 190 | [out] IVssEnumObject **ppEnum 191 | ); 192 | 193 | [helpstring("method DeleteSnapshots")] 194 | HRESULT DeleteSnapshots( 195 | [in] VSS_ID SourceObjectId, 196 | [in] VSS_OBJECT_TYPE eSourceObjectType, 197 | [in] BOOL bForceDelete, 198 | [out] LONG* plDeletedSnapshots, 199 | [out] VSS_ID* pNondeletedSnapshotID 200 | ); 201 | 202 | [helpstring("method BreakSnapshotSet")] 203 | HRESULT BreakSnapshotSet( 204 | [in] VSS_ID SnapshotSetId 205 | ); 206 | 207 | [helpstring("method IsVolumeSupported")] 208 | HRESULT IsShareSupported( 209 | [in] VSS_ID ProviderId, 210 | [in] VSS_PWSZ pwszShareName, 211 | [out] BOOL * pbSupportedByThisProvider 212 | ); 213 | 214 | [helpstring("method IsVolumeSnapshotted")] 215 | HRESULT IsShareSnapshotted( 216 | [in] VSS_ID ProviderId, 217 | [in] VSS_PWSZ pwszShareName, 218 | [out] BOOL * pbSnapshotsPresent, 219 | [out] LONG * plSnapshotCompatibility 220 | ); 221 | }; 222 | 223 | [ 224 | object, 225 | uuid(F2C2787D-95AB-40D4-942D-298F5F757874), 226 | helpstring("IVssRemsnapCoordinatorInternal interface"), 227 | pointer_default(unique) 228 | ] 229 | interface IVssRemsnapCoordinatorInternal : IUnknown 230 | { 231 | [helpstring("method OnSnapshotSetDone")] 232 | HRESULT OnSnapshotSetDone( 233 | ); 234 | 235 | [helpstring("method OnSnapshotSetAbort")] 236 | HRESULT OnSnapshotSetAbort( 237 | ); 238 | }; 239 | 240 | 241 | [ 242 | object, 243 | uuid(D6222095-05C3-42f3-81D9-A4A0CEC05C26), 244 | helpstring("IVssShim interface"), 245 | pointer_default(unique) 246 | ] 247 | interface IVssShim : IUnknown 248 | { 249 | [helpstring("method SimulateSnapshotFreeze")] 250 | HRESULT SimulateSnapshotFreeze( 251 | [in] VSS_ID guidSnapshotSetId, 252 | [in] ULONG ulOptionFlags, 253 | [in] ULONG ulVolumeCount, 254 | [in, unique, size_is(ulVolumeCount, ) ] 255 | VSS_PWSZ* ppwszVolumeNamesArray, 256 | [out] IVssAsync** ppAsync 257 | ); 258 | 259 | [helpstring("method SimulateSnapshotThaw")] 260 | HRESULT SimulateSnapshotThaw( 261 | [in] VSS_ID guidSnapshotSetId 262 | ); 263 | 264 | [helpstring("method WaitForSubscribingCompletion")] 265 | HRESULT WaitForSubscribingCompletion(); 266 | }; 267 | 268 | [ 269 | object, 270 | uuid(77ED5996-2F63-11d3-8A39-00C04F72D8E3), 271 | helpstring("IVssAdmin interface"), 272 | pointer_default(unique) 273 | ] 274 | interface IVssAdmin : IUnknown 275 | { 276 | [helpstring("method RegisterProvider")] 277 | HRESULT RegisterProvider( 278 | [in] VSS_ID pProviderId, 279 | [in] CLSID ClassId, 280 | [in] VSS_PWSZ pwszProviderName, 281 | [in] VSS_PROVIDER_TYPE eProviderType, 282 | [in] VSS_PWSZ pwszProviderVersion, 283 | [in] VSS_ID ProviderVersionId 284 | ); 285 | 286 | [helpstring("method UnregisterProvider")] 287 | HRESULT UnregisterProvider( 288 | [in] VSS_ID ProviderId 289 | ); 290 | 291 | [helpstring("method QueryProviders")] 292 | HRESULT QueryProviders( 293 | [out] IVssEnumObject**ppEnum 294 | ); 295 | 296 | [helpstring("method AbortAllSnapshotsInProgress")] 297 | HRESULT AbortAllSnapshotsInProgress( 298 | ); 299 | }; 300 | 301 | 302 | //////////////////////////////////////////////////////// 303 | // VSS Type Library 304 | 305 | [ 306 | uuid(97AEFDD8-2F60-11d3-8A39-00C04F72D8E3), 307 | version(1.0), 308 | helpstring("Volume Shadow Copy Service 1.0 Type Library") 309 | ] 310 | library VSS 311 | { 312 | importlib("stdole2.tlb"); 313 | 314 | [ 315 | uuid(E579AB5F-1CC4-44b4-BED9-DE0991FF0623), 316 | helpstring("VSSCoordinator Class") 317 | ] 318 | coclass VSSCoordinator 319 | { 320 | [default] interface IVssCoordinator; 321 | interface IVssAdmin; 322 | interface IVssRemsnapCoordinatorInternal; 323 | } 324 | 325 | [ 326 | uuid(95243A62-2F9B-4FDF-B437-40D965F6D17F), 327 | helpstring("VSSRemoteCoordinator Class") 328 | ] 329 | coclass VSSRemoteCoordinator 330 | { 331 | [default] interface IVssRemoteCoordinator; 332 | interface IVssRemsnapCoordinatorInternal; 333 | } 334 | } 335 | -------------------------------------------------------------------------------- /inc/win2003/vsmgmt.idl: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // vsmgmt.idl - Interfaces for Snapshots management exposed by VSS and/or providers 4 | // 5 | // Copyright (c) 2005 Microsoft Corporation 6 | // 7 | 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | // Imports 11 | // 12 | 13 | import "oaidl.idl"; 14 | import "ocidl.idl"; 15 | 16 | import "vss.idl"; 17 | 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | // Constants 21 | // 22 | 23 | 24 | // Types of returned objects in a Query 25 | typedef enum _VSS_MGMT_OBJECT_TYPE { 26 | VSS_MGMT_OBJECT_UNKNOWN = 0, 27 | VSS_MGMT_OBJECT_VOLUME, // Refers to a volume to be snapshotted 28 | VSS_MGMT_OBJECT_DIFF_VOLUME, // Refers to a volume to hold a diff area 29 | VSS_MGMT_OBJECT_DIFF_AREA, // Refers to an association between the two objects above. 30 | } VSS_MGMT_OBJECT_TYPE; 31 | 32 | 33 | // Denotes that no maximum space is specified in AddDiffArea or ChangeDiffAreaMaximumSize 34 | const LONGLONG VSS_ASSOC_NO_MAX_SPACE = -1; 35 | 36 | // If this constant is specified in ChangeDiffAreaMaximumSize then the association is removed 37 | const LONGLONG VSS_ASSOC_REMOVE = 0; 38 | 39 | 40 | /////////////////////////////////////////////////////////////////////////////// 41 | // Typedefs and structures 42 | // 43 | 44 | 45 | // Structure containing the properties of a volume as being a volume to be snapshotted. 46 | typedef struct _VSS_VOLUME_PROP { 47 | VSS_PWSZ m_pwszVolumeName; // The volume name, in \\?\Volume{GUID} format. 48 | VSS_PWSZ m_pwszVolumeDisplayName; // The shortest mount point (for example C:\) 49 | } VSS_VOLUME_PROP, *PVSS_VOLUME_PROP; 50 | 51 | 52 | // Structure containing the properties of a volume that can be used to keep a diff area 53 | typedef struct _VSS_DIFF_VOLUME_PROP { 54 | VSS_PWSZ m_pwszVolumeName; // The volume name, in \\?\Volume{GUID} format. 55 | VSS_PWSZ m_pwszVolumeDisplayName; // Represents the shortest mount point (for example C:\) 56 | LONGLONG m_llVolumeFreeSpace; // Free space on that volume 57 | LONGLONG m_llVolumeTotalSpace; // Total space on that volume 58 | } VSS_DIFF_VOLUME_PROP, *PVSS_DIFF_VOLUME_PROP; 59 | 60 | 61 | // Structure containing the properties of a diff area association between 62 | // a volume to be snapshotted and a diff volume. 63 | typedef struct _VSS_DIFF_AREA_PROP { 64 | VSS_PWSZ m_pwszVolumeName; // The original volume name 65 | VSS_PWSZ m_pwszDiffAreaVolumeName; // The diff area volume name 66 | LONGLONG m_llMaximumDiffSpace; // Maximum space that on the diff area volume in this association. 67 | LONGLONG m_llAllocatedDiffSpace; // Allocated space on the diff area volume by this association. 68 | LONGLONG m_llUsedDiffSpace; // Used space from the allocated area above. 69 | } VSS_DIFF_AREA_PROP, *PVSS_DIFF_AREA_PROP; 70 | 71 | 72 | // General-purpose union containing the properties of a volume or diff area 73 | [ switch_type(VSS_MGMT_OBJECT_TYPE) ] 74 | typedef union { 75 | [case(VSS_MGMT_OBJECT_VOLUME)] VSS_VOLUME_PROP Vol; 76 | [case(VSS_MGMT_OBJECT_DIFF_VOLUME)] VSS_DIFF_VOLUME_PROP DiffVol; 77 | [case(VSS_MGMT_OBJECT_DIFF_AREA)] VSS_DIFF_AREA_PROP DiffArea; 78 | [default]; 79 | } VSS_MGMT_OBJECT_UNION; 80 | 81 | 82 | typedef struct _VSS_MGMT_OBJECT_PROP { 83 | VSS_MGMT_OBJECT_TYPE Type; 84 | [ switch_is(Type) ] VSS_MGMT_OBJECT_UNION Obj; 85 | } VSS_MGMT_OBJECT_PROP, *PVSS_MGMT_OBJECT_PROP; 86 | 87 | 88 | /////////////////////////////////////////////////////////////////////////////// 89 | // Forward declarations 90 | // 91 | 92 | interface IVssSnapshotMgmt; 93 | interface IVssDifferentialSoftwareSnapshotMgmt; 94 | interface IVssEnumMgmtObject; 95 | 96 | 97 | /////////////////////////////////////////////////////////////////////////////// 98 | // Interfaces 99 | // 100 | 101 | 102 | // Used to manage diff areas remotely for Software-based snapshots (using hte copy-on-write mechanism). 103 | // Implemented by VSS and each provider. 104 | [ 105 | object, 106 | uuid(FA7DF749-66E7-4986-A27F-E2F04AE53772), 107 | helpstring("IVssSnapshotMgmt interface"), 108 | pointer_default(unique) 109 | ] 110 | interface IVssSnapshotMgmt: IUnknown 111 | { 112 | // Returns an interface to further configure a snapshot provider 113 | HRESULT GetProviderMgmtInterface( 114 | [in] VSS_ID ProviderId, // It might be a software or a system provider. 115 | [in] REFIID InterfaceId, // Might be IID_IVssDifferentialSoftwareSnapshotMgmt 116 | [out, iid_is(InterfaceId)] 117 | IUnknown** ppItf 118 | ); 119 | 120 | // 121 | // Queries 122 | // 123 | 124 | // Query volumes that support snapshots 125 | HRESULT QueryVolumesSupportedForSnapshots( 126 | [in] VSS_ID ProviderId, 127 | [in] LONG lContext, 128 | [out] IVssEnumMgmtObject **ppEnum 129 | ); 130 | 131 | // Query snapshots on the given volume. 132 | HRESULT QuerySnapshotsByVolume( 133 | [in] VSS_PWSZ pwszVolumeName, 134 | [in] VSS_ID ProviderId, 135 | [out] IVssEnumObject **ppEnum 136 | ); 137 | }; 138 | 139 | 140 | 141 | // More APIs to manage diff areas remotely for Software-based snapshots (using hte copy-on-write mechanism). 142 | // Implemented by VSS 143 | [ 144 | object, 145 | uuid(0f61ec39-fe82-45f2-a3f0-768b5d427102), 146 | helpstring("IVssSnapshotMgmt2 interface"), 147 | pointer_default(unique) 148 | ] 149 | interface IVssSnapshotMgmt2: IUnknown 150 | { 151 | // Returns an interface to further configure a snapshot provider 152 | HRESULT GetMinDiffAreaSize( 153 | [out] LONGLONG * pllMinDiffAreaSize 154 | ); 155 | }; 156 | 157 | 158 | 159 | // Used to manage diff areas remotely for Software-based 160 | // snapshots (using the copy-on-write mechanism). 161 | // This is implemented by a Snapshot/System provider and 162 | // returned by IVssSnapshotMgmt::GetProviderMgmtInterface 163 | [ 164 | object, 165 | uuid(214A0F28-B737-4026-B847-4F9E37D79529), 166 | helpstring("IVssDifferentialSoftwareSnapshotMgmt interface"), 167 | pointer_default(unique) 168 | ] 169 | interface IVssDifferentialSoftwareSnapshotMgmt: IUnknown 170 | { 171 | // 172 | // Diff area management 173 | // 174 | 175 | // Adds a diff area association for a certain volume. 176 | // If the association is not supported, an error code will be returned. 177 | HRESULT AddDiffArea( 178 | [in] VSS_PWSZ pwszVolumeName, 179 | [in] VSS_PWSZ pwszDiffAreaVolumeName, 180 | [in] LONGLONG llMaximumDiffSpace 181 | ); 182 | 183 | // Updates the diff area max size for a certain volume. 184 | // This may not have an immediate effect 185 | // note that setting llMaximumDiffSpace to 0 will disable the 186 | // diff area 187 | HRESULT ChangeDiffAreaMaximumSize( 188 | [in] VSS_PWSZ pwszVolumeName, 189 | [in] VSS_PWSZ pwszDiffAreaVolumeName, 190 | [in] LONGLONG llMaximumDiffSpace 191 | ); 192 | 193 | // 194 | // Queries 195 | // 196 | 197 | // Query volumes that support diff areas (including the disabled ones) 198 | HRESULT QueryVolumesSupportedForDiffAreas( 199 | [in] VSS_PWSZ pwszOriginalVolumeName, 200 | [out] IVssEnumMgmtObject **ppEnum 201 | ); 202 | 203 | // Query diff areas that host snapshots on the given (snapshotted) volume 204 | HRESULT QueryDiffAreasForVolume( 205 | [in] VSS_PWSZ pwszVolumeName, 206 | [out] IVssEnumMgmtObject **ppEnum 207 | ); 208 | 209 | // Query diff areas that physically reside on the given volume 210 | HRESULT QueryDiffAreasOnVolume( 211 | [in] VSS_PWSZ pwszVolumeName, 212 | [out] IVssEnumMgmtObject **ppEnum 213 | ); 214 | 215 | // Query diff areas in use by the given snapshot 216 | HRESULT QueryDiffAreasForSnapshot( 217 | [in] VSS_ID SnapshotId, 218 | [out] IVssEnumMgmtObject **ppEnum 219 | ); 220 | }; 221 | 222 | 223 | 224 | // This returns a set of volumes that can be snapshotted by Babbage. Returned by Query. 225 | [ 226 | object, 227 | uuid(01954E6B-9254-4e6e-808C-C9E05D007696), 228 | helpstring("IVssEnumMgmtObject Interface"), 229 | pointer_default(unique) 230 | ] 231 | interface IVssEnumMgmtObject : IUnknown 232 | { 233 | HRESULT Next( 234 | [in] ULONG celt, 235 | [out, size_is(celt), length_is(*pceltFetched)] 236 | VSS_MGMT_OBJECT_PROP *rgelt, 237 | [out] ULONG *pceltFetched 238 | ); 239 | 240 | HRESULT Skip( 241 | [in] ULONG celt 242 | ); 243 | 244 | HRESULT Reset(); 245 | 246 | HRESULT Clone( 247 | [in, out] IVssEnumMgmtObject **ppenum 248 | ); 249 | }; 250 | 251 | 252 | //////////////////////////////////////////////////////////////////////////////// 253 | // Snapshot Mgmt Type Library 254 | // 255 | 256 | [ 257 | uuid(84015C41-291D-49e6-BF7F-DD40AE93632B), 258 | version(1.0), 259 | helpstring("Shadow Copy Mgmt 1.0 Type Library") 260 | ] 261 | library VSMGMT 262 | { 263 | importlib("stdole2.tlb"); 264 | 265 | [ 266 | uuid(0B5A2C52-3EB9-470a-96E2-6C6D4570E40F), 267 | helpstring("VssSnapshotMgmt Class") 268 | ] 269 | coclass VssSnapshotMgmt 270 | { 271 | [default] interface IVssSnapshotMgmt; 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /inc/win2003/vsprov.idl: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2000 Microsoft Corporation 4 | // 5 | 6 | 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | // Imports 10 | // 11 | 12 | 13 | import "oaidl.idl"; 14 | import "ocidl.idl"; 15 | 16 | import "vss.idl"; 17 | import "vdslun.idl"; 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | // Forward declarations 21 | // 22 | 23 | // interfaces supported by the provider 24 | interface IVssSnapshotProvider; 25 | interface IVssProviderNotifications; 26 | 27 | 28 | typedef VSS_PWSZ *PVSS_PWSZ; 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // Interfaces 32 | // 33 | 34 | [ 35 | object, 36 | uuid(609e123e-2c5a-44d3-8f01-0b1d9a47d1ff), 37 | helpstring("IVssSoftwareSnapshotProvider interface"), 38 | pointer_default(unique) 39 | ] 40 | interface IVssSoftwareSnapshotProvider : IUnknown 41 | { 42 | [helpstring("method SetContext")] 43 | HRESULT SetContext( 44 | [in] LONG lContext 45 | ); 46 | 47 | [helpstring("method GetSnapshot")] 48 | HRESULT GetSnapshotProperties( 49 | [in] VSS_ID SnapshotId, 50 | [out] VSS_SNAPSHOT_PROP *pProp 51 | ); 52 | 53 | [helpstring("method Query")] 54 | HRESULT Query( 55 | [in] VSS_ID QueriedObjectId, 56 | [in] VSS_OBJECT_TYPE eQueriedObjectType, 57 | [in] VSS_OBJECT_TYPE eReturnedObjectsType, 58 | [out] IVssEnumObject **ppEnum 59 | ); 60 | 61 | [helpstring("method DeleteSnapshots")] 62 | HRESULT DeleteSnapshots( 63 | [in] VSS_ID SourceObjectId, 64 | [in] VSS_OBJECT_TYPE eSourceObjectType, 65 | [in] BOOL bForceDelete, 66 | [out] LONG* plDeletedSnapshots, 67 | [out] VSS_ID* pNondeletedSnapshotID 68 | ); 69 | 70 | [helpstring("method BeginPrepareSnapshot")] 71 | HRESULT BeginPrepareSnapshot( 72 | [in] VSS_ID SnapshotSetId, 73 | [in] VSS_ID SnapshotId, 74 | [in] VSS_PWSZ pwszVolumeName, 75 | [in] LONG lNewContext 76 | ); 77 | 78 | [helpstring("method IsVolumeSupported")] 79 | HRESULT IsVolumeSupported( 80 | [in] VSS_PWSZ pwszVolumeName, 81 | [out] BOOL * pbSupportedByThisProvider 82 | ); 83 | 84 | [helpstring("method IsVolumeSnapshotted")] 85 | HRESULT IsVolumeSnapshotted( 86 | [in] VSS_PWSZ pwszVolumeName, 87 | [out] BOOL * pbSnapshotsPresent, 88 | [out] LONG * plSnapshotCompatibility 89 | ); 90 | 91 | [helpstring("method SetSnapshotProperty")] 92 | HRESULT SetSnapshotProperty ( 93 | [in] VSS_ID SnapshotId, 94 | [in] VSS_SNAPSHOT_PROPERTY_ID eSnapshotPropertyId, 95 | [in] VARIANT vProperty 96 | ); 97 | 98 | [helpstring("method RevertToSnapshot")] 99 | HRESULT RevertToSnapshot( 100 | [in] VSS_ID SnapshotId 101 | ); 102 | 103 | [helpstring("method QueryRevertStatus")] 104 | HRESULT QueryRevertStatus( 105 | [in] VSS_PWSZ pwszVolume, 106 | [out] IVssAsync** ppAsync 107 | ); 108 | }; 109 | 110 | 111 | [ 112 | object, 113 | uuid(5F894E5B-1E39-4778-8E23-9ABAD9F0E08C), 114 | helpstring("IVssProviderCreateSnapshotSet interface"), 115 | pointer_default(unique) 116 | ] 117 | interface IVssProviderCreateSnapshotSet : IUnknown 118 | { 119 | [helpstring("method EndPrepareSnapshots")] 120 | HRESULT EndPrepareSnapshots( 121 | [in] VSS_ID SnapshotSetId 122 | ); 123 | 124 | [helpstring("method PreCommitSnapshots")] 125 | HRESULT PreCommitSnapshots( 126 | [in] VSS_ID SnapshotSetId 127 | ); 128 | 129 | [helpstring("method CommitSnapshots")] 130 | HRESULT CommitSnapshots( 131 | [in] VSS_ID SnapshotSetId 132 | ); 133 | 134 | [helpstring("method PostCommitSnapshots")] 135 | HRESULT PostCommitSnapshots( 136 | [in] VSS_ID SnapshotSetId, 137 | [in] LONG lSnapshotsCount 138 | ); 139 | 140 | [helpstring("method PreFinalCommitSnapshots")] 141 | HRESULT PreFinalCommitSnapshots( 142 | [in] VSS_ID SnapshotSetId 143 | ); 144 | 145 | [helpstring("method PostFinalCommitSnapshots")] 146 | HRESULT PostFinalCommitSnapshots( 147 | [in] VSS_ID SnapshotSetId 148 | ); 149 | 150 | [helpstring("method AbortSnapshots")] 151 | HRESULT AbortSnapshots( 152 | [in] VSS_ID SnapshotSetId 153 | ); 154 | }; 155 | 156 | 157 | [ 158 | object, 159 | uuid(E561901F-03A5-4afe-86D0-72BAEECE7004), 160 | helpstring("IVssProviderNotifications interface"), 161 | pointer_default(unique) 162 | ] 163 | interface IVssProviderNotifications : IUnknown 164 | { 165 | [helpstring("method OnLoad")] 166 | HRESULT OnLoad( 167 | [in,unique] IUnknown* pCallback 168 | ); 169 | 170 | [helpstring("method OnUnload")] 171 | HRESULT OnUnload( 172 | [in] BOOL bForceUnload 173 | ); 174 | }; 175 | 176 | 177 | [ 178 | object, 179 | uuid(9593A157-44E9-4344-BBEB-44FBF9B06B10), 180 | helpstring("IVssHardwareSnapshotProvider interface"), 181 | pointer_default(unique) 182 | ] 183 | interface IVssHardwareSnapshotProvider : IUnknown 184 | { 185 | [helpstring("method AreLunsSupported")] 186 | HRESULT AreLunsSupported ( 187 | [in] LONG lLunCount, 188 | [in] LONG lContext, 189 | [in, unique, size_is(lLunCount)] VSS_PWSZ *rgwszDevices, 190 | [in, out, size_is(lLunCount)] VDS_LUN_INFORMATION *pLunInformation, 191 | [out] BOOL *pbIsSupported 192 | ); 193 | 194 | [helpstring("method FillInLunInfo")] 195 | HRESULT FillInLunInfo ( 196 | [in] VSS_PWSZ wszDeviceName, 197 | [in, out] VDS_LUN_INFORMATION *pLunInfo, 198 | [out] BOOL *pbIsSupported 199 | ); 200 | 201 | 202 | [helpstring("method BeginPrepareSnapshot")] 203 | HRESULT BeginPrepareSnapshot( 204 | [in] VSS_ID SnapshotSetId, 205 | [in] VSS_ID SnapshotId, 206 | [in] LONG lContext, 207 | [in] LONG lLunCount, 208 | [in, unique, size_is(lLunCount)] VSS_PWSZ *rgDeviceNames, 209 | [in, out, size_is(lLunCount)] VDS_LUN_INFORMATION *rgLunInformation 210 | ); 211 | 212 | 213 | 214 | [helpstring("method GetTargetLuns")] 215 | HRESULT GetTargetLuns( 216 | [in] LONG lLunCount, 217 | [in, unique, size_is(lLunCount)] VSS_PWSZ *rgDeviceNames, 218 | [in, unique, size_is(lLunCount)] VDS_LUN_INFORMATION *rgSourceLuns, 219 | [in, out, size_is(lLunCount)] VDS_LUN_INFORMATION *rgDestinationLuns 220 | ); 221 | 222 | [helpstring("method LocateLuns")] 223 | HRESULT LocateLuns( 224 | [in] LONG lLunCount, 225 | [in, unique, size_is(lLunCount)] 226 | VDS_LUN_INFORMATION *rgSourceLuns 227 | ); 228 | 229 | [helpstring("OnLunEmpty")] 230 | HRESULT OnLunEmpty ( 231 | [in, unique] VSS_PWSZ wszDeviceName, 232 | [in, unique] VDS_LUN_INFORMATION *pInformation 233 | ); 234 | 235 | }; 236 | 237 | 238 | //////////////////////////////////////////////////////// 239 | // VSS Type Library 240 | 241 | [ 242 | 243 | uuid(73C8B4C1-6E9D-4fc2-B304-030EC763FE81), 244 | version(1.0), 245 | helpstring("Volume Shadow Copy Service Provider 1.0 Type Library") 246 | 247 | ] 248 | library VSSProvider 249 | { 250 | importlib("stdole2.tlb"); 251 | 252 | } 253 | -------------------------------------------------------------------------------- /inc/win2003/vsswprv.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 6.00.0366 */ 7 | /* Compiler settings for vsswprv.idl: 8 | Oicf, W1, Zp8, env=Win32 (32b run) 9 | protocol : dce , ms_ext, c_ext, robust 10 | error checks: allocation ref bounds_check enum stub_data 11 | VC __declspec() decoration level: 12 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 13 | DECLSPEC_UUID(), MIDL_INTERFACE() 14 | */ 15 | //@@MIDL_FILE_HEADING( ) 16 | 17 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 18 | 19 | 20 | /* verify that the version is high enough to compile this file*/ 21 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 22 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 23 | #endif 24 | 25 | #include "rpc.h" 26 | #include "rpcndr.h" 27 | 28 | #ifndef __RPCNDR_H_VERSION__ 29 | #error this stub requires an updated version of 30 | #endif // __RPCNDR_H_VERSION__ 31 | 32 | 33 | #ifndef __vsswprv_h__ 34 | #define __vsswprv_h__ 35 | 36 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 37 | #pragma once 38 | #endif 39 | 40 | /* Forward Declarations */ 41 | 42 | #ifndef __VSSoftwareProvider_FWD_DEFINED__ 43 | #define __VSSoftwareProvider_FWD_DEFINED__ 44 | 45 | #ifdef __cplusplus 46 | typedef class VSSoftwareProvider VSSoftwareProvider; 47 | #else 48 | typedef struct VSSoftwareProvider VSSoftwareProvider; 49 | #endif /* __cplusplus */ 50 | 51 | #endif /* __VSSoftwareProvider_FWD_DEFINED__ */ 52 | 53 | 54 | /* header files for imported files */ 55 | #include "oaidl.h" 56 | #include "ocidl.h" 57 | #include "vss.h" 58 | 59 | #ifdef __cplusplus 60 | extern "C"{ 61 | #endif 62 | 63 | void * __RPC_USER MIDL_user_allocate(size_t); 64 | void __RPC_USER MIDL_user_free( void * ); 65 | 66 | /* interface __MIDL_itf_vsswprv_0000 */ 67 | /* [local] */ 68 | 69 | const GUID VSS_SWPRV_ProviderId = { 0xb5946137, 0x7b9f, 0x4925, { 0xaf, 0x80, 0x51, 0xab, 0xd6, 0xb, 0x20, 0xd5 } }; 70 | 71 | 72 | extern RPC_IF_HANDLE __MIDL_itf_vsswprv_0000_v0_0_c_ifspec; 73 | extern RPC_IF_HANDLE __MIDL_itf_vsswprv_0000_v0_0_s_ifspec; 74 | 75 | 76 | #ifndef __VSSW_LIBRARY_DEFINED__ 77 | #define __VSSW_LIBRARY_DEFINED__ 78 | 79 | /* library VSSW */ 80 | /* [helpstring][version][uuid] */ 81 | 82 | 83 | EXTERN_C const IID LIBID_VSSW; 84 | 85 | EXTERN_C const CLSID CLSID_VSSoftwareProvider; 86 | 87 | #ifdef __cplusplus 88 | 89 | class DECLSPEC_UUID("65EE1DBA-8FF4-4a58-AC1C-3470EE2F376A") 90 | VSSoftwareProvider; 91 | #endif 92 | #endif /* __VSSW_LIBRARY_DEFINED__ */ 93 | 94 | /* Additional Prototypes for ALL interfaces */ 95 | 96 | /* end of Additional Prototypes */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | 104 | 105 | -------------------------------------------------------------------------------- /inc/win2003/vsswprv.idl: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2000 Microsoft Corporation 4 | // 5 | 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Imports 9 | // 10 | 11 | import "oaidl.idl"; 12 | import "ocidl.idl"; 13 | 14 | import "vss.idl"; 15 | 16 | 17 | 18 | /////////////////////////////////////////////////////////////////////////////// 19 | // Constants and enums 20 | // 21 | 22 | 23 | #pragma midl_echo( "const GUID VSS_SWPRV_ProviderId = { 0xb5946137, 0x7b9f, 0x4925, { 0xaf, 0x80, 0x51, 0xab, 0xd6, 0xb, 0x20, 0xd5 } };" ) 24 | 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | // Typedefs and structures 28 | // 29 | 30 | 31 | /////////////////////////////////////////////////////////////////////////////// 32 | // Forward declarations 33 | // 34 | 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | // Interfaces 38 | // 39 | 40 | 41 | 42 | 43 | //////////////////////////////////////////////////////////////////////////////// 44 | // Snapshot Software Type Library 45 | // @doc 46 | 47 | [ 48 | uuid(93BB06B6-B6DA-43c8-BC9B-E32DB49AA6F7), 49 | version(1.0), 50 | helpstring("Software Shadow Copy provider 1.0 Type Library") 51 | ] 52 | library VSSW 53 | { 54 | importlib("stdole2.tlb"); 55 | 56 | [ 57 | uuid(65EE1DBA-8FF4-4a58-AC1C-3470EE2F376A), 58 | helpstring("VSSoftwareProvider Class") 59 | ] 60 | coclass VSSoftwareProvider 61 | { 62 | [default] interface IUnknown; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /inc/winxp/vsbackup.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | vsbackup.h 8 | 9 | Abstract: 10 | 11 | Declaration of backup interfaces IVssExamineWriterMetadata and 12 | IVssBackupComponents, IVssWMComponent 13 | 14 | Brian Berkowitz [brianb] 3/13/2000 15 | 16 | 17 | TBD: 18 | 19 | Add comments. 20 | 21 | Revision History: 22 | 23 | Name Date Comments 24 | brianb 03/30/2000 Created 25 | brianb 04/18/2000 Added IVssCancelCallback 26 | brianb 05/03/2000 Changed IVssWriter::Initialize method 27 | brianb 05/16/2000 Remove cancel stuff 28 | mikejohn 05/24/2000 Changed parameters on SimulateXxxx() calls 29 | mikejohn 09/18/2000 176860: Added calling convention methods where missing 30 | ssteiner 11/10/2000 143801 MOve SimulateSnashotXxxx() calls to be hosted by VssSvc 31 | 32 | --*/ 33 | 34 | #ifndef _VSBACKUP_H_ 35 | #define _VSBACKUP_H_ 36 | 37 | // description of a component 38 | typedef struct _VSS_COMPONENTINFO 39 | { 40 | VSS_COMPONENT_TYPE type; // either VSS_CT_DATABASE or VSS_CT_FILEGROUP 41 | BSTR bstrLogicalPath; // logical path to component 42 | BSTR bstrComponentName; // component name 43 | BSTR bstrCaption; // description of component 44 | BYTE *pbIcon; // icon 45 | UINT cbIcon; // icon 46 | bool bRestoreMetadata; // whether component supplies restore metadata 47 | bool bNotifyOnBackupComplete; // whether component needs to be informed if backup was successful 48 | bool bSelectable; // is component selectable 49 | UINT cFileCount; // # of files in file group 50 | UINT cDatabases; // # of database files 51 | UINT cLogFiles; // # of log files 52 | } VSS_COMPONENTINFO; 53 | 54 | typedef const VSS_COMPONENTINFO *PVSSCOMPONENTINFO; 55 | 56 | 57 | // component information 58 | class IVssWMComponent : public IUnknown 59 | { 60 | public: 61 | // get component information 62 | STDMETHOD(GetComponentInfo)(PVSSCOMPONENTINFO *ppInfo) = 0; 63 | 64 | // free component information 65 | STDMETHOD(FreeComponentInfo)(PVSSCOMPONENTINFO pInfo) = 0; 66 | 67 | // obtain a specific file in a file group 68 | STDMETHOD(GetFile) 69 | ( 70 | IN UINT iFile, 71 | OUT IVssWMFiledesc **ppFiledesc 72 | ) = 0; 73 | 74 | // obtain a specific physical database file for a database 75 | STDMETHOD(GetDatabaseFile) 76 | ( 77 | IN UINT iDBFile, 78 | OUT IVssWMFiledesc **ppFiledesc 79 | ) = 0; 80 | 81 | // obtain a specific physical log file for a database 82 | STDMETHOD(GetDatabaseLogFile) 83 | ( 84 | IN UINT iDbLogFile, 85 | OUT IVssWMFiledesc **ppFiledesc 86 | ) = 0; 87 | }; 88 | 89 | 90 | // interface to examine writer metadata 91 | class IVssExamineWriterMetadata : public IUnknown 92 | { 93 | public: 94 | // obtain identity of the writer 95 | STDMETHOD(GetIdentity) 96 | ( 97 | OUT Guid *pidInstance, 98 | OUT Guid *pidWriter, 99 | OUT BSTR *pbstrWriterName, 100 | OUT VSS_USAGE_TYPE *pUsage, 101 | OUT VSS_SOURCE_TYPE *pSource 102 | ) = 0; 103 | 104 | // obtain number of include files, exclude files, and components 105 | STDMETHOD(GetFileCounts) 106 | ( 107 | OUT UINT *pcIncludeFiles, 108 | OUT UINT *pcExcludeFiles, 109 | OUT UINT *pcComponents 110 | ) = 0; 111 | 112 | // obtain specific include files 113 | STDMETHOD(GetIncludeFile) 114 | ( 115 | IN UINT iFile, 116 | OUT IVssWMFiledesc **ppFiledesc 117 | ) = 0; 118 | 119 | // obtain specific exclude files 120 | STDMETHOD(GetExcludeFile) 121 | ( 122 | IN UINT iFile, 123 | OUT IVssWMFiledesc **ppFiledesc 124 | ) = 0; 125 | 126 | // obtain specific component 127 | STDMETHOD(GetComponent) 128 | ( 129 | IN UINT iComponent, 130 | OUT IVssWMComponent **ppComponent 131 | ) = 0; 132 | 133 | // obtain restoration method 134 | STDMETHOD(GetRestoreMethod) 135 | ( 136 | OUT VSS_RESTOREMETHOD_ENUM *pMethod, 137 | OUT BSTR *pbstrService, 138 | OUT BSTR *pbstrUserProcedure, 139 | OUT VSS_WRITERRESTORE_ENUM *pwriterRestore, 140 | OUT bool *pbRebootRequired, 141 | UINT *pcMappings 142 | ) = 0; 143 | 144 | // obtain a specific alternative location mapping 145 | STDMETHOD(GetAlternateLocationMapping) 146 | ( 147 | IN UINT iMapping, 148 | OUT IVssWMFiledesc **ppFiledesc 149 | ) = 0; 150 | 151 | // obtain reference to actual XML document 152 | STDMETHOD(GetDocument)(IXMLDOMDocument **pDoc) = 0; 153 | 154 | // convert document to a XML string 155 | STDMETHOD(SaveAsXML)(BSTR *pbstrXML) = 0; 156 | 157 | // load document from an XML string 158 | STDMETHOD(LoadFromXML)(BSTR bstrXML) = 0; 159 | }; 160 | 161 | 162 | class IVssWriterComponentsExt : 163 | public IVssWriterComponents, 164 | public IUnknown 165 | { 166 | }; 167 | 168 | 169 | // backup components interface 170 | class IVssBackupComponents : public IUnknown 171 | { 172 | public: 173 | // get count of writer components 174 | STDMETHOD(GetWriterComponentsCount)(OUT UINT *pcComponents) = 0; 175 | 176 | // obtain a specific writer component 177 | STDMETHOD(GetWriterComponents) 178 | ( 179 | IN UINT iWriter, 180 | OUT IVssWriterComponentsExt **ppWriter 181 | ) = 0; 182 | 183 | // initialize and create BACKUP_COMPONENTS document 184 | STDMETHOD(InitializeForBackup)(IN BSTR bstrXML = NULL) = 0; 185 | 186 | // set state describing backup 187 | STDMETHOD(SetBackupState) 188 | ( 189 | IN bool bSelectComponents, 190 | IN bool bBackupBootableSystemState, 191 | IN VSS_BACKUP_TYPE backupType, 192 | IN bool bPartialFileSupport = false 193 | ) = 0; 194 | 195 | STDMETHOD(InitializeForRestore)(IN BSTR bstrXML) = 0; 196 | 197 | // gather writer metadata 198 | STDMETHOD(GatherWriterMetadata) 199 | ( 200 | OUT IVssAsync **pAsync 201 | ) = 0; 202 | 203 | // get count of writers with metadata 204 | STDMETHOD(GetWriterMetadataCount) 205 | ( 206 | OUT UINT *pcWriters 207 | ) = 0; 208 | 209 | // get writer metadata for a specific writer 210 | STDMETHOD(GetWriterMetadata) 211 | ( 212 | IN UINT iWriter, 213 | OUT Guid *pidInstance, 214 | OUT IVssExamineWriterMetadata **ppMetadata 215 | ) = 0; 216 | 217 | // free writer metadata 218 | STDMETHOD(FreeWriterMetadata)() = 0; 219 | 220 | // add a component to the BACKUP_COMPONENTS document 221 | STDMETHOD(AddComponent) 222 | ( 223 | IN Guid instanceId, 224 | IN Guid writerId, 225 | IN VSS_COMPONENT_TYPE ct, 226 | IN LPCWSTR wszLogicalPath, 227 | IN LPCWSTR wszComponentName 228 | ) = 0; 229 | 230 | // dispatch PrepareForBackup event to writers 231 | STDMETHOD(PrepareForBackup) 232 | ( 233 | OUT IVssAsync **ppAsync 234 | ) = 0; 235 | 236 | // abort the backup 237 | STDMETHOD(AbortBackup)() = 0; 238 | 239 | // dispatch the Identify event so writers can expose their metadata 240 | STDMETHOD(GatherWriterStatus) 241 | ( 242 | OUT IVssAsync **pAsync 243 | ) = 0; 244 | 245 | 246 | // get count of writers with status 247 | STDMETHOD(GetWriterStatusCount) 248 | ( 249 | OUT UINT *pcWriters 250 | ) = 0; 251 | 252 | STDMETHOD(FreeWriterStatus)() = 0; 253 | 254 | STDMETHOD(GetWriterStatus) 255 | ( 256 | IN UINT iWriter, 257 | OUT Guid *pidInstance, 258 | OUT Guid *pidWriter, 259 | OUT BSTR *pbstrWriter, 260 | OUT VSS_WRITER_STATE *pnStatus, 261 | OUT HRESULT *phResultFailure 262 | ) = 0; 263 | 264 | // indicate whether backup succeeded on a component 265 | STDMETHOD(SetBackupSucceeded) 266 | ( 267 | IN Guid instanceId, 268 | IN Guid writerId, 269 | IN VSS_COMPONENT_TYPE ct, 270 | IN LPCWSTR wszLogicalPath, 271 | IN LPCWSTR wszComponentName, 272 | IN bool bSucceded 273 | ) = 0; 274 | 275 | // set backup options for the writer 276 | STDMETHOD(SetBackupOptions) 277 | ( 278 | IN Guid writerId, 279 | IN VSS_COMPONENT_TYPE ct, 280 | IN LPCWSTR wszLogicalPath, 281 | IN LPCWSTR wszComponentName, 282 | IN LPCWSTR wszBackupOptions 283 | ) = 0; 284 | 285 | // indicate that a given component is selected to be restored 286 | STDMETHOD(SetSelectedForRestore) 287 | ( 288 | IN Guid writerId, 289 | IN VSS_COMPONENT_TYPE ct, 290 | IN LPCWSTR wszLogicalPath, 291 | IN LPCWSTR wszComponentName, 292 | IN bool bSelectedForRestore 293 | ) = 0; 294 | 295 | 296 | // set restore options for the writer 297 | STDMETHOD(SetRestoreOptions) 298 | ( 299 | IN Guid writerId, 300 | IN VSS_COMPONENT_TYPE ct, 301 | IN LPCWSTR wszLogicalPath, 302 | IN LPCWSTR wszComponentName, 303 | IN LPCWSTR wszRestoreOptions 304 | ) = 0; 305 | 306 | // indicate that additional restores will follow 307 | STDMETHOD(SetAdditionalRestores) 308 | ( 309 | IN Guid writerId, 310 | IN VSS_COMPONENT_TYPE ct, 311 | IN LPCWSTR wszLogicalPath, 312 | IN LPCWSTR wszComponentName, 313 | IN bool bAdditionalRestores 314 | ) = 0; 315 | 316 | 317 | // set the backup stamp that the differential or incremental 318 | // backup is based on 319 | STDMETHOD(SetPreviousBackupStamp) 320 | ( 321 | IN Guid writerId, 322 | IN VSS_COMPONENT_TYPE ct, 323 | IN LPCWSTR wszLogicalPath, 324 | IN LPCWSTR wszComponentName, 325 | IN LPCWSTR wszPreviousBackupStamp 326 | ) = 0; 327 | 328 | 329 | 330 | // save BACKUP_COMPONENTS document as XML string 331 | STDMETHOD(SaveAsXML)(BSTR *pbstrXML) = 0; 332 | 333 | // signal BackupComplete event to the writers 334 | STDMETHOD(BackupComplete)(OUT IVssAsync **ppAsync) = 0; 335 | 336 | // add an alternate mapping on restore 337 | STDMETHOD(AddAlternativeLocationMapping) 338 | ( 339 | IN Guid writerId, 340 | IN VSS_COMPONENT_TYPE componentType, 341 | IN LPCWSTR wszLogicalPath, 342 | IN LPCWSTR wszComponentName, 343 | IN LPCWSTR wszPath, 344 | IN LPCWSTR wszFilespec, 345 | IN bool bRecursive, 346 | IN LPCWSTR wszDestination 347 | ) = 0; 348 | 349 | // add a subcomponent to be restored 350 | STDMETHOD(AddRestoreSubcomponent) 351 | ( 352 | IN Guid writerId, 353 | IN VSS_COMPONENT_TYPE componentType, 354 | IN LPCWSTR wszLogicalPath, 355 | IN LPCWSTR wszComponentName, 356 | IN LPCWSTR wszSubComponentLogicalPath, 357 | IN LPCWSTR wszSubComponentName, 358 | IN bool bRepair 359 | ) = 0; 360 | 361 | // requestor indicates whether files were successfully restored 362 | STDMETHOD(SetFileRestoreStatus) 363 | ( 364 | IN Guid writerId, 365 | IN VSS_COMPONENT_TYPE ct, 366 | IN LPCWSTR wszLogicalPath, 367 | IN LPCWSTR wszComponentName, 368 | IN VSS_FILE_RESTORE_STATUS status 369 | ) = 0; 370 | 371 | 372 | // signal PreRestore event to the writers 373 | STDMETHOD(PreRestore)(OUT IVssAsync **ppAsync) = 0; 374 | 375 | // signal PostRestore event to the writers 376 | STDMETHOD(PostRestore)(OUT IVssAsync **ppAsync) = 0; 377 | 378 | // Called to set the context for subsequent snapshot-related operations 379 | STDMETHOD(SetContext) 380 | ( 381 | IN LONG lContext 382 | ) = 0; 383 | 384 | // start a snapshot set 385 | STDMETHOD(StartSnapshotSet) 386 | ( 387 | OUT Guid *pSnapshotSetId 388 | ) = 0; 389 | 390 | // add a volume to a snapshot set 391 | STDMETHOD(AddToSnapshotSet) 392 | ( 393 | IN VSS_PWSZ pwszVolumeName, 394 | IN Guid ProviderId, 395 | OUT Guid *pidSnapshot 396 | ) = 0; 397 | 398 | // create the snapshot set 399 | STDMETHOD(DoSnapshotSet) 400 | ( 401 | OUT IVssAsync** ppAsync 402 | ) = 0; 403 | 404 | STDMETHOD(DeleteSnapshots) 405 | ( 406 | IN Guid SourceObjectId, 407 | IN VSS_OBJECT_TYPE eSourceObjectType, 408 | IN BOOL bForceDelete, 409 | IN LONG* plDeletedSnapshots, 410 | IN Guid* pNondeletedSnapshotID 411 | ) = 0; 412 | 413 | STDMETHOD(ImportSnapshots) 414 | ( 415 | OUT IVssAsync** ppAsync 416 | ) = 0; 417 | 418 | STDMETHOD(RemountReadWrite) 419 | ( 420 | IN Guid SnapshotId, 421 | OUT IVssAsync** pAsync 422 | ) = 0; 423 | 424 | STDMETHOD(BreakSnapshotSet) 425 | ( 426 | IN Guid SnapshotSetId 427 | ) = 0; 428 | 429 | STDMETHOD(GetSnapshotProperties) 430 | ( 431 | IN Guid SnapshotId, 432 | OUT VSS_SNAPSHOT_PROP *pProp 433 | ) = 0; 434 | 435 | STDMETHOD(Query) 436 | ( 437 | IN Guid QueriedObjectId, 438 | IN VSS_OBJECT_TYPE eQueriedObjectType, 439 | IN VSS_OBJECT_TYPE eReturnedObjectsType, 440 | IN IVssEnumObject **ppEnum 441 | ) = 0; 442 | 443 | STDMETHOD(IsVolumeSupported) 444 | ( 445 | IN Guid ProviderId, 446 | IN VSS_PWSZ pwszVolumeName, 447 | IN BOOL * pbSupportedByThisProvider 448 | ) = 0; 449 | 450 | STDMETHOD(DisableWriterClasses) 451 | ( 452 | IN const Guid *rgWriterClassId, 453 | IN UINT cClassId 454 | ) = 0; 455 | 456 | STDMETHOD(EnableWriterClasses) 457 | ( 458 | IN const Guid *rgWriterClassId, 459 | IN UINT cClassId 460 | ) = 0; 461 | 462 | STDMETHOD(DisableWriterInstances) 463 | ( 464 | IN const Guid *rgWriterInstanceId, 465 | IN UINT cInstanceId 466 | ) = 0; 467 | 468 | // called to expose a snapshot 469 | STDMETHOD(ExposeSnapshot) 470 | ( 471 | IN Guid SnapshotId, 472 | IN VSS_PWSZ wszPathFromRoot, 473 | IN LONG lAttributes, 474 | IN VSS_PWSZ wszExpose, 475 | OUT VSS_PWSZ *pwszExposed 476 | ) = 0; 477 | 478 | }; 479 | 480 | 481 | __declspec(dllexport) HRESULT STDAPICALLTYPE CreateVssBackupComponents( 482 | OUT IVssBackupComponents **ppBackup 483 | ); 484 | 485 | __declspec(dllexport) HRESULT STDAPICALLTYPE CreateVssExamineWriterMetadata ( 486 | IN BSTR bstrXML, 487 | OUT IVssExamineWriterMetadata **ppMetadata 488 | ); 489 | 490 | 491 | #define VSS_SW_BOOTABLE_STATE (1 << 0) 492 | 493 | __declspec(dllexport) HRESULT APIENTRY SimulateSnapshotFreeze ( 494 | IN GUID guidSnapshotSetId, 495 | IN ULONG ulOptionFlags, 496 | IN ULONG ulVolumeCount, 497 | IN LPWSTR *ppwszVolumeNamesArray, 498 | OUT IVssAsync **ppAsync 499 | ); 500 | 501 | __declspec(dllexport) HRESULT APIENTRY SimulateSnapshotThaw( 502 | IN GUID guidSnapshotSetId 503 | ); 504 | 505 | __declspec(dllexport) HRESULT APIENTRY IsVolumeSnapshotted( 506 | IN VSS_PWSZ pwszVolumeName, 507 | OUT BOOL *pbSnapshotsPresent, 508 | OUT LONG *plSnapshotCapability 509 | ); 510 | 511 | ///////////////////////////////////////////////////////////////////// 512 | // Life-management methods for structure members 513 | 514 | __declspec(dllexport) void APIENTRY VssFreeSnapshotProperties( 515 | IN VSS_SNAPSHOT_PROP* pProp 516 | ); 517 | 518 | 519 | /// 520 | 521 | 522 | #endif // _VSBACKUP_H_ 523 | -------------------------------------------------------------------------------- /lib/win2003/obj/amd64/vss_uuid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/amd64/vss_uuid.lib -------------------------------------------------------------------------------- /lib/win2003/obj/amd64/vssapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/amd64/vssapi.lib -------------------------------------------------------------------------------- /lib/win2003/obj/i386/vss_uuid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/i386/vss_uuid.lib -------------------------------------------------------------------------------- /lib/win2003/obj/i386/vssapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/i386/vssapi.lib -------------------------------------------------------------------------------- /lib/win2003/obj/ia64/vss_uuid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/ia64/vss_uuid.lib -------------------------------------------------------------------------------- /lib/win2003/obj/ia64/vssapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/win2003/obj/ia64/vssapi.lib -------------------------------------------------------------------------------- /lib/winxp/obj/i386/vss_uuid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/winxp/obj/i386/vss_uuid.lib -------------------------------------------------------------------------------- /lib/winxp/obj/i386/vssapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/lib/winxp/obj/i386/vssapi.lib -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /stdafx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | // stdafx.cpp : source file that includes just the standard includes 25 | // HoboCopy.pch will be the pre-compiled header 26 | // stdafx.obj will contain the pre-compiled type information 27 | 28 | #include "stdafx.h" 29 | 30 | // TODO: reference any additional headers you need in STDAFX.H 31 | // and not in this file 32 | -------------------------------------------------------------------------------- /stdafx.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Wangdera Corporation (hobocopy@wangdera.com) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | // stdafx.h : include file for standard system include files, 26 | // or project specific include files that are used frequently, but 27 | // are changed infrequently 28 | // 29 | 30 | #pragma once 31 | 32 | // Modify the following defines if you have to target a platform prior to the ones specified below. 33 | // Refer to MSDN for the latest info on corresponding values for different platforms. 34 | #ifndef WINVER // Allow use of features specific to Windows XP or later. 35 | #define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. 36 | #endif 37 | 38 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 39 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 40 | #endif 41 | 42 | #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. 43 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 44 | #endif 45 | 46 | #ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. 47 | #define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. 48 | #endif 49 | 50 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 51 | #include 52 | #include 53 | 54 | 55 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 56 | 57 | #include 58 | #include 59 | 60 | // TODO: reference additional headers your program requires here 61 | #include 62 | #include 63 | //#include 64 | #include 65 | #include 66 | #include 67 | 68 | #include 69 | 70 | //#import raw_interfaces_only 71 | #include 72 | 73 | #include 74 | 75 | using namespace std; 76 | 77 | #define CHECK_HRESULT(x) { HRESULT ckhr = ((x)); if (ckhr != S_OK) throw new CComException(ckhr, __FILE__, __LINE__); } 78 | 79 | //#include "CHoboCopyException.h" 80 | //#include "Utilities.h" 81 | //#include "Console.h" 82 | //#include "OutputWriter.h" 83 | //#include "CCopyFilter.h" 84 | //#include "CDirectoryAction.h" 85 | //#include "CCopyAction.h" 86 | //#include "CDeleteAction.h" 87 | //#include "CIncludeAllCopyFilter.h" 88 | //#include "CModifiedSinceCopyFilter.h" 89 | //#include "CBackupState.h" 90 | -------------------------------------------------------------------------------- /vcredist_x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candera/hobocopy/6d077add489a22015bba8efb3432a556057e942e/vcredist_x86.exe --------------------------------------------------------------------------------