Search code examples
inno-setuppascalscript

How to remove component size from application size in Inno Setup


I have multiples sub-exe components in my application setup.

In the custom type during component selection, the user is able to chose the components he wants to install (Google Chrome, Visual Studio ... etc) along the main app.

The size of those sub-exe wasn't showing so I explicitly written it down using ExtraDiskSpaceRequired: 2411724800.

But the problem is that, once the installation is complete, in Add or remove programs, the main application size combines (addition) all the components size selected and installed together even though each component is not related by any means to the main application.

*Temporary solution:
My solution was to simply not explicitly write the sub-exe size so it won't be added to the main application size when installed and selected since it's 0, but it then doesn't show the user component's size during the component selection which is a no no.

Is it possible to patch it so the main application only show his own size as well as being able to prompt the user the size of each components he wants to install in the component selection so he knows the storage needed to actually install those?

Reproducible example:

[Components]
Name: "NETFrameworkComponent"; Description: ".NET Framework 4.8"; Types:compact full custom; Flags: fixed; ExtraDiskSpaceRequired: 4718592000 
Name: "CodeMeterComponent"; Description: "Code Meter"; Types: full compact custom; Flags: fixed; ExtraDiskSpaceRequired: 108003328
Name: "VisualStudioComponent"; Description: "Visual Studio Installer"; Types: full; ExtraDiskSpaceRequired: 2411724800
Name: "GoogleChromeComponent"; Description: "Google Chrome"; Types: full; ExtraDiskSpaceRequired: 361758720


[Files] 
Source: "Dependencies\ndp48-x86-x64-allos-enu.exe"; DestDir: "{app}"; Flags: deleteafterinstall; AfterInstall: InstallNETFramework; Components: NETFrameworkComponent; Check: NETFrameworkIsNotInstalled
Source: "Dependencies\CodeMeterRuntime.exe"; DestDir: "{app}"; Flags: deleteafterinstall; AfterInstall: InstallCodeMeter; Components: CodeMeterComponent; Check: CodeMeterIsNotInstalled
Source: "Dependencies\ChromeStandaloneSetup64.exe"; DestDir: "{app}"; Flags: deleteafterinstall; AfterInstall: InstallGoogleChrome; Components: GoogleChromeComponent; Check: GoogleChromeIsNotInstalled
Source: "Dependencies\VisualStudioSetup.exe"; DestDir: "{app}"; Flags: deleteafterinstall; AfterInstall: InstallVisualStudio; Components: VisualStudioComponent; Check: VisualStudioIsNotInstalled

Thanks


Solution

  • There's imo no easy way, you have to either:

    • Give up on the built-in component size display and checking and implement that on your own. That's probably the correct way, but also more difficult to implement.
    • Or "correct" the installation size post-installation. E.g. from CurStepChanged(ssPostInstall) event. That's easier. See below.
    [Setup]
    AppId=My Program
    
    [Components]
    #define NETFrameworkComponentSize 4718592000
    Name: "NETFrameworkComponent"; Description: ".NET Framework 4.8"; \
        Types: compact full custom; Flags: fixed; \
        ExtraDiskSpaceRequired: {#NETFrameworkComponentSize}
    ...
    
    [Code]
    
    procedure CurStepChanged(CurStep: TSetupStep);
    var
      RootKey: Integer;
      AppId, UninstallKey: string;
      EstimatedSizeOrig, EstimatedSize: Cardinal;
    begin
      if CurStep = ssPostInstall then
      begin
        AppId := '{#SetupSetting("AppId")}';
        // Just in case there's a curly bracket in the AppId
        StringChange(AppId, '{{', '{');
        UninstallKey :=
          'Software\Microsoft\Windows\CurrentVersion\Uninstall\' + AppId + '_is1';
        if IsAdminInstallMode then RootKey := HKLM
          else RootKey := HKCU;
    
        if not RegQueryDWordValue(
                 RootKey, UninstallKey, 'EstimatedSize', EstimatedSize) then
        begin
          Log('Cannot read estimated size');
        end
          else
        begin
          Log(Format('Installation size is %d KB', [EstimatedSize]));
          EstimatedSizeOrig := EstimatedSize;
    
          if WizardIsComponentSelected('NETFrameworkComponent') then
          begin
            Log('Deducting .NET framework component size');
            EstimatedSize := EstimatedSize - ({#NETFrameworkComponentSize} / 1024);
          end;
    
          // Similarly for other components
          // ...
    
          if EstimatedSizeOrig <> EstimatedSize then
          begin
            Log(Format('Updating installation size from %d to %d KB', [
              EstimatedSizeOrig, EstimatedSize]));
            if not RegWriteDWordValue(
                     RootKey, UninstallKey, 'EstimatedSize', EstimatedSize) then
            begin
              Log('Failed to update installation size');
            end;
          end;
        end;
      end;
    end;
    

    Somewhat related: How to update application size shown in Windows Control panel/Settings app with size of additional downloads in Inno Setup