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

I know how to overwrite the files using this method

[Files]
Source: "Project\*"; DestDir: "{app}"; \
    Flags: ignoreversion recursesubdirs onlyifdoesntexist; Permissions: everyone-full

But when I change the program using the Change option in 'Install Or Change Program' section I want to not overwrite the files.

I create the change option for my installer like this:

[setup]
AppModifyPath="{srcexe}" /modify=1

How do I do this?



Solution 1:[1]

First, your code seems wrong. With the onlyifdoesntexist flag, the files are never overwritten, contrary to what you claim. So for most purposes, simply using this flag will do.


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  
  InnoSetupReg :=
    'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1';
  { 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(InnoSetupReg);

  AppPathName := 'Inno Setup: App Path';
  Result :=
    RegQueryStringValue(HKLM, InnoSetupReg, AppPathName, S) or
    RegQueryStringValue(HKCU, InnoSetupReg, AppPathName, S);
end;

See also Pascal scripting: Check parameters.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1