gpt4 book ai didi

windows - Inno Setup - 在自定义页面上使用进度条复制文件

转载 作者:行者123 更新时间:2023-12-03 11:11:52 27 4
gpt4 key购买 nike

我目前正在开发一个更新我们公司软件的程序。

我让用户在“CreateInputDirPage”中选择安装程序的位置和备份位置

目前我正在为两个目录的选择创建一个掩码:

SelectPathPage := CreateInputDirPage(PreviousPageId,
'文本1',
'文本 2.',
'文本 3', False, '新文件夹');
SelectPathPage.Add('公司程序路径');
SelectPathPage.Add('备份文件夹路径');

然后,如果第一个文件夹确实包含我们公司的程序,我将使用现有文件进行验证。现在我想将第一个选择复制到备份文件夹中的新子文件夹。

我从 another question 中找到了这个示例代码用于复制文件:DirectoryCopy(SelectPathPage.Values[0], SelectPathPage.Values[1]);

这似乎与“NextButtonClick”功能一起使用。

如何在带有进度条的“SelectPathPage”掩码之后将文件夹和文件夹的内容复制到单独的掩码上,并在复制完成后使下一个按钮可用。它应该类似于带有进度条的“安装”-Mask。甚至可以在 Inno Setup 的自定义掩码中创建这样的东西吗?

提前致谢

最佳答案

使用CreateOutputProgressPage创建进度页面。

并修改Copying hidden files in Inno Setup中的DirectoryCopy函数以推进页面上的进度。

要计算总大小(设置进度条的最大值),代码需要来自 Inno Setup get directory size including subdirectoriesGetDirSize 函数.

[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;

enter image description here

enter image description here

关于windows - Inno Setup - 在自定义页面上使用进度条复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62299905/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com