Créer une installation

Nous avons utilisé pour cela le logiciel NSIS (Nullsoft Scriptable Installation System). Il est possible de le télécharger à cette adresse.

Les explications sont détaillées ici.

Nous donnons notre fichier .nsi en exemple :


;NSIS Modern User Interface version 1.62


!define MUI_PRODUCT "Grenouf"
!define MUI_VERSION "1.0" ;Define your own software version here

!include "MUI.nsh"

;$9 is being used to store the Start Menu Folder.
;Do not use this variable in your script (or Push/Pop it)!

;To change this variable, use MUI_STARTMENU_VARIABLE.
;Have a look at the Readme for info about other options (default folder,
;registry).

;Remember the Start Menu Folder
!define MUI_STARTMENU_REGISTRY_ROOT "HKCU" 
!define MUI_STARTMENU_REGISTRY_KEY "Software\${MUI_PRODUCT}" 
!define MUI_STARTMENU_REGISTRY_VALUENAME "Start Menu Folder"

!define TEMP $R0

;--------------------------------
;Configuration

  ;General
  OutFile "Grenouf_Setup.exe"

;Folder selection page
  InstallDir "$PROGRAMFILES\Grenouf"

;--------------------------------
;Modern UI Configuration

  !define MUI_WELCOMEPAGE
  ;!define MUI_COMPONENTSPAGE
  !define MUI_DIRECTORYPAGE
  !define MUI_STARTMENUPAGE
  
  !define MUI_ABORTWARNING

  !define MUI_UNINSTALLER
  !define MUI_UNCONFIRMPAGE
  !define MUI_FINISHPAGE  

  ;Modern UI System
  !insertmacro MUI_SYSTEM
  
;--------------------------------
;Languages

  !insertmacro MUI_LANGUAGE "French"
  
;--------------------------------
;Language Strings

  ;Description
 
;--------------------------------
;Data
 
  ;LicenseData "License.txt"

;--------------------------------
;.OnInit  

 Function .onInit

   ; On vérifie si l'installation n'a pas déjà eu lieu
   EnumRegValue $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" 0   

   StrCmp "" $1 go_on go_abort

   go_abort:
   MessageBox MB_OK "Grenouf est déjà installé"
   Abort ; causes installer to quit.

   go_on:
 FunctionEnd

;--------------------------------
;Installer Sections

Section "Grenouf.exe" SecCopyUI

  SetOutPath "$INSTDIR"
  CreateDirectory "Data"


  File "Grenouf.exe"
  File "glut32.dll"
  File "Lisez-moi.txt"
  SetOutPath "$INSTDIR\Data"
  File "Data\*"	


;  SetOutPath "$SYSDIR"
;  File "glut32.dll"

  SetOutPath "$INSTDIR"
  !insertmacro MUI_STARTMENU_WRITE_BEGIN

    ;Create shortcuts
    CreateDirectory "$SMPROGRAMS\${MUI_STARTMENU_VARIABLE}"
    CreateShortCut "$SMPROGRAMS\${MUI_STARTMENU_VARIABLE}\Grenouf.lnk" "$INSTDIR\Grenouf.exe"
    CreateShortCut "$SMPROGRAMS\${MUI_STARTMENU_VARIABLE}\Lisez-moi.lnk" "$INSTDIR\Lisez-moi.txt"
    CreateShortCut "$SMPROGRAMS\${MUI_STARTMENU_VARIABLE}\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
    CreateShortCut "$DESKTOP\Grenouf.lnk" "$INSTDIR\Grenouf.exe"


;Write shortcut location to the registry (for Uninstaller)

    WriteRegStr HKCU "Software\${MUI_PRODUCT}" "Start Menu Folder" "${MUI_STARTMENU_VARIABLE}"
    
  !insertmacro MUI_STARTMENU_WRITE_END
    
  ;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"

  ;Create uninstaller for Control Panel
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" "$INSTDIR\Uninstall.exe"

  ;SetRebootFlag true ;Pour redémarrer l'ordinateur à la fin de l'installation

SectionEnd

;Display the Finish header
;Insert this macro after the sections if you are not using a finish page
!insertmacro MUI_SECTIONS_FINISHHEADER

;--------------------------------
;Descriptions

!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${SecCopyUI} $(DESC_SecCopyUI)
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END
 
;--------------------------------
;Uninstaller Section

Section "Uninstall"

  Delete "$INSTDIR\Grenouf.exe"
  Delete "$INSTDIR\Lisez-moi.txt"
  Delete "$INSTDIR\Uninstall.exe"
  Delete "$INSTDIR\Data\*"
  Delete "$INSTDIR\Glut32.dll"
;  Delete "$SYSDIR\Glut32.dll"
  Delete "$DESKTOP\Grenouf.lnk"

  RMDir "$INSTDIR\Data"

  ;Remove shortcut
  ReadRegStr ${TEMP} HKCU "Software\${MUI_PRODUCT}" "Start Menu Folder"
  
  StrCmp ${TEMP} "" noshortcuts
  
    Delete "$SMPROGRAMS\${TEMP}\Grenouf.lnk"
    Delete "$SMPROGRAMS\${TEMP}\Lisez-moi.lnk"
    Delete "$SMPROGRAMS\${TEMP}\Uninstall.lnk"
    RMDir "$SMPROGRAMS\${TEMP}" ;Only if empty, so it won't delete other shortcuts
    
  noshortcuts:

  RMDir "$INSTDIR"
  
  DeleteRegValue HKCU "Software\${MUI_PRODUCT}" "Start Menu Folder"

  ;Create uninstaller for Control Panel
  DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName"
  DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString"
  
  ;Display the Finish header
  !insertmacro MUI_UNFINISHHEADER

SectionEnd