| 34 | } |
| 35 | |
| 36 | bool DeleteKeyCommand::Undo() { |
| 37 | auto key = Registry::OpenKey(_path, KEY_CREATE_SUB_KEY); |
| 38 | if (!key) |
| 39 | return false; |
| 40 | |
| 41 | DWORD error; |
| 42 | CRegKey keyBackup; |
| 43 | ::SetLastError(error = keyBackup.Open(HKEY_CURRENT_USER, DeletedPathBackup + _savePath, KEY_READ)); |
| 44 | if (!keyBackup) |
| 45 | return false; |
| 46 | |
| 47 | CRegKey newKey; |
| 48 | DWORD disp; |
| 49 | error = newKey.Create(key.Get(), _name, nullptr, 0, KEY_ALL_ACCESS, nullptr, &disp); |
| 50 | ::SetLastError(error); |
| 51 | if (error != ERROR_SUCCESS) |
| 52 | return false; |
| 53 | |
| 54 | ::SetLastError(error = ::RegCopyTree(keyBackup, nullptr, newKey)); |
| 55 | if (error != ERROR_SUCCESS) |
| 56 | return false; |
| 57 | |
| 58 | return InvokeCallback(false); |
| 59 | } |