我目前正在开发一个更新我们公司软件的程序,我让用户在 "CreateInputDirPage "中选择安装程序的位置和备份位置。
我让用户在 "CreateInputDirPage "中选择安装程序的位置和备份位置。
目前,我正在为两个目录的选择创建一个掩码,然后用现有的文件验证第一个文件夹是否存放了我们公司的程序。
SelectPathPage := CreateInputDirPage(PreviousPageId,
'Text 1',
'Text 2.',
'Text 3', False, 'New Folder');
SelectPathPage.Add('Path to company program');
SelectPathPage.Add('Path to backup folder');
现在我想把第一个选择复制到备份文件夹的一个新的子文件夹中。
我发现这个示例代码来自 另一个问题 用于复制文件。DirectoryCopy(SelectPathPage.Values[0], SelectPathPage.Values[1]);
这似乎与 "NextButtonClick "功能有关。
我怎样才能在 "SelectPathPage"-Mask之后的一个单独的掩码上复制文件夹和文件夹的内容,并带有一个进度条,当复制完成后,下一个按钮就可以使用了,这应该类似于 "Install"-Mask的进度条。
先谢谢你
使用 CreateOutputProgressPage
来创建进度页。
并修改 DirectoryCopy
功能从 在Inno Setup中复制隐藏文件 来推进页面上的进度。
要计算总的大小(设置进度条的最大值),代码中需要用到 GetDirSize
功能从 Inno Setup获取包括子目录在内的目录大小。.
[Code]
const
ProgressRatio = 1024;
procedure DirectoryCopyWithProgress(
SourcePath, DestPath: string; ProgressPage: TOutputProgressWizardPage);
var
FindRec: TFindRec;
SourceFilePath: string;
DestFilePath: string;
Size: Int64;
begin
if FindFirst(SourcePath + '\*', FindRec) then
begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
SourceFilePath := SourcePath + '\' + FindRec.Name;
DestFilePath := DestPath + '\' + FindRec.Name;
ProgressPage.SetText(SourceFilePath, DestFilePath);
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
Size := Int64(FindRec.SizeHigh) shl 32 + FindRec.SizeLow;
if FileCopy(SourceFilePath, DestFilePath, False) then
begin
Log(Format('Copied %s to %s with %s bytes', [
SourceFilePath, DestFilePath, IntToStr(Size)]));
end
else
begin
Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath]));
end;
end
else
begin
Size := 0;
if DirExists(DestFilePath) or CreateDir(DestFilePath) then
begin
Log(Format('Created %s', [DestFilePath]));
DirectoryCopyWithProgress(SourceFilePath, DestFilePath, ProgressPage);
end
else
begin
Log(Format('Failed to create %s', [DestFilePath]));
end;
end;
Size := Size / ProgressRatio;
ProgressPage.SetProgress(
ProgressPage.ProgressBar.Position + Longint(Size),
ProgressPage.ProgressBar.Max);
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end
else
begin
Log(Format('Failed to list %s', [SourcePath]));
end;
end;
function SelectPathPageNextButtonClick(Sender: TWizardPage): Boolean;
var
SourcePath: string;
DestPath: string;
ProgressPage: TOutputProgressWizardPage;
TotalSize: Longint;
begin
ProgressPage := CreateOutputProgressPage('Copying files...', '');
SourcePath := TInputDirWizardPage(Sender).Values[0];
DestPath := TInputDirWizardPage(Sender).Values[1];
TotalSize := GetDirSize(SourcePath) / ProgressRatio;
Log(Format('Total size is %s', [IntToStr(TotalSize)]));
ProgressPage.SetProgress(0, TotalSize);
ProgressPage.Show;
try
DirectoryCopyWithProgress(SourcePath, DestPath, ProgressPage);
finally
ProgressPage.Hide;
ProgressPage.Free;
end;
Result := True;
end;
procedure InitializeWizard();
var
SelectPathPage: TInputDirWizardPage;
begin
SelectPathPage :=
CreateInputDirPage(wpSelectDir, 'Text 1', 'Text 2.', 'Text 3', False, 'New Folder');
SelectPathPage.Add('Path to company program');
SelectPathPage.Add('Path to backup folder');
SelectPathPage.OnNextButtonClick := @SelectPathPageNextButtonClick;
end;