Subversion Repositories Games.Chess Giants

Rev

Rev 163 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

!include "MUI2.nsh"
!include "FileFunc.nsh"

!define PRODUCT_NAME "Chess Giants"
!define PUBLISHER_WEBSITE "http://www.pmbaty.com/chess/"
!define INSTALLER_SRC "Z:\pmbaty\Documents\Mes projets\Chess Giants"

Name "${PRODUCT_NAME}"
BrandingText "${PRODUCT_NAME} - ${PUBLISHER_WEBSITE}"

SetCompressor lzma
RequestExecutionLevel user

AllowRootDirInstall true
InstallDir "$LOCALAPPDATA\${PRODUCT_NAME}"

!define MUI_ICON "${INSTALLER_SRC}\installer\installer.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${INSTALLER_SRC}\installer\installer.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "${INSTALLER_SRC}\installer\finish.bmp"
!define MUI_ABORTWARNING

!insertmacro MUI_PAGE_LICENSE "${INSTALLER_SRC}\License.txt"
!insertmacro MUI_PAGE_DIRECTORY

Var STR_HAYSTACK
Var STR_NEEDLE
Var STR_CONTAINS_VAR_1
Var STR_CONTAINS_VAR_2
Var STR_CONTAINS_VAR_3
Var STR_CONTAINS_VAR_4
Var STR_RETURN_VAR
Var LABEL_RESETCONFIG
Var CHECKBOX_RESETCONFIG
 
Function StrContains
                Exch $STR_NEEDLE
                Exch 1
                Exch $STR_HAYSTACK
                StrCpy $STR_RETURN_VAR ""
                StrCpy $STR_CONTAINS_VAR_1 -1
                StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
                StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
        loop:
                IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
                StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
                StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
                StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
                Goto loop
        found:
                StrCpy $STR_RETURN_VAR $STR_NEEDLE
                Goto done
        done:
                Pop $STR_NEEDLE
                Exch $STR_RETURN_VAR  
FunctionEnd
!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
                Push `${HAYSTACK}`
                Push `${NEEDLE}`
                Call StrContains
                Pop `${OUT}`
!macroend
 
!define StrContains '!insertmacro "_StrContainsConstructor"'

Function .onVerifyInstDir
                Push $R0
                Push $R1
                ${StrContains} $0 "Program Files" "$INSTDIR"
                StrCmp $0 "Program Files" pathbad
                StrCpy $R0 "$INSTDIR"
        loop:
                StrLen $R1 "$R0"
                StrCmp $R1 0 pathbad
                IfFileExists "$R0" 0 parentLoop
                ${GetFileAttributes} "$R0" "DIRECTORY" $R1
                StrCmp $R1 0 parentLoop
                ${GetFileAttributes} "$R0" "READONLY" $R1
                StrCmp $R1 1 pathbad
                ClearErrors
                IfFileExists "$R0\.nsis_test_dir" pathgood 0
                CreateDirectory "$R0\.nsis_test_dir"
                IfErrors pathbad 0
                RMDir "$R0\.nsis_test_dir"
                Goto pathgood
        parentLoop:
                ${GetParent} "$R0" "$R0"
                Goto loop
        pathbad:
                Abort
        pathgood:
                Pop $R1
                Pop $R0
FunctionEnd

Function MyFinishShow
                ${NSD_CreateLabel} 120u 120u 60% 40u "If the program was previously installed, all your custom settings are preserved. If you want to reset them as well (for example, to fix a misconfiguration problem) then tick the following checkbox."
                Pop $LABEL_RESETCONFIG
                SetCtlColors $LABEL_RESETCONFIG "" "ffffff"
                ${NSD_CreateCheckbox} 120u 165u 60% 10u "&Reset all program settings"
                Pop $CHECKBOX_RESETCONFIG
                SetCtlColors $CHECKBOX_RESETCONFIG "" "ffffff"
FunctionEnd

Function MyFinishLeave
                ${NSD_GetState} $CHECKBOX_RESETCONFIG $0
                ${If} $0 <> 0
                        ; if asked to, reset the configuration file
                        Delete "$INSTDIR\config.ini"
                ${EndIf}
FunctionEnd

;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
AutoCloseWindow true

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyFinishShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyFinishLeave
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"

Section ""
        SetOutPath "$INSTDIR"

        ; erase old files
        RMDir /r "$INSTDIR\data"
        RMDir /r "$INSTDIR\engines"
        RMDir /r "$INSTDIR\helpfiles"
        ; RMDir /r "$INSTDIR\themes"; -- keep user themes

        ; deploy our files
        File /r "${INSTALLER_SRC}\data"
        File /r "${INSTALLER_SRC}\engines"
        File /r "${INSTALLER_SRC}\helpfiles"
        File /r "${INSTALLER_SRC}\themes"
        File "${INSTALLER_SRC}\*.pgn"
        File "${INSTALLER_SRC}\${PRODUCT_NAME}.exe"
;       File "${INSTALLER_SRC}\${PRODUCT_NAME}.exe.manifest"
        File "${INSTALLER_SRC}\Chess Giants (English).html"
        File "${INSTALLER_SRC}\Chess Giants (French).html"
        ; File "${INSTALLER_SRC}\config.ini" -- config.ini shall be created on-the-fly

        File "${INSTALLER_SRC}\materials.cfg"
        File "${INSTALLER_SRC}\d3dx9_42.dll"
        File "${INSTALLER_SRC}\msvcr90.dll"
        File "${INSTALLER_SRC}\openal32.dll"
        File "${INSTALLER_SRC}\wrap_oal.dll"

        ; create Start menu shortcuts
        CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a chess game"
        CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a chess game"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Documentation (English).lnk" "$INSTDIR\Chess Giants (English).html" "" "" "" "" "" "Read the software documentation in English"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Documentation (Français).lnk" "$INSTDIR\Chess Giants (French).html" "" "" "" "" "" "Read the software documentation in French"

        ; associate .pgn files with Chess Giants
        WriteRegStr HKCU "Software\Classes\.pgn" "" "ChessGiantsPGN"
        WriteRegStr HKCU "Software\Classes\ChessGiantsPGN" "" "Portable Game Notation"
;       WriteRegStr HKCU "Software\Classes\ChessGiantsPGN\DefaultIcon" "" "$INSTDIR\${PRODUCT_NAME}.exe,1"
        WriteRegStr HKCU "Software\Classes\ChessGiantsPGN\shell\open\command" "" '"$INSTDIR\${PRODUCT_NAME}.exe" "%1"'

        ; associate .fen files with Chess Giants
        WriteRegStr HKCU "Software\Classes\.fen" "" "ChessGiantsFEN"
        WriteRegStr HKCU "Software\Classes\ChessGiantsFEN" "" "Forsyth-Edwards Notation"
;       WriteRegStr HKCU "Software\Classes\ChessGiantsFEN\DefaultIcon" "" "$INSTDIR\${PRODUCT_NAME}.exe,1"
        WriteRegStr HKCU "Software\Classes\ChessGiantsFEN\shell\open\command" "" '"$INSTDIR\${PRODUCT_NAME}.exe" "%1"'

        ; create a proper uninstaller
        WriteUninstaller $INSTDIR\uninstall.exe
        WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}"
        WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayIcon" "$INSTDIR\${PRODUCT_NAME}.exe,0"
        WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
        WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
        WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "${PRODUCT_NAME}"
        WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoModify" 1
        WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1
        ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
        IntFmt $0 "0x%08X" $0
        WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "EstimatedSize" "$0"

        ; the program was installed successfully, ask it to delete the installer by writing a little registry key
        WriteRegStr HKCU "Software\Chess Giants" "InstallerPath" "$EXEPATH"
SectionEnd

Section "Uninstall"
        DeleteRegKey HKCU "Software\Classes\.pgn"
        DeleteRegKey HKCU "Software\Classes\ChessGiantsPGN"
        DeleteRegKey HKCU "Software\Classes\.fen"
        DeleteRegKey HKCU "Software\Classes\ChessGiantsFEN"

        Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
        RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
        RMDir /r "$INSTDIR"

        DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
SectionEnd