Author Topic: NSIS-based installer  (Read 13514 times)

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« on: June 07, 2008, 07:09:41 PM »
I created an NSIS-based installer for Darwinbots 2.43.1L. It currently installs all the OCX's installed by the original installer as well as msstdfmt.dll (needed for the custom costs dialog), and registers them all. It does not install comdlg32.dll, which is usually already present. If it should be added, tell me. Currently the installed bots consist of Alga Minimalis, Animal Minimalis, Seasnake, and Republican Bee. If you want to recommend any example bots, then do so

I tested it on a brand-new Windows XP SP2 install (hosed my old VirtualBox image thanks to a lack of disk space when merging a snapshot) and it seems to work mostly fine, although for some reason the Settings directory didn't seem to get created (it's in the script though as a recursive copy, although with only default.set).

If you were to make a consistent way of downlloading the newest Darwinbots executable (I.e. in a single place which doesn't change between versions), I could make the installer download the newest version during the installation, using NSISdl. ZIP decompression is also supported in NSIS so that isn't a problem.

The installer is internally compressed with solid LZMA compression so don't bother compressing it again.

(edit: new installer below)

Oh, and here is the NSIS script. It'll need some adjusting to work on Windows since I use it on Linux and it is using Unix-style paths.

Right now, it doesn't uninstall any of the DLLs/OCXs which it installs. If that's an issue I can still add the removal to the uninstall code, but I'd have to add more registry keys to remember whether or not it existed before the installer ran.
Code: [Select]
!include MUI2.nsh
!include VB6RunTime.nsh

Name "DarwinBots 2.4"
OutFile "Darwin_setup.exe"
InstallDir "$PROGRAMFILES\DarwinBots"
InstallDirRegKey HKCU "Software\DarwinBots" ""
RequestExecutionLevel admin
BrandingText " "
XPStyle on
CRCCheck on
SilentInstall normal
SetCompressor /SOLID lzma

Var AlreadyInstalled

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

Section "Install" Install
  SetOutPath "$INSTDIR"

  File "/home/goffrie/Darwinbots/DarwinBotsII/Darwin.exe"
  File "/home/goffrie/Darwinbots/DarwinBotsII/How to setup a DarwinBots server.txt"
  SetOverwrite off
  File "/home/goffrie/Darwinbots/DarwinBotsII/intsett.ini"
  File /r "/home/goffrie/Darwinbots/DarwinBotsII/Robots"
  File /r "/home/goffrie/Darwinbots/DarwinBotsII/Settings"
  SetOutPath "$INSTDIR\Autosave"
  SetOutPath "$INSTDIR\Saves"
  SetOutPath "$INSTDIR\Transfers"
  SetOutPath "$INSTDIR\Transfers\F1"
  SetOutPath "$INSTDIR\Transfers\F1\in"
  SetOutPath "$INSTDIR\Transfers\F1\out"

  SetOutPath "$SYSDIR"

  File "/home/goffrie/Darwinbots/OCX/*.OCX"
  RegDLL "$SYSDIR\COMCT232.OCX"
  RegDLL "$SYSDIR\COMDLG32.OCX"
  RegDLL "$SYSDIR\MSCOMCTL.OCX"
  RegDLL "$SYSDIR\MSINET.OCX"
  RegDLL "$SYSDIR\RICHTX32.OCX"
  RegDLL "$SYSDIR\TABCTL32.OCX"
  File "msstdfmt.dll"
  RegDLL "$SYSDIR\msstdfmt.dll"
  SetOverwrite on

;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"

;Store installation folder
  WriteRegStr HKCU "Software\Darwinbots" "" $INSTDIR

;Install VB runtime
  IfFileExists "$INSTDIR\Darwin.exe" 0 new_installation
    StrCpy $AlreadyInstalled 1
  new_installation:

  !insertmacro VB6RunTimeInstall /home/goffrie/Darwinbots/vb6 $AlreadyInstalled
SectionEnd

Section "Uninstall"

  Delete "$INSTDIR\Darwin.exe"
  Delete "$INSTDIR\How to setup a DarwinBots server.txt"
  Delete "$INSTDIR\intsett.ini"
  Delete "$INSTDIR\Uninstall.exe"
  Delete "$INSTDIR\Robots\Alga_Minimalis.txt"
  Delete "$INSTDIR\Robots\Animal_Minimalis.txt"
  Delete "$INSTDIR\Robots\Gridlock.txt"
  Delete "$INSTDIR\Robots\Republican_Bee.txt"
  Delete "$INSTDIR\Robots\Seasnake_1.0.txt"
  Delete "$INSTDIR\Settings\default.set"
  RMDir "$INSTDIR\Autosave"
  RMDir "$INSTDIR\Robots"
  RMDir "$INSTDIR\Saves"
  RMDir "$INSTDIR\Settings"
  RMDir "$INSTDIR\Transfers\F1\in"
  RMDir "$INSTDIR\Transfers\F1\out"
  RMDir "$INSTDIR\Transfers\F1"
  RMDir "$INSTDIR\Transfers"
  RMDir "$INSTDIR"
  DeleteRegKey /ifempty HKCU "Software\Darwinbots"

;Remove VB runtime
  !insertmacro VB6RunTimeUnInstall
SectionEnd

Gah, another thing I forgot to mention: It doesn't install any shortcuts, I forgot to add it in. I'll put it in... later
« Last Edit: June 10, 2008, 09:02:35 PM by goffrie »

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #1 on: June 10, 2008, 07:32:11 AM »
Nobody wants to comment?

Offline ikke

  • Bot Destroyer
  • ***
  • Posts: 300
    • View Profile
NSIS-based installer
« Reply #2 on: June 10, 2008, 10:15:42 AM »
Quote from: goffrie
Nobody wants to comment?
Speaking for myself: not commenting is a sign of lack of knowledge on my part, not for lack of respect for the work done...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #3 on: June 10, 2008, 03:21:17 PM »
It looks good, but like you say it needs to add shortcuts (one of the shortcuts should be to the actual folder itself, since much work needs to be done in that folder).  Also, the directory name should be DarwinbotsII (even though it's confusing since most haven't seen DB1).  Mostly this is to allow me to eventually have a Darwinbots3 directory that's distinct without causing people to panic when they can't find DB2.  You should also keep the exe name unchanged, so users can find a way to know what version they're using by opening up their directory.  Any maybe a text file that explains where to find the latest patches and what to do with them.  When I start up the exe, it prompts me about missing settings files.  It would be nice if the installer handled all of that, and we could do away with that whole clause.  After I click through the dialogs, my new install does not start a simulation, or it starts an empty simulation (hard to tell either way).  I would set up some quick settings for the different bots included, so people can load them immediately when they first start the game.  It's especially important that these default settings be something that they can leave running for a time and see some mutations going on.  So the settings should be set to let it run without crashing (the population, not the program ).  The default settings that the program launches with should be animal minimalis (but then again, I'm hardly an impartial judge )  When I uninstalled the program, I accidentally left the game running, so not everything got deleted.  The uninstaller should give me a warning message or something to let me know.

Also, some notes to Eric: the splash screen that used to launch when the program was run no longer does.  At the very least it should spash the first time the game is run (which you can detect if there's no lastexit.sim file maybe?).  intsett.ini should remove any irrelevant data (such as the bogus http), to prevent users from thinking that it is important, and not knowing what to set it to.

And I would include the bot Dominator Invincibalis.  It's a good middle tier bot that's very resistant to breaking changes in newer versions.

I'm appreciative of the effort.  Don't think my long list of complaints is anything but nitpicking
« Last Edit: June 10, 2008, 03:25:35 PM by Numsgil »

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #4 on: June 10, 2008, 07:03:26 PM »
Shortcuts have been added to the script (on my hard drive for now.)

Just a question - is the proper capitalization "DarwinBots" or "Darwinbots"? It's been used both ways, so I'm wondering which I should use for paths and such.
Quote
After I click through the dialogs, my new install does not start a simulation, or it starts an empty simulation (hard to tell either way). I would set up some quick settings for the different bots included, so people can load them immediately when they first start the game.
Sorry, I don't really understand you here - what file(s) should be added?
About uninstalling, I already have the "confirm" page, which lists the install directory. What else should I add there?
« Last Edit: June 10, 2008, 07:04:06 PM by goffrie »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #5 on: June 10, 2008, 08:12:07 PM »
DarwinBots is what Carlo uses (the original coder).  I use Darwinbots.  I would say that Darwinbots is the modern spelling, and DarwinBots is an archaic spelling.

For adding files: are you familiar with the fact that you can save different simulating settings in settings files?  These have a .set file type.  Which is different than saving a simulation with file type .sim.  Basically they're a template for a new simulation.  I would add a few that set up some good settings for the different bots you're including.

And as for uninstalling, I think there should just be a warning if it wasn't able to delete something for some reason.  Don't know if the software allows that or not, though, but it would be nice.

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #6 on: June 10, 2008, 08:21:49 PM »
Okay, I'll use "Darwinbots" then.

I am aware of .set files, although I wasn't too sure what you meant by "my new install does not start a simulation". Anyways, I did add Dominator Invincibalis, and created some basic (more or less tested) .set files. The only problem is that Republican Bee is significantly better at combat than the other bots, so I basically had to rig the settings in favour of the other bot, but it would still usually win in the end.

Also, I get what you mean by the warnings now. I'll see if I can do anything about that.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #7 on: June 10, 2008, 08:29:26 PM »
Much appreciated

Oh, also, Excalibur might be another good bot to include.  It's had some fans recently, and been praised highly for its strength vs. ease of understanding.

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #8 on: June 10, 2008, 09:01:20 PM »
Okay, new version time!

Has Alga Minimalis, Animal Minimalis, Dominator Invincibalis, Excalibur, Republican Bee, and Seasnake 1.0.
It now creates shortcuts on the desktop (always, just one) and in the start menu (there is an installer page for that). It also creates an entry in Add/Remove Programs.
If the uninstaller is unable to remove any files, it will warn the user. If it cannot then delete the folder, it will prompt to recursively delete the folders, and if it still cannot do so, it will ask if it can schedule the deletion for the next bootup. Yay NSIS.
It includes several basic setting files, although none of them include Excalibur because that was added at the last minute and I was lazy
It's been tested a few times (*cough* I've installed/uninstalled around... what, 20 times already? ) although I don't know if the delete-on-reboot works (it is an NSIS option so it should be okay.)

Once again, if you can put the latest version of Darwinbots in a standard place, I can have the installer automatically download it. You can have a zip called 'Darwin.zip' and it can contain the properly versioned .exe and it should be okay.

Hope you like it

[attachment=957:Darwin_setup.exe]
P.S. Go LZMA, 9MB executable -> 2.5MB installer = win

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #9 on: June 10, 2008, 09:19:16 PM »
Quote from: goffrie
Once again, if you can put the latest version of Darwinbots in a standard place, I can have the installer automatically download it. You can have a zip called 'Darwin.zip' and it can contain the properly versioned .exe and it should be okay.

That's really Eric's area, since he's the one that'll have to place the new versions in the appropriate place.  Assuming we did it, though, would it be able to update all the shortcuts to point to the newest version?  It's really a pain trying to find the newest version to run from a list of 20 exes in the directory.

I'm testing the installer now...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #10 on: June 10, 2008, 09:25:15 PM »
When I first started the simulation, I still get an empty sim.  This might not be an issue with the installer but with the exe.  I'm not sure.  Hitting F1 and then start new started up a proper sim (this is what the program should do automatically in my mind).  The mutation rates could do with some tweaking (way too high at present).  I had some difficulty loading new settings (kept reverting to my old settings), but that might be an issue with the program and not the installer or the settings.  The uninstaller seemed to work just fine, so no issues there.

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #11 on: June 10, 2008, 09:25:23 PM »
Quote
Assuming we did it, though, would it be able to update all the shortcuts to point to the newest version? It's really a pain trying to find the newest version to run from a list of 20 exes in the directory.
It would update just during installation, and I'm pretty sure I could get the shortcut to point to the right executable. I guess I could make a separate automatic update program, although it'd be tied to my installer (for shortcut updating).

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #12 on: June 10, 2008, 09:28:11 PM »
NSIS is free software, right?  I don't mind tying the program to free software if it makes users' lives easier, especially with updates.

Offline goffrie

  • Bot Builder
  • **
  • Posts: 65
    • View Profile
NSIS-based installer
« Reply #13 on: June 10, 2008, 09:32:08 PM »
Hint: its website is http://nsis.sourceforge.net/  Yup, it's free software.

Speaking of "free as in freedom" software, here's the NSIS source:
Code: [Select]
!include MUI2.nsh
!include VB6RunTime.nsh

Name "Darwinbots 2.4"
OutFile "Darwin_setup.exe"
InstallDir "$PROGRAMFILES\DarwinbotsII"
InstallDirRegKey HKLM "Software\Darwinbots" "InstallDir"
RequestExecutionLevel admin
BrandingText " "
XPStyle on
CRCCheck on
SilentInstall normal
SetCompressor /SOLID lzma

Var AlreadyInstalled

!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Darwinbots"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "ShortcutDir"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
Var StartMenuFolder
!insertmacro MUI_PAGE_STARTMENU "DarwinbotsII" $StartMenuFolder
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

Section "Install" Install
  SetShellVarContext current
  SetOutPath "$INSTDIR"

  File "/home/goffrie/Darwinbots/DarwinBotsII/Darwin2.43.1l.exe"
  File "/home/goffrie/Darwinbots/DarwinBotsII/How to setup a DarwinBots server.txt"
  SetOverwrite off
  File "/home/goffrie/Darwinbots/DarwinBotsII/intsett.ini"
  File /r "/home/goffrie/Darwinbots/DarwinBotsII/Robots"
  File /r "/home/goffrie/Darwinbots/DarwinBotsII/Settings"
  SetOutPath "$INSTDIR\Autosave"
  SetOutPath "$INSTDIR\Saves"
  SetOutPath "$INSTDIR\Transfers"
  SetOutPath "$INSTDIR\Transfers\F1"
  SetOutPath "$INSTDIR\Transfers\F1\in"
  SetOutPath "$INSTDIR\Transfers\F1\out"

  SetOutPath "$SYSDIR"

  File "/home/goffrie/Darwinbots/OCX/*.OCX"
  RegDLL "$SYSDIR\COMCT232.OCX"
  RegDLL "$SYSDIR\COMDLG32.OCX"
  RegDLL "$SYSDIR\MSCOMCTL.OCX"
  RegDLL "$SYSDIR\MSINET.OCX"
  RegDLL "$SYSDIR\RICHTX32.OCX"
  RegDLL "$SYSDIR\TABCTL32.OCX"
  File "msstdfmt.dll"
  RegDLL "$SYSDIR\msstdfmt.dll"
  SetOverwrite on

;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"

;Create Start Menu shortcuts
  !insertmacro MUI_STARTMENU_WRITE_BEGIN "DarwinbotsII"
  CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Darwinbots.lnk" "$INSTDIR\Darwin2.43.1l.exe"
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Darwinbots folder.lnk" "$INSTDIR"
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  !insertmacro MUI_STARTMENU_WRITE_END

  CreateShortCut "$DESKTOP\Darwinbots.lnk" "$INSTDIR\Darwin2.43.1l.exe"

;Store installation folder
  WriteRegStr HKLM "Software\Darwinbots" "InstallDir" $INSTDIR

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII" "DisplayName" "Darwinbots II"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII" "UninstallString" "$INSTDIR\Uninstall.exe"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII" "InstallLocation" "$INSTDIR"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII" "NoRepair" 1

;Install VB runtime
  IfFileExists "$INSTDIR\Darwin.exe" 0 new_installation
    StrCpy $AlreadyInstalled 1
  new_installation:

  !insertmacro VB6RunTimeInstall /home/goffrie/Darwinbots/vb6 $AlreadyInstalled
SectionEnd

Section "Uninstall"
  SetShellVarContext current

  Delete "$INSTDIR\Darwin2.43.1l.exe"
  Delete "$INSTDIR\How to setup a DarwinBots server.txt"
  Delete "$INSTDIR\intsett.ini"
  Delete "$INSTDIR\Uninstall.exe"
  Delete "$INSTDIR\Robots\Alga_Minimalis.txt"
  Delete "$INSTDIR\Robots\Animal_Minimalis.txt"
  Delete "$INSTDIR\Robots\Dominator_Invicibalis.txt"
  Delete "$INSTDIR\Robots\Excalibur.txt"
  Delete "$INSTDIR\Robots\Republican_Bee.txt"
  Delete "$INSTDIR\Robots\Seasnake_1.0.txt"
  Delete "$INSTDIR\Settings\default.set"
  Delete "$INSTDIR\Settings\lastexit.set"
  Delete "$INSTDIR\Settings\AnimalMinimalis-mutation.set"
  Delete "$INSTDIR\Settings\Dominator.set"
  Delete "$INSTDIR\Settings\DominatorVsSeasnake.set"
  Delete "$INSTDIR\Settings\RepublicanBee.set"
  Delete "$INSTDIR\Settings\RepublicanBeeVsDominator.set"
  Delete "$INSTDIR\Settings\Seasnake.set"
  Delete "$INSTDIR\Settings\SeasnakeVsRepublicanBee.set"

  IfErrors 0 +2
    MessageBox MB_OK "Could not delete some files. Ensure that they are not in use and delete them manually."
  ClearErrors

  RMDir "$INSTDIR\Autosave"
  RMDir "$INSTDIR\Robots"
  RMDir "$INSTDIR\Saves"
  RMDir "$INSTDIR\Settings"
  RMDir "$INSTDIR\Transfers\F1\in"
  RMDir "$INSTDIR\Transfers\F1\out"
  RMDir "$INSTDIR\Transfers\F1"
  RMDir "$INSTDIR\Transfers"
  RMDir "$INSTDIR"

  IfErrors 0 okay
    MessageBox MB_YESNO "One or more folders were not deleted because they contain extra files, such as custom settings, save files or robots. Delete them?" IDNO okay
    ClearErrors
    MessageBox MB_YESNO "Are you sure you want to perform this operation? This will delete ALL files in $INSTDIR." IDNO okay
    RMDir /r "$INSTDIR"
    IfErrors 0 okay
      MessageBox MB_YESNO "Deleting all files recursively failed. Do you want to delete them on the next reboot?" IDNO okay
      RMDIR /r /REBOOTOK "$INSTDIR"
  okay:

  !insertmacro MUI_STARTMENU_GETFOLDER "DarwinbotsII" $StartMenuFolder
  Delete "$SMPROGRAMS\$StartMenuFolder\Darwinbots.lnk"
  Delete "$SMPROGRAMS\$StartMenuFolder\Darwinbots folder.lnk"
  Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk"
  RMDir "$SMPROGRAMS\$StartMenuFolder"

  Delete "$DESKTOP\Darwinbots.lnk"

  DeleteRegKey /ifempty HKLM "Software\Darwinbots"

  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DarwinbotsII"

;Remove VB runtime
  !insertmacro VB6RunTimeUnInstall
SectionEnd
« Last Edit: June 10, 2008, 09:32:52 PM by goffrie »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
NSIS-based installer
« Reply #14 on: June 10, 2008, 09:41:11 PM »
Yup, I have no problems with having everything use an installer.  Unless Eric rejects the idea, I'm behind it 100%.  It'll make it easier to package DB with some custom DLLs if the need arises, and makes it much easier on the casual user.

As far as automatically detecting new versions: how exactly are you envisioning it would work?  Like would I re-run the old installer and it would tell me if it has a new version to install, and then do it automatically?

Maybe when you click the Darwinbots shortcut in the start menu, it would run a bridge application that would check for new updates, and install them.  Otherwise it would just run the latest DB version.  That way people's versions are kept up to date automagically.