-
Notifications
You must be signed in to change notification settings - Fork 14
/
ShellFileOperations.iss
108 lines (85 loc) · 2.86 KB
/
ShellFileOperations.iss
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
[Code]
type
TSHFileOpStruct = record
hwnd: HWND;
wFunc: UINT;
pFrom: String;
pTo: String;
fFlags: Word;
fAnyOperationsAborted: BOOL;
hNameMappings: HWND;
lpszProgressTitle: String;
end;
const
FO_MOVE = $0001;
FO_COPY = $0002;
FO_RENAME = $0004;
FOF_NULL = $0000;
FOF_MULTIDESTFILES = $0001;
FOF_NOCONFIRMATION = $0010;
FOF_NOCONFIRMMKDIR = $0200;
function SHFileOperation(lpFileOp: TSHFileOpStruct): Integer;
external 'SHFileOperationW@shell32.dll stdcall';
function ShellFileOperation(const Source: String; const Destination: String; const Operation: uint; const extraFlags: uint): Boolean;
var
FileOp: TSHFileOpStruct;
OperationResult: Integer;
begin
FileOp.hwnd := WizardForm.Handle;
FileOp.wFunc := Operation;
FileOp.pFrom := PAnsiChar(Source);
FileOp.pTo := PAnsiChar(Destination);
FileOp.fFlags := FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR or extraFlags;
OperationResult := SHFileOperation(FileOp)
if OperationResult <> 0 then
begin
Log('Error! Operation gave a bad result! ' + IntToStr(OperationResult))
Result := false
exit;
end;
result := true
end;
function ShellRename(const Source: String; const Destination: String): Boolean;
begin
result := ShellFileOperation(Source + #0#0, Destination + #0#0, FO_RENAME, FOF_NULL)
end;
function ShellCopy(const Source: String; const Destination: String): Boolean;
begin
result := ShellFileOperation(Source + #0#0, Destination + #0#0, FO_COPY, FOF_NULL)
end;
function ShellMove(const Source: String; const Destination: String): Boolean;
begin
result := ShellFileOperation(Source + #0#0, Destination + #0#0, FO_MOVE, FOF_NULL)
end;
function ShellCopyMultipleDest(const Source: array of string; const Destination: array of string): Boolean;
var
SourceString, DestinationString: string;
I: Integer;
begin
Log('Will copy the following files: ')
for i := 0 to GetArrayLength(Source) - 1 do
begin
Log(Source[i] + ' ---> ' + Destination[i])
SourceString := SourceString + Source[i] + #0
DestinationString := DestinationString + Destination[i] + #0
end;
SourceString := SourceString + #0
DestinationString := DestinationString + #0
result := ShellFileOperation(SourceString, DestinationString, FO_COPY, FOF_MULTIDESTFILES)
end;
function ShellMoveMultiple(const Source: array of string; const Destination: String): Boolean;
var
SourceString: string;
I: Integer;
begin
Log('Will move the following files: ')
for i := 0 to GetArrayLength(Source) - 1 do
begin
Log(Source[i])
SourceString := SourceString + Source[i] + #0
end;
SourceString := SourceString + #0
Log('To: ' + Destination)
result := ShellFileOperation(SourceString, AddBackSlash(Destination) + #0#0, FO_MOVE, FOF_NULL)
end;
[/Code]