Subversion Repositories Games.Rick Dangerous

Rev

Rev 9 | 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 "Rick Dangerous"
!define PUBLISHER "Pierre-Marie Baty"
!define PUBLISHER_WEBSITE "http://www.pmbaty.com/rick/"
!define INSTALLER_SRC "Z:\Documents\Mes projets\Rick Dangerous"

Name "${PRODUCT_NAME}"
BrandingText "${PRODUCT_NAME} by ${PUBLISHER} - ${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_ABORTWARNING

!insertmacro MUI_PAGE_LICENSE "${INSTALLER_SRC}\installer\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
 
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

;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
AutoCloseWindow true

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

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

Section ""
        SetOutPath "$INSTDIR"

        ; deploy our files
        File /r "${INSTALLER_SRC}\sounds"
        File "${INSTALLER_SRC}\${PRODUCT_NAME}.exe"
        File "${INSTALLER_SRC}\SDL2.dll"
        File "${INSTALLER_SRC}\Rick Dangerous Paper Toy.pdf"

        ; create Start menu shortcuts
        CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a Rick Dangerous game"
        CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a Rick Dangerous game"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Rick Dangerous Paper Toy.lnk" "$INSTDIR\Rick Dangerous Paper Toy.pdf" "" "" "" "" "" "Build your own Rick Dangerous 3D paper toy!"
        CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Online Help (incl. how to play).lnk" "http://www.pmbaty.com/rick/" "" "" "" "" "" "Visit the website to learn how to play"

        ; 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" "${PUBLISHER}"
        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"
SectionEnd

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

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