Inno Setup 调用或复制本机 Windows 文件复制操作
Inno Setup invoke or replicate native Windows file copy operation
我知道 FileCopy
函数可用于复制 [Code]
部分中的文件,这对大多数用途都适用。但是,有什么方法可以调用本机 Windows 文件复制操作,以便显示标准 Windows 文件复制对话框以及进度、剩余时间等(即与 Ctrl+C
相同) , 后跟 Ctrl+V
), 这也将允许用户在过程中取消或暂停复制操作?或者,更好的是,有没有办法直接在 [Code]
部分中复制类似的功能?
将SHFileOperation
与FO_COPY
一起使用:
type
TSHFileOpStruct = record
hwnd: HWND;
wFunc: UINT;
pFrom: string;
pTo: string;
fFlags: Word;
fAnyOperationsAborted: BOOL;
hNameMappings: HWND;
lpszProgressTitle: string;
end;
const
FO_COPY = [=10=]02;
FOF_NOCONFIRMATION = [=10=]10;
function SHFileOperation(lpFileOp: TSHFileOpStruct): Integer;
external 'SHFileOperationW@shell32.dll stdcall';
procedure ShellCopyFile;
var
FromPath: string;
ToPath: string;
FileOp: TSHFileOpStruct;
begin
FromPath :=
ExpandConstant('{src}\data1.dat') + #0 +
ExpandConstant('{src}\data2.dat') + #0;
ToPath := ExpandConstant('{app}') + #0;
FileOp.hwnd := WizardForm.Handle;
FileOp.wFunc := FO_COPY;
FileOp.pFrom := FromPath;
FileOp.pTo := ToPath;
FileOp.fFlags := FOF_NOCONFIRMATION;
if SHFileOperation(FileOp) <> 0 then
begin
MsgBox('Copying failed.', mbError, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ShellCopyFile;
end;
end;
该代码适用于 Inno Setup 的 Unicode 版本(Inno Setup 6 的唯一版本)。
我知道 FileCopy
函数可用于复制 [Code]
部分中的文件,这对大多数用途都适用。但是,有什么方法可以调用本机 Windows 文件复制操作,以便显示标准 Windows 文件复制对话框以及进度、剩余时间等(即与 Ctrl+C
相同) , 后跟 Ctrl+V
), 这也将允许用户在过程中取消或暂停复制操作?或者,更好的是,有没有办法直接在 [Code]
部分中复制类似的功能?
将SHFileOperation
与FO_COPY
一起使用:
type
TSHFileOpStruct = record
hwnd: HWND;
wFunc: UINT;
pFrom: string;
pTo: string;
fFlags: Word;
fAnyOperationsAborted: BOOL;
hNameMappings: HWND;
lpszProgressTitle: string;
end;
const
FO_COPY = [=10=]02;
FOF_NOCONFIRMATION = [=10=]10;
function SHFileOperation(lpFileOp: TSHFileOpStruct): Integer;
external 'SHFileOperationW@shell32.dll stdcall';
procedure ShellCopyFile;
var
FromPath: string;
ToPath: string;
FileOp: TSHFileOpStruct;
begin
FromPath :=
ExpandConstant('{src}\data1.dat') + #0 +
ExpandConstant('{src}\data2.dat') + #0;
ToPath := ExpandConstant('{app}') + #0;
FileOp.hwnd := WizardForm.Handle;
FileOp.wFunc := FO_COPY;
FileOp.pFrom := FromPath;
FileOp.pTo := ToPath;
FileOp.fFlags := FOF_NOCONFIRMATION;
if SHFileOperation(FileOp) <> 0 then
begin
MsgBox('Copying failed.', mbError, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ShellCopyFile;
end;
end;
该代码适用于 Inno Setup 的 Unicode 版本(Inno Setup 6 的唯一版本)。