How to Correctly show component sizes in inno component page

こ雲淡風輕ζ 提交于 2019-12-23 07:05:50

问题


I am not getting the correct memory sizes of all the component selected in the component page.

Please give me a solution how the total memory selected for all the components should be correct?

The memory size is displayed on the label at the bottom of the page.


回答1:


If in the [files] section check flags are used, not all flags can be processed by Inno-setup. Especially if you created check flags which rely on the [code] section.

In my setup a created an array of all files. In this record I have a selected flag, and a filesizeflag. An example looks like:

 files[index].selected := // true or false depending on your wizard flow 
 files[index].filesize := {#filesize(..)} // on the .. the source file, including path

Before calling the dir page wizard page you go through a procedure which counts the file sizes and adds them to the file size already counted. Yhe file size already counted is for every setup different, depending how much code you have in the code section is my experience.

My example code for counting the space is a good start (I hope)

Procedure GetSetUsedDiskSpace();
// This procedure counts an displays the used disk space
{}
var
 TempS, SearchString, NumberString, diskspace : String;
 Position, p2                                 : Integer;
 Tot_disk, TempSpace                          : Longint;
 {}
 begin
  TempS        := InitDiskSpace; // wizardform.DiskSpaceLabel.Caption;
  SearchString := 'MB';
  Position     := pos(SearchString, TempS);
  NumberString := copy(TempS, 1, Position-2); // exclusive the space before the MB
  p2           := 0;
  repeat // find the space before the number
   p2           := pos(' ', NumberString);
   NumberString := copy(NumberString, p2 + 1, length(NumberString) - p2);
  until p2 = 0;
  p2 := pos(',', NumberString);
  if (p2 = 0) then
   begin // Some languages use the period as a decimal separator
    p2 := pos('.', NumberString);
   end;
  if (p2 > 0) then
   begin
    NumberString := copy(Numberstring, 1, p2-1) + copy(NumberString, p2+1, 1);
    // If there is a need to more shifting we add some code
   end;
  TempSpace := StrToInt(NumberString);
  TempSpace := TempSpace * 1024 * 1024; // Conversion to bytes
  TempSpace := TempSpace / 10;          // We replaced the decimal separator once
  CountSpace;                           // Count the space for our selection
  Tot_disk      := UsedDiskSpace + TempSpace; // The total in bytes
  UsedDiskSpace := Tot_disk;                  // We need this for the control panel
  Tot_disk      := Tot_disk / 1024;           // The total in kilobytes
  Tot_disk      := Tot_disk / 1024;           // The total in MB
  diskspace     := IntToStr(Tot_disk);
  TempS         := SetupMessage(msgDiskSpaceMBLabel);
  StringChangeEx(TempS, '[mb]', diskspace, True);
  WizardForm.DiskSpaceLabel.Caption := TempS;
 end;


来源:https://stackoverflow.com/questions/21694654/how-to-correctly-show-component-sizes-in-inno-component-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!