Source Mod Installers: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 3: Line 3:
For this, you need [http://nsis.sourceforge.net/ NSIS] and [http://hmne.sourceforge.net/ HM NIS Edit].
For this, you need [http://nsis.sourceforge.net/ NSIS] and [http://hmne.sourceforge.net/ HM NIS Edit].


Use the following code where:
{{note|To automate the file list, use the NSIS Script Wizard in HM NIS Edit, then copy the list to your <code>setup.nsi</code>.}}
* <code>##MODNAME##</code> is the Mod name.
* <code>##MODVERSION##</code> is the installer's release version.
* <code>##MODTEAM##</code> is the Mod's team.
* <code>##MODURL##</code> is the Mod's website.
* <code>##MODDIR##</code> is the Mod's root directory (i.e. <code>cstrike</code>).
* <code>##INSTICO##</code> is the location on the local computer where the icon for the installer executable is.
* <code>##DESKICO##</code> is the location on the local computer where the icon for the desktop icon for the game is.
* <code>##FILE1##</code> is the first file you wish to install in the mod folder.
* <code>##FILE2##</code> is the second file you wish to install in the mod folder.
* <code>##FILEX##</code> is the last file you wish to install in the mod folder.
{{note|To automate the FILE1-FILEX list, use the NSIS Script Wizard in HM NIS Edit, then copy the list to your <code>setup.nsi</code>.}}


{{note|You might want to be sure to include a [[Wikipedia:ZIP (file format)|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.}}
{{note|You might want to be sure to include a [[Wikipedia:ZIP (file format)|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=
=Code from setup.nsi=
<pre>!define PRODUCT_NAME "##MODNAME##"
<pre>
!define PRODUCT_VERSION "##MODVERSION##"
!define PRODUCT_NAME "Mod's Name"
!define PRODUCT_PUBLISHER "##MODTEAM##"
 
!define PRODUCT_WEB_SITE "##MODURL##"
!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
 
!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


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


!include "MUI.nsh"
!include "MUI.nsh"
Line 41: Line 45:
   SetOverwrite ifdiff
   SetOverwrite ifdiff
   SetOutPath "$INSTDIR"
   SetOutPath "$INSTDIR"
  File "##FILE1##"
;!!!!AT THIS POINT, YOU SHOULD ADD A LIST OF LOCAL FILES TO INSTALL
  File "##FILE2##"
;File "Blah"
  File "##FILEX##"
;File directories are local


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


SectionEnd
SectionEnd
 
!ifndef NO_DESKTOP_ICON
Section "Desktop Shortcut" SEC02
      SetOutPath "$DESKTOP"
      CreateShortcut "${PRODUCT_NAME}.lnk" $STEAMEXE `-applaunch 220 -game "$INSTDIR"` "$ICONDIR\${FULL_GAME_NAME}.ico"
SectionEnd
!endif
Function .onInit
Function .onInit
        ReadRegStr $0 HKLM "Software\Valve\Steam" InstallPath
      ReadRegStr $R0 HKLM "Software\Valve\Steam" InstallPath
        ReadRegStr $1 HKCU "Software\Valve\Steam" SourceModInstallPath
      ReadRegStr $R1 HKCU "Software\Valve\Steam" SourceModInstallPath
        IfErrors 0 lbl_end
      IfErrors lbl_error 0
        ClearErrors
      StrCpy $INSTDIR "$R1\${MODDIR}"
        StrCpy $0 "$PROGRAMFILES\Valve\Steam"
        StrCpy $1 "$PROGRAMFILES\Valve\Steam\SteamApps\SourceMods"
        lbl_end:
                StrCpy $INSTDIR "$1\##MODDIR##"
!ifndef NO_DESKTOP_ICON
!ifndef NO_DESKTOP_ICON
                StrCpy $2 "$0\steam\games"
      StrCpy $ICONDIR "$R0\steam\games"
      SectionSetFlags ${SEC02} 0
!endif
!endif
      SectionSetFlags ${SEC01} 17
      StrCpy $STEAMEXE "$R0\steam.exe"
      Return
      lbl_error:
            ClearErrors
            SectionSetFlags ${SEC01} 16
FunctionEnd</pre>
FunctionEnd</pre>



Revision as of 21:55, 21 October 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: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

!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

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

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

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

Section "Mod" SEC01
  SetOverwrite ifdiff
  SetOutPath "$INSTDIR"
;!!!!AT THIS POINT, YOU SHOULD ADD A LIST OF LOCAL FILES TO INSTALL
;File "Blah"
;File directories are local

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

SectionEnd
!ifndef NO_DESKTOP_ICON
Section "Desktop Shortcut" SEC02
      SetOutPath "$DESKTOP"
      CreateShortcut "${PRODUCT_NAME}.lnk" $STEAMEXE `-applaunch 220 -game "$INSTDIR"` "$ICONDIR\${FULL_GAME_NAME}.ico"
SectionEnd
!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