qforce3
16th September 2008 15:44 UTC
How to replace old program version with new one?
Hello everybody,
I'm new to NSIS and creating installers went very well so far for me. However, what I'm wondering about is this: What do you do if an older version of your program is already installed?
- Deinstall it first, then install the new version?
- Overwrite everything and hope there's no garbage left?
- Manually maintain a list of file 'differences' between each version and take that into account during installation?
Some more questions:
- What if you want to transfer the settings of the old version to the new one?
- What if the user tries to install an older version over a newer one?
Thanks for any help you guys can give me!
MSG
16th September 2008 15:56 UTC
When my installer finds an older version, it goes into upgrade mode: It overwrites only those files that I know have changed since any previous version. I'm the release engineer, I know which files have to be overwritten, so I just put those File commands in a separate section. All other File commands (for all unchanged files) are only executed in Reinstall and Newinstall modes.
If the installer finds a newer version of my project installed, it issues a warning "you're trying to install an older version than [previously installed version]". If the user chooses to continue, I once again do the all-knowing trick: I design the source code so that it can handle this situation. Any files I know were different (or not present yet, or are missing now) I extract. Any other files I leave alone.
As for overwriting settings, that's never been a problem for my projects.
qforce3
16th September 2008 16:32 UTC
So if I understand correctly, that means, if you have the following versions:
- noob-app-1.0
- noob-app-1.1
- noob-app-1.2
- noob-app-1.3 <= current version
then you would manually maintain a list of differences between 1.0 and 1.3, 1.1 and 1.3, and 1.2 and 1.3, right?
Huh... sounds very laborious to me, especially if there are many files to keep track of. Isn't there any way to automate this task?
Comperio
16th September 2008 19:59 UTC
I think the easiest way would be to call the prior version's uninstall program (maybe in silent mode) before installing the new version. This would ensure that you replaced all the files and that any unnecessary (old) files were cleaned up.
If the app in question follows Microsoft best practices, then the settings should be separate from the application (like under the user's %AppData% folder), so re-installing shouldn't affect those. But if not, then you'll need to first save the old settings somewhere before you delete them during the uninstall.
If you want to prevent installing an older version on top of a new version, you'll need to do a version check right off the bat (in .OnInit, for example).
setdosa
17th September 2008 17:21 UTC
Hi, I am also trying the same way but I am not getting the required setup. can you please help me on how I can do this? say after the .OnInit what should I use to make the installer do a self verification of its previopus version???
Comperio
17th September 2008 18:41 UTC
You'd need to get the version from somewhere--like maybe the registry or from the file itself. Then, use VersionCompare to compare the versions. See the help file for info on usage. Basically, it would look something like this:
!include logiclib.nsh
!include wordfunc.nsh
!insertmacro VersionCompare
...
Function .onInit
; assume $OldVersion is already set and that ${ThisVersion} is already defined
; set $0ldVersion to "0.0.0.0" if old version is not found
${VersionCompare} "$OldVersion" "${ThisVersion}" $0
${If} $0 = 1
; this version is OLDER
MessageBox MB_OK "This version is older than than existing!"
Abort
${EndIf}
...
FunctionEnd