Archive: Patching a previous NSIS installed program?


Patching a previous NSIS installed program?
I wrote a little proggie, and used NSIS to install it.

Now, I'd like to be able to patch my program, and am wondering how to make NSIS make sure that the dir the user is trying to install the patch to - really is where the original proggie is installed.

I very much a n00b when it comes to NSIS, so I can't figure it out.

What I need:

Is there a way for NSIS to do a check for a certain file (in the dir that the user selects) and make sure that file is there (so that I'll know that my proggie is really installed there) and if its not, popup a error box, then kick user back to the DIR selection screen to try again??

Does that make sense?? :)

I'm sure its easy as hell, but I don't know NSIS well.

THX!


This comes straight from the docs:

Function .onVerifyInstDir
IfFileExists $INSTDIR\Winamp.exe PathGood
Abort
PathGood
FunctionEnd

Of course you can add your own messageboxes as needed.


thx!!

however, one problem - when the error box pops up, you have to hit it
twice to dismiss it. Not a serious bug, but annoying.

Here is my exact code:


Function .onVerifyInstDir
IfFileExists $INSTDIR\myfile.exe PathGood
MessageBox MB_OK "Sorry - this is not where myfile is, please try again."
PathGood:
FunctionEnd


You forgot to put the abort command in your example. This will keep the install button from being enabled.

There does seem to be a bug however. The same problem occured when I tested it. Sounds like onVerifyInstDir is being called twice.


Ok.

I wanted the Msg box to let users know that they had picked a wrong dir - else just having the install button not work might confuse them.

is there a way to have the msg box AND abort both called? would that fix the bug?


Function .onVerifyInstDir
IfFileExists $INSTDIR\myfile.exe PathGood
MessageBox MB_OK "Sorry - this is not where myfile is, please try again."
Abort
PathGood:
FunctionEnd

But the bug is still present (2 msgboxes). I will take a look and see why onVerifyInstDir is being called twice.


ok.

Thx for your help! And thanks for checking out this bug. Its not serious, but it is kinda annoying.


Use a structure from RegCode, see:

http://forums.winamp.com/showthread....threadid=70530

Summarized: use .onNextPage to trigger an alternative .onVerifyInstDir that will only be called when clicking "Install" and only once!

A little extract:


Function .onNextPage
StrCmp $R9 1 good1
StrCmp $R9 2 good2
IntOp $R9 $R9 + 1
Return
good1:
...

; alternative .onVerifyInstDir (only triggered when install is hit!)
good2:
IfFileExists "$INSTDIR" 0 PathGood
MessageBox MB_YESNO|MB_ICONQUESTION '"$INSTDIR" allready exists. Continue?$\r$\n$\r$\nIf you continue a backup of existing files will be created during install in:$\r$\n"$INSTDIR\Backup by App"' IDYes PathGood
Abort
PathGood:
IntOp $R9 $R9 + 1
FunctionEnd

Be sure to adapt the page numbers to your install!


Maybe that's a solution to the problem. It avoids the bug anyway!

Good luck, greetz, Hendri.

BTW,

Function .onInit
Strcpy $R9 0
FunctionEnd
should also be included of course, but you can find everything in a zip at the url above.

Good luck,
-Hn3.