wacki
22nd July 2008 23:41 UTC
Overwrite protection - Making sure install doesn't accidently erase anything
I'm trying to include a safeguard in the installer that will prevent a user from accidentally erasing something. Is there any way to provide a pop up window that says:
"File XXXXX already exists, would you like to overwite?
[Yes] [Yes to All] [No]"
LoRd_MuldeR
22nd July 2008 23:51 UTC
Check for the existence of the file with "IfFileExists" and display a warning if it's already there. Depending on the user's decision you can either skip or overwrite...
LoRd_MuldeR
23rd July 2008 00:17 UTC
Here is a macro:
!define FileOverwriteCheck "!insertmacro _FileOverwriteCheck"
!macro _FileOverwriteCheck target source
IfFileExists "$OUTDIR\${target}" 0 +3
MessageBox MB_YESNO 'Overwrite file: "$OUTDIR\${target}" ???' IDYES +2
Goto +2
File "/oname=${target}" "${source}"
!macroend
Section
SetOuPath $INSTDIR
${FileOverwriteCheck} "File.foo" "C:\Data\File.foo"
...
SectionEnd
wacki
23rd July 2008 20:44 UTC
LoRd_MuldeR,
Thanks for the help. The macro works fine. Is there a [B}file /r[/B] version of it? Something that will allow me to copy over an entire directory and warn me of popups?
LoRd_MuldeR
23rd July 2008 20:51 UTC
The /r switch will include all files from all subdirectories. Since you don't know which files will be extracted in advance, that won't work with the proposed macro...
wacki
28th July 2008 21:14 UTC
Does anyone here have a macro that can employ the "Yes to all" feature when copying/overwriting files? I would have to force someone to click "yes" a 100 times when doing a re-install.
Animaether
29th July 2008 02:02 UTC
messageboxes have, at most "yes, no, cancel" and "abort, retry, ignore" as advanced options.. so a 'yes to all' or 'no to all' wouldn't be possible with a messagebox.
You could pop up two messageboxes.. one after the first that asks if the user wants the just-chosen action to be applied to any further such warnings.
Or you can try working with the MessageBox plugin:
http://nsis.sourceforge.net/MessageBox_plug-in
It allows you to use 4 buttons, customize the text on them, and get the results. That way you can can certainly have [Yes] [No] [Yes to all] [No to all], or whatever tickles your fancy.