Old 16th September 2008, 14:44   #1
qforce3
Junior Member
 
Join Date: Sep 2008
Location: Germany
Posts: 2
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!
qforce3 is offline   Reply With Quote
Old 16th September 2008, 14:56   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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.
MSG is offline   Reply With Quote
Old 16th September 2008, 15:32   #3
qforce3
Junior Member
 
Join Date: Sep 2008
Location: Germany
Posts: 2
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?
qforce3 is offline   Reply With Quote
Old 16th September 2008, 18:59   #4
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
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).
Comperio is offline   Reply With Quote
Old 17th September 2008, 16:21   #5
setdosa
Junior Member
 
Join Date: Sep 2008
Posts: 1
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???
setdosa is offline   Reply With Quote
Old 17th September 2008, 17:41   #6
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
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:
code:
!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

Comperio is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump