Reputation: 11465
I am trying to dynamically set the SetOverwrite
state for choosing between unconditionally replace some files or replace them only if my setup is providing some newer versions.
I have tried with logiclib
${if} $isReinstall = 1
SetOverwrite on
${debug} "SetOverwrite on (overwrite)"
${else}
SetOverwrite ifnewer
${debug} "SetOverwrite ifnewer"
${endif}
File "foo"
And with classic IntCmp
IntCmp $isReinstall 1 0 +3 +3
SetOverwrite on
goto +2
SetOverwrite ifnewer
File "foo"
But nothing seem to work: if my file foo
is already present on disk, it is always skipped. My $isReinstall
being 1
or not.
It seems that the last SetOverwrite
statement in the stream of instructions (regardless of the logiclib macros) overloads the previous one.
If I add another SetOverwrite on
just before the File
directive, the file is correctly replaced.
Is my analysis correct? How could I decide at runtime if a file can or cannot be replaced?
Upvotes: 2
Views: 1600
Reputation: 3575
Try using this code instead:
${If} $isReinstall = 1
SetOverwrite on
File "foo"
${Else}
SetOverwrite ifnewer
File "foo"
${EndIf}
The important point to note is that the File command appears within the If block and this needs to be done because the SetOverwrite command affects every line below it. See this piece of the NSIS documentation for a full explanation.
Upvotes: 3