Source Mod Installers: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 157: Line 157:
* [http://nsis.sourceforge.net/wiki/Main_Page NSIS Wiki]
* [http://nsis.sourceforge.net/wiki/Main_Page NSIS Wiki]
* [http://nsis.sourceforge.net/wiki/ZipDLL ZipDLL] — Use this to possibly compress your installer
* [http://nsis.sourceforge.net/wiki/ZipDLL ZipDLL] — Use this to possibly compress your installer
* [http://www.iconxp.com/ IconXP] :It's a great icon application with a trial version available (link is broken)
* [http://www.iconxp.com/ IconXP]
:It's a great icon application with a trial version available (link is broken)
[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Modding]]
[[Category:Modding]]

Revision as of 07:53, 18 December 2005

Extra thanks to User:Garry Newman for relaying the basics of a mod installer.

For this, you need NSIS and HM NIS Edit.

Note.pngNote:The steam restart script block requires FindProc to be installed in your NSIS Plugins folder.
Note.pngNote:To automate the file list, use the NSIS Script Wizard in HM NIS Edit, then copy the list to your setup.nsi.
Note.pngNote:You might want to be sure to include a ZIP-compressed version of the mod as a download. This will make certain people who do not like third-party setup files will be able to get the mod.

Code from setup.nsi

!define PRODUCT_NAME "Mod's Name"

!define PRODUCT_VERSION "Release Version"

!define PRODUCT_PUBLISHER "Mod Team/Company Name"

!define PRODUCT_WEB_SITE "Mod Website"

!define MODDIR "Mod's root directory"
;(i.e. cstrike)

!define MUI_ICON "Installer Icon"
;This is the location on the local computer where the icon for the installer executable is.

!define FULL_GAME_NAME "Full Game Name"
;This is the name of the game defined in gameinfo.txt
;Remove all colons from this (as well as any other invalid char in a file name)

!define DESKICO "Desktop Icon"
;This is the location on the local computer where the icon for the desktop icon for the game is.
;The icon name must be the same as the one in gameinfo.txt
;Remove all colons from this (as well as any other invalid char in a file name)

;Uncomment this if you do not wish to have a custom desktop icon:
;!define NO_DESKTOP_ICON

;Uncomment this if you want to use ZipDLL
;!define ZIPDLL

;Uncomment this if you want to use the restart steam script
;!define RESTARTSTEAM

!ifdef ZIPDLL
	!include "zipdll.nsh"
!endif

var ICONDIR
var STEAMEXE

!include "MUI.nsh"
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
ShowInstDetails show

Section "Mod Files" SEC01
	SetOverwrite ifdiff
!ifdef ZIPDLL
	File "C:\...\zipfile.zip"
	StrCpy $R0 "$INSTDIR\zipfile.zip"
	ZipDLL::extractall "$R0" "$INSTDIR"
	Delete "$R0"
!else
	SetOutPath "$INSTDIR"
	;!! CHANGE THE LINE BELOW - /r tells it to include all files and dirs below this path
	File /r "x:\path\to\your\mod\directory\"
!endif

!ifndef NO_DESKTOP_ICON
	SetOutPath "$ICONDIR"
	File "${DESKICO}"
!endif

SectionEnd
!ifndef NO_DESKTOP_ICON
Section "Desktop Shortcut" SEC02
	SetOutPath "$DESKTOP"
	CreateShortcut "${FULL_GAME_NAME}.lnk" $STEAMEXE \
		'-applaunch 220 -game "$INSTDIR"' "$ICONDIR\${FULL_GAME_NAME}.ico"
SectionEnd
!endif
!ifdef RESTARTSTEAM
Page custom Finish
Function TickCountStart
	!define TickCountStart `!insertmacro TickCountStartCall`

	!macro TickCountStartCall
		Call TickCountStart
	!macroend

	Push $0
	System::Call 'kernel32::GetTickCount()i .r0'
	Exch $0
FunctionEnd

Function TickCountEnd
	!define TickCountEnd `!insertmacro TickCountEndCall`

	!macro TickCountEndCall _RESULT
		Call TickCountEnd
		Pop ${_RESULT}
	!macroend

	Exch $0
	Push $1
	System::Call 'kernel32::GetTickCount()i .r1'
	System::Int64Op $1 - $0
	Pop $0
	Pop $1
	Exch $0
FunctionEnd
Function Finish
  ReadRegStr $R0 HKCU "Software\Valve\Steam\Steam.exe" UpTimeStart
  StrCmp $R0 0 final 0
  MessageBox MB_YESNO|MB_ICONEXCLAMATION "Steam must be restarted for the game to show on the games list.$\r$\nWould you like the installer to restart steam for you?$\r$\n$\r$\n(Restart may take a while)$\r$\nInstaller will timeout after 30 seconds." IDNO final
  ReadRegStr $R1 HKCU "Software\Valve\Steam" SteamExe
  ExecWait '"$R1" "-shutdown"'
  loop:
  ${TickCountStart}
  FindProcDLL::FindProc "steam.exe"
  StrCmp $R0 1 0 exit
  ${TickCountEnd} $R3
  IntOp $R4 $R4 + $R3
  IntCmp $R4 30000 timeout loop timeout
  exit:
  Exec '"$R1"'
  Goto final
  timeout:
  MessageBox MB_OK|MB_ICONINFORMATION "$R4$\r$\nSteam restart timed out"
  final:
  MessageBox MB_OK "Installation was successful"
FunctionEnd
!endif
Function .onInit
	ReadRegStr $R0 HKLM "Software\Valve\Steam" InstallPath
	ReadRegStr $R1 HKCU "Software\Valve\Steam" SourceModInstallPath
	IfErrors lbl_error 0
	StrCpy $INSTDIR "$R1\${MODDIR}"
!ifndef NO_DESKTOP_ICON
	StrCpy $ICONDIR "$R0\steam\games"
	SectionSetFlags ${SEC02} 0
!endif
	SectionSetFlags ${SEC01} 17
	StrCpy $STEAMEXE "$R0\steam.exe"
	Return
	lbl_error:
		ClearErrors
		SectionSetFlags ${SEC01} 16
FunctionEnd

See Also

It's a great icon application with a trial version available (link is broken)