Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Some questions about creating an installer for trunk.

News and discussion of the PC port of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Some questions about creating an installer for trunk.

Post by Diziet Sma »

Having looked through some older posts regarding building from source, I've now automated my trunk builds, and installed NSIS so that I can create a Win-Installer. I also had to install SVN, as the makefile will not function properly with TortoiseSVN.

Everything is now working well, and today I successfully made my first Installer :D, which leads to my 3 questions...

1. From what I can see, the option "pkg-win-snapshot" in the makefile simply appends the SVN revision number to the filename and file version information. Is this assumption correct, or is there some more fundamental difference between a snapshot and a release version?

2. The default installer as created by OOlite.nsi attempts to uninstall Oolite before proceeding. In other words, it wants to perform an upgrade. What I want to do is create an installer which will allow me to have both 1.72.2 AND trunk installed simultaneously. I have produced a modified version of OOlite.nsi which I believe will accomplish this goal. I'm tempted to simply go ahead and test it, but the more cautious side of me would like confirmation from somebody with more experience in this area first. Have I got it right?

I've modified cosmetic references of Oolite to Oolite-Trunk
InstallDir changed to Oolite-Trunk
All registry keys and strings changed to Oolite-Trunk
Start Menu entries changed to Oolite-Trunk

So far as I can judge, this will allow me to install/upgrade/uninstall both 1.72 and trunk independently of each other.

This is my edited OOlite.nsi script (OOlite_Trunk.nsi).

Code: Select all

; Need to include the versions as we can't pass them in as parameters
; and it's too much work to try to dynamically edit this file
!include /NONFATAL "OoliteVersions.nsh"

!ifndef SVNREV
!warning "No SVN Revision supplied"
!define SVNREV 0
!endif
!ifndef VERSION
!warning "No Version information supplied"
!define VERSION 0.0.0.0
!endif
; Version number must be of format X.X.X.X.
; We use M.m.R.S:  M-major, m-minor, R-revision, S-subversion
!define VER ${VERSION}
!ifndef DST
!define DST ..\..\oolite.app
!endif
!ifndef OUTDIR
!define OUTDIR .
!endif

!ifndef SNAPSHOT
!define EXTVER ""
!else
!define EXTVER "-dev"
!endif

!include "MUI.nsh"

SetCompress auto
SetCompressor LZMA
SetCompressorDictSize 32
SetDatablockOptimize on
OutFile "${OUTDIR}\OoliteInstall-${VER}${EXTVER}.exe"
BrandingText "(C) 2003-2009 Giles Williams and contributors"
Name "Oolite"
Caption "Oolite ${VER}${EXTVER} (Trunk Version) Setup"
SubCaption 0 " "
SubCaption 1 " "
SubCaption 2 " "
SubCaption 3 " "
SubCaption 4 " "
Icon Oolite.ico
UninstallIcon Oolite.ico
InstallDirRegKey HKLM Software\Oolite-Trunk "Install_Dir"
InstallDir $PROGRAMFILES\Oolite-Trunk
CRCCheck on
InstallColors /windows
InstProgressFlags smooth
AutoCloseWindow false
SetOverwrite on

VIAddVersionKey "ProductName" "Oolite"
VIAddVersionKey "FileDescription" "A space combat/trading game, inspired by Elite."
VIAddVersionKey "LegalCopyright" "© 2003-2009 Giles Williams and contributors"
VIAddVersionKey "FileVersion" "${VER}"
!ifdef SNAPSHOT
VIAddVersionKey "SVN Revision" "${SVNREV}"
!endif
!ifdef BUILDTIME
VIAddVersionKey "Build Time" "${BUILDTIME}"
!endif
VIProductVersion "${VER}"

!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP ".\OoliteInstallerHeaderBitmap_ModernUI.bmp"
!define MUI_HEADERIMAGE_UNBITMAP ".\OoliteInstallerHeaderBitmap_ModernUI.bmp"
!define MUI_ICON oolite.ico
!define MUI_UNICON oolite.ico

!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES  
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

Function .onInit
 ; 1. Check for multiple running installers
 System::Call 'kernel32::CreateMutexA(i 0, i 0, t "OoliteInstallerMutex") i .r1 ?e'
 Pop $R0
 
 StrCmp $R0 0 +3
   MessageBox MB_OK|MB_ICONEXCLAMATION "Another instance of the Oolite installer is already running."
   Abort

  ; 2. Checks for already-installed versions of Oolite-Trunk and offers to uninstall
  ReadRegStr $R0 HKLM \
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk" \
  "UninstallString"
  StrCmp $R0 "" done
 
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  "Oolite-Trunk is already installed. $\n$\nClick `OK` to remove the \
  previous version or `Cancel` to cancel this upgrade." \
  IDOK uninst
  Abort
 
;Run the uninstaller
uninst:
  ClearErrors
  ExecWait '$R0 _?=$INSTDIR'
  IfErrors no_remove_uninstaller
    Delete "$INSTDIR\UninstOolite.exe"
    Goto done
  no_remove_uninstaller:
    MessageBox MB_OK|MB_ICONEXCLAMATION "The Uninstaller did not complete successfully.  Please ensure Oolite-Trunk was correctly uninstalled then run the installer again."
    Abort
done:
FunctionEnd

Function RegSetup
FunctionEnd

Function un.RegSetup
FunctionEnd

;------------------------------------------------------------
; Installation Section
Section ""
SetOutPath $INSTDIR

; Package files
CreateDirectory "$INSTDIR\AddOns"

File "Oolite.ico"
File "Oolite_Readme.txt"
File "OoliteRS.pdf"
File "..\..\Doc\AdviceForNewCommanders.pdf"
File /r /x .svn /x *~ "${DST}"

WriteUninstaller "$INSTDIR\UninstOolite.exe"

; Registry entries
WriteRegStr HKLM Software\Oolite-Trunk "Install_Dir" "$INSTDIR"
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk DisplayName "Oolite ${VER}${EXTVER}"
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk UninstallString '"$INSTDIR\UninstOolite.exe"'

; Start Menu shortcuts
SetOutPath $INSTDIR\oolite.app
CreateDirectory "$SMPROGRAMS\Oolite-Trunk"
CreateShortCut "$SMPROGRAMS\Oolite-Trunk\Oolite.lnk" "$INSTDIR\oolite.app\oolite.exe" "" "$INSTDIR\Oolite.ico"
CreateShortCut "$SMPROGRAMS\Oolite-Trunk\Oolite ReadMe.lnk" "$INSTDIR\Oolite_Readme.txt"
CreateShortCut "$SMPROGRAMS\Oolite-Trunk\Oolite Reference Sheet.lnk" "$INSTDIR\OoliteRS.pdf"
CreateShortCut "$SMPROGRAMS\Oolite-Trunk\Oolite Website.lnk" "http://oolite.org/"
CreateShortCut "$SMPROGRAMS\Oolite-Trunk\Oolite Uninstall.lnk" "$INSTDIR\UninstOolite.exe"

Call RegSetup

Exec "notepad.exe $INSTDIR\Oolite_Readme.txt"

SectionEnd

;------------------------------------------------------------
; Uninstaller Section
Section "Uninstall"

; Remove registry entries
DeleteRegKey HKLM Software\Oolite-Trunk
DeleteRegKey HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk
Call un.RegSetup

; Remove Start Menu entries
RMDir /r "$SMPROGRAMS\Oolite-Trunk"

; Remove Package files (but leave any generated content behind)
RMDir /r "$INSTDIR\oolite.app\Contents"
RMDir /r "$INSTDIR\oolite.app\GNUstep"
RMDir /r "$INSTDIR\oolite.app\oolite.app"
RMDir /r "$INSTDIR\oolite.app\Resources"
RMDir /r "$INSTDIR\oolite.app\Logs"
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\oolite.app\*.*"

SectionEnd


3. As an aside, clearly OOlite.nsi is the script that would need to be modified in order to make an installer which automatically changes the default install-directory if it is running on Vista. I don't know how this would be done, (or indeed if it can be) but is anybody currently investigating the possibility?
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6580
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

OK, let's see.
1. I don't think there are any other differences, apart from the full revision number being dispalyed, really.

2. This is deliberate and we would like it so for this version only. 1.73 will be a pretty major upgrade of the game with plenty datafiles changed. Requiring an uninstall of previous versions ensures that there will not be any problems related to old datafiles that could somehow remain behind. If you want to keep both versions, you can copy your 1.72.2 tree to some other location on disk, then run the 1.73 installer and let it uninstall 1.72.2. After 1.73, the installer could be changed again to not require uninstallation of previous version. IHowever, f you want to change the installer so that it does not check for old versions, you need to remove this part of the script:

Code: Select all

; 2. Checks for already-installed versions of Oolite-Trunk and offers to uninstall 
  ReadRegStr $R0 HKLM \ 
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk" \ 
  "UninstallString" 
  StrCmp $R0 "" done 
  
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ 
  "Oolite-Trunk is already installed. $\n$\nClick `OK` to remove the \ 
  previous version or `Cancel` to cancel this upgrade." \ 
  IDOK uninst 
  Abort 
3. To change the default install folder, change the line that reads

Code: Select all

InstallDir $PROGRAMFILES\Oolite-Trunk
to

Code: Select all

InstallDir C:\Oolite-Trunk
The reason I have not changed it yet is that I do not like very much hardcoding the path, but it could be a good idea to go ahead and do it anyway.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Post by Diziet Sma »

another_commander wrote:
OK, let's see.
1. I don't think there are any other differences, apart from the full revision number being dispalyed, really.
Ok. thanks for confirming this.
another_commander wrote:
2. This is deliberate and we would like it so for this version only. 1.73 will be a pretty major upgrade of the game with plenty datafiles changed. Requiring an uninstall of previous versions ensures that there will not be any problems related to old datafiles that could somehow remain behind. If you want to keep both versions, you can copy your 1.72.2 tree to some other location on disk, then run the 1.73 installer and let it uninstall 1.72.2. After 1.73, the installer could be changed again to not require uninstallation of previous version. However, f you want to change the installer so that it does not check for old versions, you need to remove this part of the script:

Code: Select all

; 2. Checks for already-installed versions of Oolite-Trunk and offers to uninstall 
  ReadRegStr $R0 HKLM \ 
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\Oolite-Trunk" \ 
  "UninstallString" 
  StrCmp $R0 "" done 
  
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ 
  "Oolite-Trunk is already installed. $\n$\nClick `OK` to remove the \ 
  previous version or `Cancel` to cancel this upgrade." \ 
  IDOK uninst 
  Abort 
Thanks for this.. and I agree with what you've said about major upgrades and datafiles, but perhaps I need to clarify a little.. I'd already thought of just disabling the section you mentioned, but realised that would be untidy and would not enable a clean uninstall of 1.72 or the trunk build. Several other things such as Start Menu items would also be overwritten, and the whole thing could easily become a mess.

I was not advocating including my script in trunk, as I feel your reasoning above is correct. The modified script I posted was intended for my own use only (and conceivably some other individuals who clearly understand what they are doing). I already have two completely separate install-dirs, the standard one for 1.72, and a manually created one for trunk complete with its own addons (as there are no registry keys for the trunk version, upgrades need to be done manually at the moment). Both versions co-exist happily and I can just run whichever one I choose, but an installer for trunk would simplify upgrades for new builds considerably. Your suggestion of copying/moving/uninstalling/installing different versions depending on which one I want to run is, I feel, tedious, time-consuming and potentially error-prone.

Therefore my OOlite_Trunk.nsi script is intended to make it look to Windows as if there are two completely separate programs installed, which coincidentally happen to have similar names. It should create separate Registry keys, separate Start-Menu entries, separate install-dirs, and enable either version to be uninstalled or upgraded independently of each other. The check for previously installed versions should also only check for previous trunk versions. So far as I can tell, it succeeds in doing all of this. Unless somebody can point out a flaw in my script or my reasoning, I will go ahead and try this, I think..
another_commander wrote:
The reason I have not changed it yet is that I do not like very much hardcoding the path, but it could be a good idea to go ahead and do it anyway.
Agreed, hardcoding is not good... what I had in mind for 1.73 (when it's released) was for the installer to discover whether it was running on XP or Vista/Windows 7, if XP, then to install to the normal default location, but if on Vista/Windows 7, to modify the install directory accordingly, thus:

Code: Select all

InstallDir $SYSTEMDRIVE\Oolite
which would avoid hardcoding issues and at the same time avoid all the Vista related dramas people have had...
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6580
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Dizzy, please try doing an installer using SVN2232. I have modified the script so now it defaults the installation to <SystemDrive>\Oolite, instead of <ProgramFiles>\Oolite. On my system it works OK. Hopefully this will stop problems arising from Vista's virtualization. I thought it would be much simpler if we had one folder for all rather than scanning the OS etc.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Post by Diziet Sma »

8) Will do.. but in the morning.. it's 2.10am here.. I'm gonna go inspect the inside of my eyelids for a few hours..
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Post by Diziet Sma »

Ok another_commander, the new install location works fine for me too. :D

I then edited your new OOlite.nsi in the same fashion as described above and tested it too. It works as planned. I can now install/upgrade/uninstall the development version fully independently of my 1.72 installation. 8) :D :D Now I can give a copy of the trunk installer to a friend who wants to try it but doesn't want to wipe out his 1.72 install and isn't up to compiling his own... :D

Registry entry for 1.72
Image

Registry entry for trunk
Image

Separate Start-Menu entry for trunk
Image

Add/Remove Programs entries
Image
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
Post Reply