forked from zodiacon/TotalRegistry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyKeyCommand.cpp
39 lines (31 loc) · 1019 Bytes
/
CopyKeyCommand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "pch.h"
#include "CopyKeyCommand.h"
#include "Registry.h"
CopyKeyCommand::CopyKeyCommand(PCWSTR path, PCWSTR name, PCWSTR targetPath, AppCommandCallback<CopyKeyCommand> cb)
: RegAppCommandBase(L"Paste Key " + CString(name), path, name, cb), _targetPath(targetPath) {
}
const CString& CopyKeyCommand::GetTargetPath() const {
return _targetPath;
}
bool CopyKeyCommand::Execute() {
auto key = Registry::OpenKey(_path + L"\\" + _name, KEY_READ);
if (!key)
return false;
auto targetKey = Registry::CreateKey(_targetPath + L"\\" + _name, KEY_ALL_ACCESS);
if (!targetKey)
return false;
if (!Registry::CopyKey(key.Get(), nullptr, targetKey))
return false;
return InvokeCallback(true);
}
bool CopyKeyCommand::Undo() {
auto key = Registry::OpenKey(_path, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | DELETE);
if (!key)
return false;
LSTATUS error;
if (ERROR_SUCCESS != (error = ::RegDeleteTree(key.Get(), _name))) {
::SetLastError(error);
return false;
}
return InvokeCallback(false);
}