if SetLastHRes SHGetDesktopFolder shfDesktop NOERROR and SetLastHRes S

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
if (SetLastHRes(SHGetDesktopFolder(shfDesktop)) = NOERROR) and
(SetLastHRes(SHILCreateFromPath(PChar(Path), iidl, attrs)) = S_OK)
then try
if (SetLastHRes(shfDesktop.BindToObject(iidl, nil, IID_IShellFolder, shfSelected)) = S_OK) and
(SetLastHRes(shfSelected.CreateViewObject(Handle, IID_IContextMenu, icm)) = S_OK)
then begin
menu := CreatePopupMenu;
if menu = 0
then RaiseLastOsError
else try
if HResultSeverity(SetLastHRes(icm.QueryContextMenu(menu, 0, 0, 0, 0))) = SEVERITY_SUCCESS
then begin
hDir := CreateFile(PChar(Path), FILE_LIST_DIRECTORY, FILE_SHARE_WRITE or FILE_SHARE_READ,
nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_OVERLAPPED, 0);
if hDir = INVALID_HANDLE_VALUE
then RaiseLastOsError
else try
ZeroMemory(@Overlapped, SizeOf(Overlapped));
Overlapped.hEvent := CreateEvent(nil, False, False, nil);
if Overlapped.hEvent = 0
then RaiseLastOsError
else try
GetMem(pBuf, BufSize);
try
if ReadDirectoryChanges(hDir, pBuf, BufSize, False, FILE_NOTIFY_CHANGE_DIR_NAME,
nil, @Overlapped, nil)
then try
ZeroMemory(@cmici, SizeOf(cmici));
cmici.cbSize := SizeOf(cmici);
cmici.lpVerb := CMDSTR_NEWFOLDERA;
cmici.fMask := CMIC_MASK_ASYNCOK;
SetLastHRes(icm.InvokeCommand(cmici));
if LastHRes = NOERROR
then if GetOverlappedResult(hDir, Overlapped, BytesTransferred, True)
then BeginRenameDir(pBuf)
else RaiseLastOsError
else RaiseLastHRes;
finally
CancelIo(hDir)
end
else RaiseLastOsError;
finally
FreeMem(pBuf, BufSize);
end;
finally
CloseHandle(Overlapped.hEvent)
end;
finally
CloseHandle(hDir)
end;
end
else RaiseLastHRes;
finally
DestroyMenu(menu)
end;
end
else RaiseLastHRes;
finally
CoTaskMemFree(iidl)
end
else RaiseLastHRes;