Inno Setup: How to overwrite on install but not on change?

前端 未结 1 1247
我寻月下人不归
我寻月下人不归 2021-01-16 08:33

I know how to overwrite the files using this method

[Files]
Source: \"Project\\*\"; DestDir: \"{app}\"; Flags: ignoreversion recursesubdirs onlyifdoesntexi         


        
相关标签:
1条回答
  • 2021-01-16 09:04

    First, your code seems wrong. With the onlyifdoesntexist flag, the files are never overwritten, contrary to what you claim.


    Anyway, a solution is to create two [Files] entries, one that overwrites and one that does not. And use the Pascal scripting to pick the entry for a respective installation mode.

    [Files]
    Source: "Project\*"; DestDir: "{app}"; Flags: ... onlyifdoesntexist; ...; Check: IsUpgrade
    Source: "Project\*"; DestDir: "{app}"; Flags: ...; ...; Check: not IsUpgrade
    

    Example of IsUpgrade implementation:

    [Code]
    
    function IsUpgrade: Boolean;
    var
      S: string;
      InnoSetupReg: string;
      AppPathName: string;
    begin  
      { The ExpandConstant is here for Inno Script Studio, }
      { which generated AppId in a form of GUID. }
      { The leading { of the GUID has to be doubled in Inno Setup, }
      { and the ExpandConstant collapses that back to single {. }
      InnoSetupReg :=
        ExpandConstant(
          'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1');
      AppPathName := 'Inno Setup: App Path';
      Result :=
        RegQueryStringValue(HKLM, InnoSetupReg, AppPathName, S) or
        RegQueryStringValue(HKCU, InnoSetupReg, AppPathName, S);
    end;
    

    See also Pascal scripting: Check parameters.

    0 讨论(0)
提交回复
热议问题