Rev 179 | 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:\Documents\Mes projets\Chess Giants"Name "${PRODUCT_NAME}"BrandingText "${PRODUCT_NAME} - ${PUBLISHER_WEBSITE}"SetCompressor lzmaRequestExecutionLevel userAllowRootDirInstall trueInstallDir "$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_DIRECTORYVar STR_HAYSTACKVar STR_NEEDLEVar STR_CONTAINS_VAR_1Var STR_CONTAINS_VAR_2Var STR_CONTAINS_VAR_3Var STR_CONTAINS_VAR_4Var STR_RETURN_VARVar LABEL_RESETCONFIGVar CHECKBOX_RESETCONFIGFunction StrContainsExch $STR_NEEDLEExch 1Exch $STR_HAYSTACKStrCpy $STR_RETURN_VAR ""StrCpy $STR_CONTAINS_VAR_1 -1StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLEStrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACKloop:IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE foundStrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 doneGoto loopfound:StrCpy $STR_RETURN_VAR $STR_NEEDLEGoto donedone:Pop $STR_NEEDLEExch $STR_RETURN_VARFunctionEnd!macro _StrContainsConstructor OUT NEEDLE HAYSTACKPush `${HAYSTACK}`Push `${NEEDLE}`Call StrContainsPop `${OUT}`!macroend!define StrContains '!insertmacro "_StrContainsConstructor"'Function .onVerifyInstDirPush $R0Push $R1${StrContains} $0 "Program Files" "$INSTDIR"StrCmp $0 "Program Files" pathbadStrCpy $R0 "$INSTDIR"loop:StrLen $R1 "$R0"StrCmp $R1 0 pathbadIfFileExists "$R0" 0 parentLoop${GetFileAttributes} "$R0" "DIRECTORY" $R1StrCmp $R1 0 parentLoop${GetFileAttributes} "$R0" "READONLY" $R1StrCmp $R1 1 pathbadClearErrorsIfFileExists "$R0\.nsis_test_dir" pathgood 0CreateDirectory "$R0\.nsis_test_dir"IfErrors pathbad 0RMDir "$R0\.nsis_test_dir"Goto pathgoodparentLoop:${GetParent} "$R0" "$R0"Goto looppathbad:Abortpathgood:Pop $R1Pop $R0FunctionEndFunction 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_RESETCONFIGSetCtlColors $LABEL_RESETCONFIG "" "ffffff"${NSD_CreateCheckbox} 120u 165u 60% 10u "&Reset all program settings"Pop $CHECKBOX_RESETCONFIGSetCtlColors $CHECKBOX_RESETCONFIG "" "ffffff"FunctionEndFunction MyFinishLeave${NSD_GetState} $CHECKBOX_RESETCONFIG $0${If} $0 <> 0; if asked to, reset the configuration fileDelete "$INSTDIR\config.ini"${EndIf}FunctionEnd;!insertmacro MUI_PAGE_COMPONENTS!insertmacro MUI_PAGE_INSTFILESAutoCloseWindow 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 filesRMDir /r "$INSTDIR\data"RMDir /r "$INSTDIR\engines"RMDir /r "$INSTDIR\helpfiles"; RMDir /r "$INSTDIR\themes"; -- keep user themes; deploy our filesFile /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-flyFile "${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 shortcutsCreateShortCut "$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 GiantsWriteRegStr 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 GiantsWriteRegStr 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 uninstallerWriteUninstaller $INSTDIR\uninstall.exeWriteRegStr 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" 1WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2IntFmt $0 "0x%08X" $0WriteRegDWORD 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 keyWriteRegStr HKCU "Software\Chess Giants" "InstallerPath" "$EXEPATH"SectionEndSection "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