Author Topic: Installing Plug-ins for Hal using NSIS  (Read 1706 times)

Medeksza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1223
    • View Profile
    • http://www.zabaware.com
Installing Plug-ins for Hal using NSIS
« on: January 10, 2011, 01:26:40 pm »
NSIS is the Nullsoft Installation System and can be downloaded from http://nsis.sourceforge.net/Main_Page

It is the installation system that Hal Assistant and the character expansion pack use. If you wish to make your own Hal plug-in and characters and want to distribute it so that end users can easily install it you can use this system.

Below is the script used by the character expansion pack to install characters in the correct location. Since the user can install Hal in a place other than the default location and different versions of Windows have different default locations, this script will find where Hal is really installed so that plug-in files are placed in the correct location.

Code: [Select]
OutFile 'PackSetup.exe'
RequestExecutionLevel admin
!define PRODUCT_NAME "Ultra Hal Character Expansion Pack"
!define PRODUCT_VERSION "6.0"
!define PRODUCT_PUBLISHER "Zabaware, Inc."
!define PRODUCT_WEB_SITE "http://www.zabaware.com/forum"
!define PRODUCT_DIR_REGKEY "Software\Zabaware\HalGenCharPack"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
var HalDir

## Include headers
!include MUI.nsh
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

## Pages
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW showComponents
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

## Languages
!insertmacro MUI_LANGUAGE English

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
ShowInstDetails show
ShowUnInstDetails show
InstallDir "$PROGRAMFILES\Zabaware\Ultra Hal Assistant 6"
!include Library.nsh


Function showComponents

 ## Disable the Back button
 GetDlgItem $R0 $HWNDPARENT 3
 EnableWindow $R0 0

FunctionEnd

Function .onInit
 
  ;Extract InstallOptions files
  ;$PLUGINSDIR will automatically be removed when the installer closes
  Push $HalDir
  ReadRegStr $HalDir HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
  IfErrors lbl_freshinstall 0
  MessageBox MB_OK|MB_ICONQUESTION "The character expansion pack is already installed. Please uninstall it from Add/Remove Programs in your control panel first if you wish to reinstall it." IDOK
  Abort
  lbl_freshinstall:
  InitPluginsDir 
  ;Make sure Hal is installed
  Push $HalDir
  ReadRegStr $HalDir HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\HalAsst62.exe" ""
  IfErrors 0 lbl_halexists
  Push $HalDir
  ReadRegStr $HalDir HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\HalAsst61.exe" ""
  IfErrors 0 lbl_halexists
  Push $HalDir
  ReadRegStr $HalDir HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\HalAsst.exe" ""
  IfErrors 0 lbl_halexists 
  lbl_nohal:
  MessageBox MB_OK|MB_ICONQUESTION "Ultra Hal Assistant 6.x is not installed. This expansion pack requires Ultra Hal Assistant 6.x which can be downloaded from www.zabaware.com" IDOK
  Abort
  lbl_halexists:
  Push $HalDir
  ReadRegStr $HalDir HKLM "SOFTWARE\Zabaware\Ultra Hal Assistant 6.0\HalConfig" "HalDir"
  IfErrors lbl_nohal 0

FunctionEnd

;********************************
;Actual installation starts here
;********************************


;Install main Hal files
Section "MainSection" SEC01
  SetOutPath "$HalDir\Characters"
  SetOverwrite on
  File "Erica.htr"
  File "Erica.jpg"
  File "EricaBack.jpg"
  File "EricaStart.jpg"
  File "James.htr"
  File "James.jpg"
  File "JamesBack.jpg"
  File "JamesStart.jpg"
  File "Jessica.htr"
  File "Jessica.jpg"
  File "JessicaBack.jpg"
  File "JessicaStart.jpg"
  File "Margene.htr"
  File "Margene.jpg"
  File "MargeneBack.jpg"
  File "MargeneStart.jpg"
  File "Mary.htr"
  File "Mary.jpg"
  File "MaryBack.jpg"
  File "MaryStart.jpg"
  File "Mike.htr"
  File "Mike.jpg"
  File "MikeBack.jpg"
  File "MikeStart.jpg"
  File "Qo'Akavot.htr"
  File "Qo'Akavot.jpg"
  File "Qo'AkavotBack.jpg"
  File "Qo'AkavotStart.jpg"
  File "Sandy.htr"
  File "Sandy.jpg"
  File "SandyBack.jpg"
  File "SandyStart.jpg"
  File "geniprvw.jpg"
  File "robystart.jpg"
  File "pedystart.jpg"
  File "pedyprvw.jpg"
  File "mrlnprvw.jpg"
  File "mrlnstart.jpg"
  File "robyprvw.jpg"
  File "genistart.jpg"
SectionEnd

Section -Post
  WriteUninstaller "$HalDir\Characters\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$HalDir\Characters\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
  Push $HalDir
  ReadRegStr $HalDir HKLM "SOFTWARE\Zabaware\Ultra Hal Assistant 6.0\HalConfig" "HalDir"
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components from $INSTDIR ?" IDYES +2
  Abort
FunctionEnd

Section Uninstall 
  Delete "$HalDir\Characters\Erica.htr"
  Delete "$HalDir\Characters\Erica.jpg"
  Delete "$HalDir\Characters\EricaBack.jpg"
  Delete "$HalDir\Characters\EricaStart.jpg"
  Delete "$HalDir\Characters\James.htr"
  Delete "$HalDir\Characters\James.jpg"
  Delete "$HalDir\Characters\JamesBack.jpg"
  Delete "$HalDir\Characters\JamesStart.jpg"
  Delete "$HalDir\Characters\Jessica.htr"
  Delete "$HalDir\Characters\Jessica.jpg"
  Delete "$HalDir\Characters\JessicaBack.jpg"
  Delete "$HalDir\Characters\JessicaStart.jpg"
  Delete "$HalDir\Characters\Margene.htr"
  Delete "$HalDir\Characters\Margene.jpg"
  Delete "$HalDir\Characters\MargeneBack.jpg"
  Delete "$HalDir\Characters\MargeneStart.jpg"
  Delete "$HalDir\Characters\Mary.htr"
  Delete "$HalDir\Characters\Mary.jpg"
  Delete "$HalDir\Characters\MaryBack.jpg"
  Delete "$HalDir\Characters\MaryStart.jpg"
  Delete "$HalDir\Characters\Mike.htr"
  Delete "$HalDir\Characters\Mike.jpg"
  Delete "$HalDir\Characters\MikeBack.jpg"
  Delete "$HalDir\Characters\MikeStart.jpg"
  Delete "$HalDir\Characters\Qo'Akavot.htr"
  Delete "$HalDir\Characters\Qo'Akavot.jpg"
  Delete "$HalDir\Characters\Qo'AkavotBack.jpg"
  Delete "$HalDir\Characters\Qo'AkavotStart.jpg"
  Delete "$HalDir\Characters\Sandy.htr"
  Delete "$HalDir\Characters\Sandy.jpg"
  Delete "$HalDir\Characters\SandyBack.jpg"
  Delete "$HalDir\Characters\SandyStart.jpg"
  Delete "$HalDir\Characters\geniprvw.jpg"
  Delete "$HalDir\Characters\robystart.jpg"
  Delete "$HalDir\Characters\pedystart.jpg"
  Delete "$HalDir\Characters\pedyprvw.jpg"
  Delete "$HalDir\Characters\mrlnprvw.jpg"
  Delete "$HalDir\Characters\mrlnstart.jpg"
  Delete "$HalDir\Characters\robyprvw.jpg"
  Delete "$HalDir\Characters\genistart.jpg"
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

If you want to make your own installation for character files you can pretty much use this script without much modification or programming knowledge. First copy all the files you want to be part of the installation into one folder. Next open notepad and copy and paste the code above into it. Then you will need some modifications. At the start is this section:
Code: [Select]
!define PRODUCT_NAME "Ultra Hal Character Expansion Pack"
!define PRODUCT_VERSION "6.0"
!define PRODUCT_PUBLISHER "Zabaware, Inc."
!define PRODUCT_WEB_SITE "http://www.zabaware.com/forum"
!define PRODUCT_DIR_REGKEY "Software\Zabaware\HalGenCharPack"

Change all 5 of these options in quotes to your own product name, version, publisher, and web site. For reg key you can change the Zabaware\HalGenCharPack to something else.

Next find the section that look like this:
Code: [Select]
;Install main Hal files
Section "MainSection" SEC01
  SetOutPath "$HalDir\Characters"
  SetOverwrite on
  File "Erica.htr"
  File "Erica.jpg"
  File "EricaBack.jpg"
  File "EricaStart.jpg"
  File "James.htr"
  File "James.jpg"
  File "JamesBack.jpg"
  File "JamesStart.jpg"
  File "Jessica.htr"
  File "Jessica.jpg"
  File "JessicaBack.jpg"
  File "JessicaStart.jpg"
  File "Margene.htr"
  File "Margene.jpg"
  File "MargeneBack.jpg"
  File "MargeneStart.jpg"
  File "Mary.htr"
  File "Mary.jpg"
  File "MaryBack.jpg"
  File "MaryStart.jpg"
  File "Mike.htr"
  File "Mike.jpg"
  File "MikeBack.jpg"
  File "MikeStart.jpg"
  File "Qo'Akavot.htr"
  File "Qo'Akavot.jpg"
  File "Qo'AkavotBack.jpg"
  File "Qo'AkavotStart.jpg"
  File "Sandy.htr"
  File "Sandy.jpg"
  File "SandyBack.jpg"
  File "SandyStart.jpg"
  File "geniprvw.jpg"
  File "robystart.jpg"
  File "pedystart.jpg"
  File "pedyprvw.jpg"
  File "mrlnprvw.jpg"
  File "mrlnstart.jpg"
  File "robyprvw.jpg"
  File "genistart.jpg"
SectionEnd
Change all the files to the files you actually want to install. Note the outpath is $HalDir\Characters which means it will put everything in the "Characters" subfolder of Hal's program files folder.

Lastly find the section that looks like:
Code: [Select]
Section Uninstall 
  Delete "$HalDir\Characters\Erica.htr"
  Delete "$HalDir\Characters\Erica.jpg"
  Delete "$HalDir\Characters\EricaBack.jpg"
  Delete "$HalDir\Characters\EricaStart.jpg"
  Delete "$HalDir\Characters\James.htr"
  Delete "$HalDir\Characters\James.jpg"
  Delete "$HalDir\Characters\JamesBack.jpg"
  Delete "$HalDir\Characters\JamesStart.jpg"
  Delete "$HalDir\Characters\Jessica.htr"
  Delete "$HalDir\Characters\Jessica.jpg"
  Delete "$HalDir\Characters\JessicaBack.jpg"
  Delete "$HalDir\Characters\JessicaStart.jpg"
  Delete "$HalDir\Characters\Margene.htr"
  Delete "$HalDir\Characters\Margene.jpg"
  Delete "$HalDir\Characters\MargeneBack.jpg"
  Delete "$HalDir\Characters\MargeneStart.jpg"
  Delete "$HalDir\Characters\Mary.htr"
  Delete "$HalDir\Characters\Mary.jpg"
  Delete "$HalDir\Characters\MaryBack.jpg"
  Delete "$HalDir\Characters\MaryStart.jpg"
  Delete "$HalDir\Characters\Mike.htr"
  Delete "$HalDir\Characters\Mike.jpg"
  Delete "$HalDir\Characters\MikeBack.jpg"
  Delete "$HalDir\Characters\MikeStart.jpg"
  Delete "$HalDir\Characters\Qo'Akavot.htr"
  Delete "$HalDir\Characters\Qo'Akavot.jpg"
  Delete "$HalDir\Characters\Qo'AkavotBack.jpg"
  Delete "$HalDir\Characters\Qo'AkavotStart.jpg"
  Delete "$HalDir\Characters\Sandy.htr"
  Delete "$HalDir\Characters\Sandy.jpg"
  Delete "$HalDir\Characters\SandyBack.jpg"
  Delete "$HalDir\Characters\SandyStart.jpg"
  Delete "$HalDir\Characters\geniprvw.jpg"
  Delete "$HalDir\Characters\robystart.jpg"
  Delete "$HalDir\Characters\pedystart.jpg"
  Delete "$HalDir\Characters\pedyprvw.jpg"
  Delete "$HalDir\Characters\mrlnprvw.jpg"
  Delete "$HalDir\Characters\mrlnstart.jpg"
  Delete "$HalDir\Characters\robyprvw.jpg"
  Delete "$HalDir\Characters\genistart.jpg"
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

This is the uninstallation instructions. Change all the file names here to match the files you installed in the previous section.

After that's done, save your script with the ".NSI" file extension and use the NSIS program you downloaded from http://nsis.sourceforge.net/ to compile it. It will make a professional setup.exe file for you and compress everything into it.
Robert Medeksza

Harry.Sons

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Installing Plug-ins for Hal using NSIS
« Reply #1 on: December 08, 2012, 09:53:24 pm »
This is just what I need. :) You made the installation so much easier for me. Thanks!