Contents
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Search
Login
Navigation
Home Source Code Inno Setup Scan a disk path or an entire disk with Inno Setup - Progress page
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Navigation
Home Source Code Inno Setup Scan a disk path or an entire disk with Inno Setup - Progress page
Who Is Online?
We have 34 guests online
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Scan a disk path or an entire disk with Inno Setup - Progress page E-mail
User Rating: / 0
PoorBest 
Source Code - Inno Setup
Written by Thomas   
Monday, 01 June 2009 19:30
Article Index
Scan a disk path or an entire disk with Inno Setup
Progress page
Cancel button
Example script
All Pages

 

In order to show at least something in Inno Setup's wizard, a progress page can be inserted. Reading and processing a directory tree is a serial operation, meaning that it's finishing time can't be predicted in advance. This is why I set the progress bar up to change its status every 1000 files or folders, and when it has hit the right side of the bar it rolls over to the left again.

  1. var
  2. ProgressPage:    TOutputProgressWizardPage;
  3. ProgressValue:    Integer;
  4. ArrayLen:        LongInt;
  5.  
  6. procedure ProcessDirectory (RootDir: String; Progress: Boolean);
  7. var
  8. NewRoot:        String;
  9. FilePath:        String;
  10. FindRec:        TFindRec;
  11. begin
  12. NewRoot := AddBackSlash (RootDir);
  13. if FindFirst (NewRoot + '*', FindRec) then
  14. begin
  15. try
  16. repeat
  17. if (FindRec.Name <> '.') AND (FindRec.Name <> '..') then
  18. begin
  19. FilePath := NewRoot + FindRec.Name;
  20. if FindRec.Attributes AND FILE_ATTRIBUTE_DIRECTORY > 0 then
  21. ProcessDirectory (FilePath, Progress)
  22. else
  23. begin
  24. // Start action -->
  25. // .
  26. // Add your custom code here.
  27. // FilePath contains the file name
  28. // including its full path name.
  29. // Try not to call a function for every file
  30. // as this could take a very long time.
  31. // .
  32. // <-- End action.
  33. ArrayLen := ArrayLen + 1;
  34. if (Progress) then
  35. begin
  36. if (ArrayLen mod 1000) = (ArrayLen / 1000) then
  37. begin
  38. ProgressValue := ProgressValue + 1;
  39. if ProgressValue = 100 then
  40. ProgressValue := 0;
  41. ProgressPage.SetProgress (ProgressValue, 100);
  42. end;
  43. end;
  44. end;
  45. end;
  46. until NOT FindNext (FindRec);
  47. finally
  48. FindClose(FindRec);
  49. end;
  50. end;
  51. end;
  52.  
  53. procedure CurStepChanged (CurStep: TSetupStep);
  54. var
  55. lI:            LongInt;
  56. Dir:        String;
  57. begin
  58. if (CurStep = ssInstall) then
  59. begin
  60. // The folder to scan.
  61. Dir := 'C:\';
  62. // The progress page.
  63. ProgressPage := CreateOutputProgressPage (CustomMessage ('ProgressTitle'),
  64. CustomMessage ('ProgressCaption'));
  65. ProgressPage.SetText (CustomMessage ('ProgressText'), Dir);
  66. ProgressPage.SetProgress(0, 0);
  67. ProgressPage.Show;
  68. // Scan the folder.
  69. ProcessDirectory (Dir, TRUE);
  70. // Hide the progress page.
  71. try
  72. finally
  73. ProgressPage.Hide;
  74. end;
  75. end;
  76. end;
  77.  

With the progress bar moving, the installation program gained a nice touch towards the standards of what people expect from a fashionate installer. Saying that, this is however only on the surface. There is no chance for the user to interrupt the disk scan unless they use the Taskmanager and kill the setup process.

 



Last Updated on Thursday, 15 October 2009 15:26
 
You need to login or register to post comments.
Discuss this item on the forums. (0 posts)

No Comments.