Archive: Need to set overwrite mode of some files on the fly?


Need to set overwrite mode of some files on the fly?
Hello, I need to set overwrite mode of some files on the fly, I thought it can be possible by setting SetOverwrite command but it seems it can't be altered by evaluating some variable in a section...

I inserted special page that allows user to choose between
1)overwriting all files
2) overwriting files only if they are newer

Then I checked the selection and wnat to apply the overwrite mode but it didn't work... Any idea? :)

I used this code:

Section "Program files (required)"

StrCmp $CX_DATA_OVER_MODE "0" _yes_overwrite _no_overwrite

_yes_overwrite:
DetailPrint "SetOverwrite on."
SetOverwrite on ;the script runs here but SetOverwrite does not work of course ...
Goto _done_overwrite

_no_overwrite:
DetailPrint "SetOverwrite ifnewer."
SetOverwrite ifnewer ;the script runs here but SetOverwrite does not work of course ...

Goto _done_overwrite
_done_overwrite:

SetOutPath $CX_DATA_DIR
File Redistribute\*.*
...
...


Hi :)

To solve your problem I think you have to remove the instructions "SetOutPath" and "File" from the label "_done_overwrite", and to put them both in "_yes_overwrite" and "_no_overwrite" :


Section "Program files (required)"
StrCmp "$CX_DATA_OVER_MODE" "0" _yes_overwrite _no_overwrite

_yes_overwrite:
DetailPrint "SetOverwrite on."
SetOverwrite on
SetOutPath "$CX_DATA_DIR"
File Redistribute\*.*

Goto _done_overwrite

_no_overwrite:
DetailPrint "SetOverwrite ifnewer."
SetOverwrite ifnewer
SetOutPath "$CX_DATA_DIR"
File Redistribute\*.*

Goto _done_overwrite

_done_overwrite:
SectionEnd


This should work, let me know if it doesn't... :D

evilO/Olive

PS: and welcome to the forums... ;)


It works
It works, thanks :) However, I have to duplicate the "File" code several times since I have to use that in several sections ...


If the datablock optimizer is on (which is the default) that should be no problem. You also use a function or call a section from the script.


It works, cool :)

Err, but I'm not too sure to understand that:

However, I have to duplicate the "File" code several times since I have to use that in several sections
The "File" instruction will not put your files twice in the installer if that is the problem...



BTW just a little modification (to avoid to "duplicate" one more line):


Section "Program files (required)"
SetOutPath "$CX_DATA_DIR"

StrCmp "$CX_DATA_OVER_MODE" "0" _yes_overwrite _no_overwrite

_yes_overwrite:
DetailPrint "SetOverwrite on."
SetOverwrite on
File Redistribute\*.*
Goto _done_overwrite

_no_overwrite:
DetailPrint "SetOverwrite ifnewer."
SetOverwrite ifnewer
File Redistribute\*.*
Goto _done_overwrite

_done_overwrite:
SectionEnd



evilO/Olive

[QUOTEThe "File" instruction will not put your files twice in the installer if that is the problem...
[/QUOTE]

I just tried to mention that I had to duplicate all the "file related" lines in the installer so there is increased possibility of errors - I change something in the future I will have to modify it on two places in the script...

Anyway, thanks :)


Why not put it all in a macro? Then you won't have to enter it twice and you can even let the macro call the same File command for every file extraction (see the UpgradeDLL macro).


Macro :eek: Well - I haven't used macros in NSIS yet, but it seems worth to try :) Thanks - I'll do that.