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

bq8i3lrv  于 2023-11-21  发布在  Windows
关注(0)|答案(1)|浏览(223)

我目前正在做一个更新我们公司软件的程序。
我让用户选择安装程序的位置和CreateInputDirPage中的备份位置。
目前我正在为两个目录的选择创建一个掩码:

  1. SelectPathPage := CreateInputDirPage(PreviousPageId,
  2. 'Text 1',
  3. 'Text 2.',
  4. 'Text 3', False, 'New Folder');
  5. SelectPathPage.Add('Path to company program');
  6. SelectPathPage.Add('Path to backup folder');

字符串
然后我用现有文件验证第一个文件夹是否确实包含我们公司的程序。现在我想将第一个选择复制到备份文件夹中的一个新子文件夹中。
我从another question中找到了复制文件的示例代码:

  1. DirectoryCopy(SelectPathPage.Values[0], SelectPathPage.Values[1]);


这似乎与NextButtonClick函数一起工作。
如何在SelectPathPage掩码后的单独掩码上复制文件夹和文件夹内容,并在复制完成后使用“下一步”按钮。它应该类似于带有进度条的“安装”掩码。是否可以在Inno Setup中的自定义掩码中创建类似的内容?
Thanks in Advance

jk9hmnmh

jk9hmnmh1#

使用CreateOutputProgressPage创建进度页。
并从Copying hidden files in Inno Setup修改DirectoryCopy函数,以在页面上推进进度。
要计算总大小(设置进度条的最大值),代码需要Inno Setup中的GetDirSize函数获取包括子目录在内的目录大小。

  1. [Code]
  2. const
  3. ProgressRatio = 1024;
  4. procedure DirectoryCopyWithProgress(
  5. SourcePath, DestPath: string; ProgressPage: TOutputProgressWizardPage);
  6. var
  7. FindRec: TFindRec;
  8. SourceFilePath: string;
  9. DestFilePath: string;
  10. Size: Int64;
  11. begin
  12. if FindFirst(SourcePath + '\*', FindRec) then
  13. begin
  14. try
  15. repeat
  16. if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
  17. begin
  18. SourceFilePath := SourcePath + '\' + FindRec.Name;
  19. DestFilePath := DestPath + '\' + FindRec.Name;
  20. ProgressPage.SetText(SourceFilePath, DestFilePath);
  21. if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
  22. begin
  23. Size := Int64(FindRec.SizeHigh) shl 32 + FindRec.SizeLow;
  24. if FileCopy(SourceFilePath, DestFilePath, False) then
  25. begin
  26. Log(Format('Copied %s to %s with %s bytes', [
  27. SourceFilePath, DestFilePath, IntToStr(Size)]));
  28. end
  29. else
  30. begin
  31. Log(Format('Failed to copy %s to %s', [
  32. SourceFilePath, DestFilePath]));
  33. end;
  34. end
  35. else
  36. begin
  37. Size := 0;
  38. if DirExists(DestFilePath) or CreateDir(DestFilePath) then
  39. begin
  40. Log(Format('Created %s', [DestFilePath]));
  41. DirectoryCopyWithProgress(
  42. SourceFilePath, DestFilePath, ProgressPage);
  43. end
  44. else
  45. begin
  46. Log(Format('Failed to create %s', [DestFilePath]));
  47. end;
  48. end;
  49. Size := Size / ProgressRatio;
  50. ProgressPage.SetProgress(
  51. ProgressPage.ProgressBar.Position + Longint(Size),
  52. ProgressPage.ProgressBar.Max);
  53. end;
  54. until not FindNext(FindRec);
  55. finally
  56. FindClose(FindRec);
  57. end;
  58. end
  59. else
  60. begin
  61. Log(Format('Failed to list %s', [SourcePath]));
  62. end;
  63. end;
  64. function SelectPathPageNextButtonClick(Sender: TWizardPage): Boolean;
  65. var
  66. SourcePath: string;
  67. DestPath: string;
  68. ProgressPage: TOutputProgressWizardPage;
  69. TotalSize: Longint;
  70. begin
  71. ProgressPage := CreateOutputProgressPage('Copying files...', '');
  72. SourcePath := TInputDirWizardPage(Sender).Values[0];
  73. DestPath := TInputDirWizardPage(Sender).Values[1];
  74. TotalSize := GetDirSize(SourcePath) / ProgressRatio;
  75. Log(Format('Total size is %s', [IntToStr(TotalSize)]));
  76. ProgressPage.SetProgress(0, TotalSize);
  77. ProgressPage.Show;
  78. try
  79. DirectoryCopyWithProgress(SourcePath, DestPath, ProgressPage);
  80. finally
  81. ProgressPage.Hide;
  82. ProgressPage.Free;
  83. end;
  84. Result := True;
  85. end;
  86. procedure InitializeWizard();
  87. var
  88. SelectPathPage: TInputDirWizardPage;
  89. begin
  90. SelectPathPage :=
  91. CreateInputDirPage(
  92. wpSelectDir, 'Text 1', 'Text 2.', 'Text 3', False, 'New Folder');
  93. SelectPathPage.Add('Path to company program');
  94. SelectPathPage.Add('Path to backup folder');
  95. SelectPathPage.OnNextButtonClick := @SelectPathPageNextButtonClick;
  96. end;

字符串


的数据


展开查看全部

相关问题