Inno Setup invoke or replicate native Windows file copy operation

我怕爱的太早我们不能终老 提交于 2019-12-08 18:31:26

Use SHFileOperation with 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            = $0002;
  FOF_NOCONFIRMATION = $0010;

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;

The code is for Unicode version of Inno Setup (the only version as of Inno Setup 6).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!