我目前正在开发一个用于更新我们公司软件的程序。
我让用户在“ 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');
然后,如果第一个Folder indead保存了我们公司的程序,我将使用现有文件进行验证。现在,我要将第一个选择复制到备份文件夹中的新子文件夹中。
我从另一个复制文件的问题中找到了以下示例代码:DirectoryCopy(SelectPathPage.Values[0], SelectPathPage.Values[1]);
似乎可以使用“ NextButtonClick”功能。
在带有进度条的“ SelectPathPage” -Mask之后,如何在单独的蒙版上复制文件夹和文件夹的内容,并在复制完成后使下一个按钮可用。它应类似于带有进度条的“安装”面具。甚至可以在Inno Setup的自定义蒙版中创建类似的内容?
提前致谢
使用CreateOutputProgressPage
创建进度页面。
并修改“在Inno设置中复制隐藏文件”中的DirectoryCopy
功能以使页面上的进度前进。
要计算总大小(以设置进度条的最大值),Inno Setup中的代码需要GetDirSize
功能获取包含子目录的目录大小。
[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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句