Rev 133 | Rev 147 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 1 | pmbaty | 1 | !include "MUI2.nsh" | 
| 2 | !include "FileFunc.nsh" | ||
| 3 | |||
| 4 | !define PRODUCT_NAME "Chess Giants" | ||
| 5 | !define PUBLISHER "Pierre-Marie Baty" | ||
| 6 | !define PUBLISHER_WEBSITE "http://www.pmbaty.com/chess/" | ||
| 7 | !define INSTALLER_SRC "C:\Users\Pierre-Marie Baty\Documents\Mes projets\Chess Giants" | ||
| 8 | |||
| 9 | Name "${PRODUCT_NAME}" | ||
| 19 | pmbaty | 10 | BrandingText "${PRODUCT_NAME} by ${PUBLISHER} - ${PUBLISHER_WEBSITE}" | 
| 1 | pmbaty | 11 | |
| 12 | SetCompressor lzma | ||
| 13 | RequestExecutionLevel user | ||
| 14 | |||
| 15 | AllowRootDirInstall true | ||
| 19 | pmbaty | 16 | InstallDir "$LOCALAPPDATA\${PRODUCT_NAME}" | 
| 1 | pmbaty | 17 | |
| 144 | pmbaty | 18 | !define MUI_ICON "${INSTALLER_SRC}\installer\installer.ico" | 
| 1 | pmbaty | 19 | !define MUI_HEADERIMAGE | 
| 144 | pmbaty | 20 | !define MUI_HEADERIMAGE_BITMAP "${INSTALLER_SRC}\installer\installer.bmp" | 
| 21 | !define MUI_WELCOMEFINISHPAGE_BITMAP "${INSTALLER_SRC}\installer\finish.bmp" | ||
| 1 | pmbaty | 22 | !define MUI_ABORTWARNING | 
| 23 | |||
| 24 | !insertmacro MUI_PAGE_LICENSE "${INSTALLER_SRC}\License.txt" | ||
| 25 | !insertmacro MUI_PAGE_DIRECTORY | ||
| 76 | pmbaty | 26 | |
| 27 | Var STR_HAYSTACK | ||
| 28 | Var STR_NEEDLE | ||
| 29 | Var STR_CONTAINS_VAR_1 | ||
| 30 | Var STR_CONTAINS_VAR_2 | ||
| 31 | Var STR_CONTAINS_VAR_3 | ||
| 32 | Var STR_CONTAINS_VAR_4 | ||
| 33 | Var STR_RETURN_VAR | ||
| 144 | pmbaty | 34 | Var LABEL_RESETCONFIG | 
| 35 | Var CHECKBOX_RESETCONFIG | ||
| 76 | pmbaty | 36 | |
| 37 | Function StrContains | ||
| 38 | Exch $STR_NEEDLE | ||
| 39 | Exch 1 | ||
| 40 | Exch $STR_HAYSTACK | ||
| 41 | StrCpy $STR_RETURN_VAR "" | ||
| 42 | StrCpy $STR_CONTAINS_VAR_1 -1 | ||
| 43 | StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE | ||
| 44 | StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK | ||
| 45 | loop: | ||
| 46 | IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1 | ||
| 47 | StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1 | ||
| 48 | StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found | ||
| 49 | StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done | ||
| 50 | Goto loop | ||
| 51 | found: | ||
| 52 | StrCpy $STR_RETURN_VAR $STR_NEEDLE | ||
| 53 | Goto done | ||
| 54 | done: | ||
| 55 | Pop $STR_NEEDLE | ||
| 56 | Exch $STR_RETURN_VAR | ||
| 57 | FunctionEnd | ||
| 58 | !macro _StrContainsConstructor OUT NEEDLE HAYSTACK | ||
| 59 | 		Push `${HAYSTACK}` | ||
| 60 | 		Push `${NEEDLE}` | ||
| 61 | Call StrContains | ||
| 62 | 		Pop `${OUT}` | ||
| 63 | !macroend | ||
| 64 | |||
| 65 | !define StrContains '!insertmacro "_StrContainsConstructor"' | ||
| 66 | |||
| 67 | Function .onVerifyInstDir | ||
| 68 | Push $R0 | ||
| 69 | Push $R1 | ||
| 70 | 		${StrContains} $0 "Program Files" "$INSTDIR" | ||
| 71 | StrCmp $0 "Program Files" pathbad | ||
| 72 | StrCpy $R0 "$INSTDIR" | ||
| 73 | loop: | ||
| 74 | StrLen $R1 "$R0" | ||
| 75 | StrCmp $R1 0 pathbad | ||
| 76 | IfFileExists "$R0" 0 parentLoop | ||
| 77 | 		${GetFileAttributes} "$R0" "DIRECTORY" $R1 | ||
| 78 | StrCmp $R1 0 parentLoop | ||
| 79 | 		${GetFileAttributes} "$R0" "READONLY" $R1 | ||
| 80 | StrCmp $R1 1 pathbad | ||
| 81 | ClearErrors | ||
| 82 | IfFileExists "$R0\.nsis_test_dir" pathgood 0 | ||
| 83 | CreateDirectory "$R0\.nsis_test_dir" | ||
| 84 | IfErrors pathbad 0 | ||
| 85 | RMDir "$R0\.nsis_test_dir" | ||
| 86 | Goto pathgood | ||
| 87 | parentLoop: | ||
| 88 | 		${GetParent} "$R0" "$R0" | ||
| 89 | Goto loop | ||
| 90 | pathbad: | ||
| 91 | Abort | ||
| 92 | pathgood: | ||
| 93 | Pop $R1 | ||
| 94 | Pop $R0 | ||
| 95 | FunctionEnd | ||
| 96 | |||
| 144 | pmbaty | 97 | Function MyFinishShow | 
| 98 | 		${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." | ||
| 99 | Pop $LABEL_RESETCONFIG | ||
| 100 | SetCtlColors $LABEL_RESETCONFIG "" "ffffff" | ||
| 101 | 		${NSD_CreateCheckbox} 120u 165u 60% 10u "&Reset all program settings" | ||
| 102 | Pop $CHECKBOX_RESETCONFIG | ||
| 103 | SetCtlColors $CHECKBOX_RESETCONFIG "" "ffffff" | ||
| 104 | FunctionEnd | ||
| 105 | |||
| 106 | Function MyFinishLeave | ||
| 107 | 		${NSD_GetState} $CHECKBOX_RESETCONFIG $0 | ||
| 108 | 		${If} $0 <> 0 | ||
| 109 | ; if asked to, reset the configuration file | ||
| 110 | Delete "$INSTDIR\config.ini" | ||
| 111 | 		${EndIf} | ||
| 112 | FunctionEnd | ||
| 113 | |||
| 1 | pmbaty | 114 | ;!insertmacro MUI_PAGE_COMPONENTS | 
| 115 | !insertmacro MUI_PAGE_INSTFILES | ||
| 73 | pmbaty | 116 | AutoCloseWindow true | 
| 1 | pmbaty | 117 | |
| 118 | !insertmacro MUI_UNPAGE_CONFIRM | ||
| 119 | !insertmacro MUI_UNPAGE_INSTFILES | ||
| 120 | |||
| 144 | pmbaty | 121 | !define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe" | 
| 122 | !define MUI_PAGE_CUSTOMFUNCTION_SHOW MyFinishShow | ||
| 123 | !define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyFinishLeave | ||
| 124 | !insertmacro MUI_PAGE_FINISH | ||
| 125 | |||
| 1 | pmbaty | 126 | !insertmacro MUI_LANGUAGE "English" | 
| 127 | !insertmacro MUI_LANGUAGE "French" | ||
| 128 | |||
| 129 | Section "" | ||
| 130 | SetOutPath "$INSTDIR" | ||
| 131 | |||
| 144 | pmbaty | 132 | ; erase old files | 
| 133 | RMDir /r "$INSTDIR\data" | ||
| 134 | RMDir /r "$INSTDIR\engines" | ||
| 135 | RMDir /r "$INSTDIR\helpfiles" | ||
| 136 | ; RMDir /r "$INSTDIR\themes"; -- keep user themes | ||
| 137 | |||
| 133 | pmbaty | 138 | ; deploy our files | 
| 1 | pmbaty | 139 | 	File /r "${INSTALLER_SRC}\data" | 
| 44 | pmbaty | 140 | 	File /r "${INSTALLER_SRC}\engines" | 
| 1 | pmbaty | 141 | 	File /r "${INSTALLER_SRC}\helpfiles" | 
| 142 | 	File /r "${INSTALLER_SRC}\themes" | ||
| 143 | 	File "${INSTALLER_SRC}\*.pgn" | ||
| 144 | 	File "${INSTALLER_SRC}\${PRODUCT_NAME}.exe" | ||
| 145 | 	File "${INSTALLER_SRC}\${PRODUCT_NAME}.exe.manifest" | ||
| 29 | pmbaty | 146 | 	File "${INSTALLER_SRC}\Chess Giants (English).html" | 
| 147 | 	File "${INSTALLER_SRC}\Chess Giants (French).html" | ||
| 144 | pmbaty | 148 | 	; File "${INSTALLER_SRC}\config.ini" -- config.ini shall be created on-the-fly | 
| 149 | |||
| 1 | pmbaty | 150 | 	File "${INSTALLER_SRC}\materials.cfg" | 
| 151 | 	File "${INSTALLER_SRC}\d3dx9_42.dll" | ||
| 152 | 	File "${INSTALLER_SRC}\msvcr90.dll" | ||
| 117 | pmbaty | 153 | 	File "${INSTALLER_SRC}\openal32.dll" | 
| 118 | pmbaty | 154 | 	File "${INSTALLER_SRC}\wrap_oal.dll" | 
| 1 | pmbaty | 155 | |
| 133 | pmbaty | 156 | ; create Start menu shortcuts | 
| 1 | pmbaty | 157 | 	CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a chess game" | 
| 158 | 	CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}" | ||
| 159 | 	CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" "" "" "" "" "" "Start a chess game" | ||
| 29 | pmbaty | 160 | 	CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Documentation (English).lnk" "$INSTDIR\Chess Giants (English).html" "" "" "" "" "" "Read the software documentation in English" | 
| 161 | 	CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Documentation (Français).lnk" "$INSTDIR\Chess Giants (French).html" "" "" "" "" "" "Read the software documentation in French" | ||
| 1 | pmbaty | 162 | |
| 133 | pmbaty | 163 | ; associate .pgn files with Chess Giants | 
| 1 | pmbaty | 164 | WriteRegStr HKCU "Software\Classes\.pgn" "" "ChessGiantsPGN" | 
| 165 | WriteRegStr HKCU "Software\Classes\ChessGiantsPGN" "" "Portable Game Notation" | ||
| 166 | ;	WriteRegStr HKCU "Software\Classes\ChessGiantsPGN\DefaultIcon" "" "$INSTDIR\${PRODUCT_NAME}.exe,1" | ||
| 167 | 	WriteRegStr HKCU "Software\Classes\ChessGiantsPGN\shell\open\command" "" '"$INSTDIR\${PRODUCT_NAME}.exe" "%1"' | ||
| 168 | |||
| 133 | pmbaty | 169 | ; associate .fen files with Chess Giants | 
| 1 | pmbaty | 170 | WriteRegStr HKCU "Software\Classes\.fen" "" "ChessGiantsFEN" | 
| 171 | WriteRegStr HKCU "Software\Classes\ChessGiantsFEN" "" "Forsyth-Edwards Notation" | ||
| 172 | ;	WriteRegStr HKCU "Software\Classes\ChessGiantsFEN\DefaultIcon" "" "$INSTDIR\${PRODUCT_NAME}.exe,1" | ||
| 173 | 	WriteRegStr HKCU "Software\Classes\ChessGiantsFEN\shell\open\command" "" '"$INSTDIR\${PRODUCT_NAME}.exe" "%1"' | ||
| 174 | |||
| 133 | pmbaty | 175 | ; create a proper uninstaller | 
| 1 | pmbaty | 176 | WriteUninstaller $INSTDIR\uninstall.exe | 
| 177 | 	WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}" | ||
| 55 | pmbaty | 178 | 	WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayIcon" "$INSTDIR\${PRODUCT_NAME}.exe,0" | 
| 1 | pmbaty | 179 | 	WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" | 
| 180 | 	WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S" | ||
| 181 | 	WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "${PUBLISHER}" | ||
| 182 | 	WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoModify" 1 | ||
| 183 | 	WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1 | ||
| 184 | 	${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 | ||
| 185 | IntFmt $0 "0x%08X" $0 | ||
| 186 | 	WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "EstimatedSize" "$0" | ||
| 73 | pmbaty | 187 | |
| 144 | pmbaty | 188 | ; the program was installed successfully, ask it to delete the installer by writing a little registry key | 
| 133 | pmbaty | 189 | WriteRegStr HKCU "Software\Chess Giants" "InstallerPath" "$EXEPATH" | 
| 1 | pmbaty | 190 | SectionEnd | 
| 14 | pmbaty | 191 | |
| 1 | pmbaty | 192 | Section "Uninstall" | 
| 193 | DeleteRegKey HKCU "Software\Classes\.pgn" | ||
| 194 | DeleteRegKey HKCU "Software\Classes\ChessGiantsPGN" | ||
| 195 | DeleteRegKey HKCU "Software\Classes\.fen" | ||
| 196 | DeleteRegKey HKCU "Software\Classes\ChessGiantsFEN" | ||
| 197 | |||
| 198 | 	Delete "$DESKTOP\${PRODUCT_NAME}.lnk" | ||
| 199 | 	RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}" | ||
| 200 | RMDir /r "$INSTDIR" | ||
| 201 | |||
| 202 | 	DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" | ||
| 203 | SectionEnd |