Changeset - r16476:1ec9b7817934
[Not reviewed]
master
0 1 0
glx - 14 years ago 2010-11-16 15:12:22
glx@openttd.org
(svn r21210) -Fix [FS#4231]: make sure text files use DOS EOL
-Fix: shortcuts were not delete when uninstalling OpenTTD on Windows Vista/7
-Add [FS#4231]: shortcuts to extra documentation files (docs and scripts subdir)
1 file changed with 86 insertions and 0 deletions:
0 comments (0 inline, 0 general)
os/windows/installer/install.nsi
Show inline comments
 
@@ -28,48 +28,50 @@ BrandingText "OpenTTD Installer"
 
SetCompressor LZMA
 

	
 
; Version Info
 
Var AddWinPrePopulate
 
VIProductVersion "${APPVERSIONINTERNAL}"
 
VIAddVersionKey "ProductName" "OpenTTD ${APPBITS}-bit Installer for Windows ${EXTRA_VERSION}"
 
VIAddVersionKey "Comments" "Installs ${APPNAMEANDVERSION}"
 
VIAddVersionKey "CompanyName" "OpenTTD Developers"
 
VIAddVersionKey "FileDescription" "Installs ${APPNAMEANDVERSION}"
 
VIAddVersionKey "ProductVersion" "${APPVERSION}"
 
VIAddVersionKey "InternalName" "InstOpenTTD-${APPARCH}"
 
VIAddVersionKey "FileVersion" "${APPVERSION}-${APPARCH}"
 
VIAddVersionKey "LegalCopyright" " "
 
; Main Install settings
 
Name "${APPNAMEANDVERSION} ${APPBITS}-bit for Windows ${EXTRA_VERSION}"
 

	
 
; NOTE: Keep trailing backslash!
 
InstallDirRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Install Folder"
 
OutFile "openttd-${APPVERSION}-${APPARCH}.exe"
 
CRCCheck force
 

	
 
ShowInstDetails show
 
ShowUninstDetails show
 

	
 
RequestExecutionLevel admin
 

	
 
Var SHORTCUTS
 
Var CDDRIVE
 

	
 
; Modern interface settings
 
!include "MUI2.nsh"
 
!include "InstallOptions.nsh"
 

	
 
!define MUI_ABORTWARNING
 
!define MUI_WELCOMEPAGE_TITLE_3LINES
 
!insertmacro MUI_PAGE_WELCOME
 
!insertmacro MUI_PAGE_LICENSE "..\..\..\COPYING"
 

	
 
!define MUI_COMPONENTSPAGE_SMALLDESC
 
!insertmacro MUI_PAGE_COMPONENTS
 

	
 
;---------------------------------
 
; Custom page for finding TTDLX CD
 
Page custom SelectCDEnter SelectCDExit ": TTD folder"
 

	
 
!insertmacro MUI_PAGE_DIRECTORY
 

	
 
;Start Menu Folder Page Configuration
 
!define MUI_STARTMENUPAGE_DEFAULTFOLDER $SHORTCUTS
 
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKEY_LOCAL_MACHINE"
 
@@ -87,121 +89,142 @@ Page custom SelectCDEnter SelectCDExit "
 
!define MUI_FINISHPAGE_LINK_LOCATION "${APPURLLINK}"
 
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
 
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\readme.txt"
 
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
 
!define MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT DisableBack
 

	
 
!insertmacro MUI_PAGE_FINISH
 
!define MUI_PAGE_HEADER_TEXT "Uninstall ${APPNAMEANDVERSION}"
 
!insertmacro MUI_UNPAGE_CONFIRM
 
!insertmacro MUI_UNPAGE_INSTFILES
 

	
 
; Set languages (first is default language)
 
!insertmacro MUI_LANGUAGE "English"
 
!insertmacro MUI_RESERVEFILE_LANGDLL
 

	
 
;--------------------------------------------------------------
 
; (Core) OpenTTD install section. Copies all internal game data
 
Section "!OpenTTD" Section1
 
	; Make sure to be upgraded OpenTTD is not running
 
	Call CheckOpenTTDRunning
 

	
 
	; Overwrite files by default, but don't complain on failure
 
	SetOverwrite try
 

	
 
	SetShellVarContext all
 

	
 
	; Define root variable relative to installer
 
	!define PATH_ROOT "..\..\..\"
 

	
 
	; Copy language files
 
	SetOutPath "$INSTDIR\lang\"
 
	File ${PATH_ROOT}bin\lang\english.lng
 

	
 
	; Copy AI files
 
	SetOutPath "$INSTDIR\ai\"
 
	File ${PATH_ROOT}bin\ai\compat_*.nut
 

	
 
	; Copy data files
 
	SetOutPath "$INSTDIR\data\"
 
	File ${PATH_ROOT}bin\data\*.grf
 
	File ${PATH_ROOT}bin\data\*.obg
 
	File ${PATH_ROOT}bin\data\*.obs
 
	File ${PATH_ROOT}bin\data\opntitle.dat
 

	
 
	; Copy the music base metadata files
 
	SetOutPath "$INSTDIR\gm\"
 
	File ${PATH_ROOT}bin\gm\*.obm
 

	
 
	; Copy the scripts
 
	SetOutPath "$INSTDIR\scripts\"
 
	File ${PATH_ROOT}bin\scripts\*.*
 
	Push "$INSTDIR\scripts\readme.txt"
 
	Call unix2dos
 

	
 
	; Copy some documention files
 
	SetOutPath "$INSTDIR\docs\"
 
	File ${PATH_ROOT}docs\multiplayer.txt
 
	Push "$INSTDIR\docs\multiplayer.txt"
 
	Call unix2dos
 
	File ${PATH_ROOT}docs\32bpp.txt
 
	Push "$INSTDIR\docs\32bpp.txt"
 
	Call unix2dos
 

	
 
	; Copy the rest of the stuff
 
	SetOutPath "$INSTDIR\"
 

	
 
	; Copy text files
 
	File ${PATH_ROOT}changelog.txt
 
	Push "$INSTDIR\changelog.txt"
 
	Call unix2dos
 
	File ${PATH_ROOT}COPYING
 
	Push "$INSTDIR\COPYING"
 
	Call unix2dos
 
	File ${PATH_ROOT}readme.txt
 
	Push "$INSTDIR\readme.txt"
 
	Call unix2dos
 
	File ${PATH_ROOT}known-bugs.txt
 
	Push "$INSTDIR\known-bugs.txt"
 
	Call unix2dos
 

	
 
	; Copy executable
 
	File /oname=openttd.exe ${BINARY_DIR}\openttd.exe
 

	
 

	
 
	; Delete old files from the main dir. they are now placed in data/ and lang/
 
	Delete "$INSTDIR\*.lng"
 
	Delete "$INSTDIR\*.grf"
 
	Delete "$INSTDIR\sample.cat"
 
	Delete "$INSTDIR\ttd.exe"
 

	
 

	
 
	; Create the Registry Entries
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Comments" "Visit ${APPURLLINK}"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "DisplayIcon" "$INSTDIR\openttd.exe,0"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "DisplayName" "OpenTTD ${APPVERSION}"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "DisplayVersion" "${APPVERSION}"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "HelpLink" "${APPURLLINK}"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Install Folder" "$INSTDIR"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Publisher" "OpenTTD"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Shortcut Folder" "$SHORTCUTS"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "UninstallString" "$INSTDIR\uninstall.exe"
 
	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "URLInfoAbout" "${APPURLLINK}"
 
	; This key sets the Version DWORD that new installers will check against
 
	WriteRegDWORD HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Version" ${INSTALLERVERSION}
 

	
 
	!insertmacro MUI_STARTMENU_WRITE_BEGIN "OpenTTD"
 
	CreateShortCut "$DESKTOP\OpenTTD.lnk" "$INSTDIR\openttd.exe"
 
	CreateDirectory "$SMPROGRAMS\$SHORTCUTS"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\OpenTTD.lnk" "$INSTDIR\openttd.exe"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Uninstall.lnk" "$INSTDIR\uninstall.exe"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Readme.lnk" "$INSTDIR\Readme.txt"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Changelog.lnk" "$INSTDIR\Changelog.txt"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Known-bugs.lnk" "$INSTDIR\known-bugs.txt"
 
	CreateDirectory "$SMPROGRAMS\$SHORTCUTS\Docs"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Docs\Multiplayer.lnk" "$INSTDIR\docs\multiplayer.txt"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Docs\32bpp.lnk" "$INSTDIR\docs\32bpp.txt"
 
	CreateDirectory "$SMPROGRAMS\$SHORTCUTS\Scripts"
 
	CreateShortCut "$SMPROGRAMS\$SHORTCUTS\Scripts\Readme.lnk" "$INSTDIR\scripts\readme.txt"
 
	!insertmacro MUI_STARTMENU_WRITE_END
 
SectionEnd
 

	
 
;--------------------------------------------------------------
 
; OpenTTD translation install section. Copies only translations
 
Section "OpenTTD translations" Section6
 
	; Overwrite files by default, but don't complain on failure
 
	SetOverwrite try
 

	
 
	; Copy language files
 
	SetOutPath "$INSTDIR\lang\"
 
	File ${PATH_ROOT}bin\lang\*.lng
 
SectionEnd
 

	
 
;----------------------------------------------------------------------------------
 
; OpenGFX files install section. Downloads OpenGFX and installs it
 
Section "Download OpenGFX (free graphics set)" Section3
 
	SetOverwrite try
 

	
 
	NSISdl::download "http://binaries.openttd.org/installer/opengfx-${OPENGFX_BASE_VERSION}.7z" "$INSTDIR\data\opengfx.7z"
 
	Pop $R0 ;Get the return value
 
	StrCmp $R0 "success" +3
 
		MessageBox MB_OK "Downloading of OpenGFX failed"
 
		Goto Done
 
@@ -280,86 +303,91 @@ Section /o "Copy data from Transport Tyc
 
	CopyFiles "$CDDRIVE\trgi.grf" "$INSTDIR\data\trgi.grf" 334
 
	CopyFiles "$CDDRIVE\trgt.grf" "$INSTDIR\data\trgt.grf" 546
 
	SetOutPath "$INSTDIR\"
 
SectionEnd
 

	
 
;-------------------------------------------
 
; Install the uninstaller (option is hidden)
 
Section -FinishSection
 
	WriteUninstaller "$INSTDIR\uninstall.exe"
 
SectionEnd
 

	
 
; Modern install component descriptions
 
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section1} "Minimal OpenTTD installation in English. You need at least one of the game graphics and sound sets installed."
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section6} "Translations of OpenTTD."
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section3} "Download the free OpenGFX game graphics set. This download is about 3 MiB."
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section4} "Download the free OpenSFX game sound set. This download is about 10 MiB."
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section5} "Download the free OpenMSX game music set. This download is about 200 KiB."
 
	!insertmacro MUI_DESCRIPTION_TEXT ${Section2} "Copies the game graphics, sounds and music from the Transport Tycoon Deluxe CD."
 
!insertmacro MUI_FUNCTION_DESCRIPTION_END
 

	
 
;-----------------------------------------------
 
; Uninstall section, deletes all installed files
 
Section "Uninstall"
 
	SetShellVarContext all
 

	
 
	MessageBox MB_YESNO|MB_ICONQUESTION \
 
		"Remove the save game folders located at $\"$INSTDIR\save?$\"$\n \
 
		If you choose Yes, your saved games will be deleted." \
 
		IDYES RemoveSavedGames IDNO NoRemoveSavedGames
 
	RemoveSavedGames:
 
		Delete "$INSTDIR\save\autosave\*"
 
		RMDir "$INSTDIR\save\autosave"
 
		Delete "$INSTDIR\save\*"
 
		RMDir "$INSTDIR\save"
 
	NoRemoveSavedGames:
 

	
 
	MessageBox MB_YESNO|MB_ICONQUESTION \
 
		"Remove the scenario folders located at $\"$INSTDIR\scenario?$\"$\n \
 
		If you choose Yes, your scenarios will be deleted." \
 
		IDYES RemoveScen IDNO NoRemoveScen
 
	RemoveScen:
 
		Delete "$INSTDIR\scenario\heightmap*"
 
		RMDir "$INSTDIR\scenario\heightmap"
 
		Delete "$INSTDIR\scenario\*"
 
		RMDir "$INSTDIR\scenario"
 
	NoRemoveScen:
 

	
 
	; Remove from registry...
 
	!insertmacro MUI_STARTMENU_GETFOLDER "OpenTTD" $SHORTCUTS
 
	ReadRegStr $SHORTCUTS HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Shortcut Folder"
 

	
 
	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD"
 

	
 
	; Delete self
 
	Delete "$INSTDIR\uninstall.exe"
 

	
 
	; Delete Shortcuts
 
	Delete "$DESKTOP\OpenTTD.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\OpenTTD.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Uninstall.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Readme.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Changelog.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Known-bugs.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Docs\Multiplayer.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Docs\32bpp.lnk"
 
	Delete "$SMPROGRAMS\$SHORTCUTS\Scripts\Readme.lnk"
 

	
 
	; Clean up OpenTTD dir
 
	Delete "$INSTDIR\changelog.txt"
 
	Delete "$INSTDIR\readme.txt"
 
	Delete "$INSTDIR\known-bugs.txt"
 
	Delete "$INSTDIR\openttd.exe"
 
	Delete "$INSTDIR\COPYING"
 
	Delete "$INSTDIR\INSTALL.LOG"
 
	Delete "$INSTDIR\crash.log"
 
	Delete "$INSTDIR\crash.dmp"
 
	Delete "$INSTDIR\openttd.cfg"
 
	Delete "$INSTDIR\hs.dat"
 
	Delete "$INSTDIR\cached_sprites.*"
 
	Delete "$INSTDIR\save\autosave\network*.tmp" ; temporary network file
 

	
 
	; AI files
 
	Delete "$INSTDIR\ai\compat_*.nut"
 

	
 
	; Data files
 
	Delete "$INSTDIR\data\opntitle.dat"
 

	
 
	Delete "$INSTDIR\data\2ccmap.grf"
 
	Delete "$INSTDIR\data\airports.grf"
 
	Delete "$INSTDIR\data\autorail.grf"
 
@@ -398,48 +426,50 @@ Section "Uninstall"
 

	
 
	; Downloaded OpenGFX/OpenSFX/OpenMSX
 
	Delete "$INSTDIR\data\opengfx\*"
 
	RMDir  "$INSTDIR\data\opengfx"
 
	Delete "$INSTDIR\data\opensfx\*"
 
	RMDir  "$INSTDIR\data\opensfx"
 
	Delete "$INSTDIR\gm\openmsx\*"
 
	RMDir  "$INSTDIR\gm\openmsx"
 

	
 
	; Language files
 
	Delete "$INSTDIR\lang\*.lng"
 

	
 
	; Scripts
 
	Delete "$INSTDIR\scripts\*.*"
 

	
 
	; Documentation
 
	Delete "$INSTDIR\docs\*.*"
 

	
 
	; Base sets for music
 
	Delete "$INSTDIR\gm\orig_win.obm"
 
	Delete "$INSTDIR\gm\no_music.obm"
 

	
 
	; Remove remaining directories
 
	RMDir "$SMPROGRAMS\$SHORTCUTS\Extras\"
 
	RMDir "$SMPROGRAMS\$SHORTCUTS\Scripts\"
 
	RMDir "$SMPROGRAMS\$SHORTCUTS\Docs\"
 
	RMDir "$SMPROGRAMS\$SHORTCUTS"
 
	RMDir "$INSTDIR\ai"
 
	RMDir "$INSTDIR\data"
 
	RMDir "$INSTDIR\gm"
 
	RMDir "$INSTDIR\lang"
 
	RMDir "$INSTDIR\scripts"
 
	RMDir "$INSTDIR\docs"
 
	RMDir "$INSTDIR"
 

	
 
SectionEnd
 

	
 
;------------------------------------------------------------
 
; Custom page function to find the TTDLX CD/install location
 
Function SelectCDEnter
 
	SectionGetFlags ${Section2} $0
 
	IntOp $1 $0 & 0x80 ; bit 7 set by upgrade, no need to copy files
 
	IntCmp $1 1 DoneCD ; Upgrade doesn't need copy files
 

	
 
	IntOp $0 $0 & 1
 
	IntCmp $0 1 NoAbort
 
	Abort
 
NoAbort:
 

	
 
	GetTempFileName $R0
 
@@ -535,48 +565,104 @@ WinNT:
 
	StrCmp ${APPARCH} "win9x" 0 Done
 
	MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "You are trying to install the Windows 95, 98 and ME version on Windows 2000, XP or Vista. This is not advised, but will work with reduced capabilities. We suggest that you download the correct version. Do you really want to continue?" IDOK Done IDCANCEL Abort
 
Abort:
 
	Quit
 
Done:
 
FunctionEnd
 

	
 
;-------------------------------------------------------------------------------
 
; Check whether OpenTTD is running
 
Function CheckOpenTTDRunning
 
	IfFileExists "$INSTDIR\openttd.exe" 0 Done
 
Retry:
 
	FindProcDLL::FindProc "openttd.exe"
 
	Pop $R0
 
	IntCmp $R0 1 0 Done
 
	ClearErrors
 
	Delete "$INSTDIR\openttd.exe"
 
	IfErrors 0 Done
 
	ClearErrors
 
	MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "OpenTTD is running. Please close it and retry." IDRETRY Retry
 
	Abort
 
Done:
 
FunctionEnd
 

	
 
;-------------------------------------------------------------------------------
 
; strips all CRs
 
; and then converts all LFs into CRLFs
 
; (this is roughly equivalent to "cat file | dos2unix | unix2dos")
 
;
 
; usage:
 
;    Push "infile"
 
;    Call unix2dos
 
;
 
; beware that this function destroys $0 $1 $2
 
Function unix2dos
 
	ClearErrors
 

	
 
	Pop $2
 
	Rename $2 $2.U2D
 
	FileOpen $1 $2 w
 

	
 
	FileOpen $0 $2.U2D r
 

	
 
	Push $2 ; save name for deleting
 

	
 
	IfErrors unix2dos_done
 

	
 
	; $0 = file input (opened for reading)
 
	; $1 = file output (opened for writing)
 

	
 
unix2dos_loop:
 
	; read a byte (stored in $2)
 
	FileReadByte $0 $2
 
	IfErrors unix2dos_done ; EOL
 
	; skip CR
 
	StrCmp $2 13 unix2dos_loop
 
	; if LF write an extra CR
 
	StrCmp $2 10 unix2dos_cr unix2dos_write
 

	
 
unix2dos_cr:
 
	FileWriteByte $1 13
 

	
 
unix2dos_write:
 
	; write byte
 
	FileWriteByte $1 $2
 
	; read next byte
 
	Goto unix2dos_loop
 

	
 
unix2dos_done:
 
	; close files
 
	FileClose $0
 
	FileClose $1
 

	
 
	; delete original
 
	Pop $0
 
	Delete $0.U2D
 

	
 
FunctionEnd
 

	
 

	
 
Var OLDVERSION
 
Var UninstallString
 

	
 
;-----------------------------------------------------------------------------------
 
; NSIS Initialize function, determine if we are going to install/upgrade or uninstall
 
Function .onInit
 
	StrCpy $SHORTCUTS "OpenTTD"
 

	
 
	SectionSetSize ${Section3} 6144
 
	SectionSetSize ${Section4} 13312
 
	SectionSetSize ${Section5} 1024
 

	
 
	SectionSetFlags 0 17
 

	
 
	; Starts Setup - let's look for an older version of OpenTTD
 
	ReadRegDWORD $R8 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Version"
 

	
 
	IfErrors ShowWelcomeMessage ShowUpgradeMessage
 
ShowWelcomeMessage:
 
	ReadRegStr $R8 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenTTD" "Version"
 
	; In the event someone still has OpenTTD 0.1, this will detect that (that installer used a string instead of dword entry)
 
	IfErrors FinishCallback
 

	
 
ShowUpgradeMessage:
0 comments (0 inline, 0 general)