gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
show an example of nsis installer code for game
- User
show an example of nsis installer code for game
- Assistant
show an example of nsis installer code for game
The code below demonstrates an example of NSIS (Nullsoft Scriptable Install System) installer script for a game.
; NSIS installer script for a game
; Define some basic properties
Outfile "Game_Installer.exe"
InstallDir $PROGRAMFILES\MyGame
RequestExecutionLevel admin
; Define the default page settings
!include "MUI2.nsh"
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\aring.ico"
; Define the game data directory
!define GAME_DATA "GameFiles"
; Define the components for installation
Page components
Page directory
Page instfiles
; Define the components available for selection
Section "Game" Section_Game
SetOutPath $INSTDIR
; Copy the game data to the install directory
File /r "${GAME_DATA}\*.*"
; Create a shortcut in the Start menu
CreateDirectory $SMPROGRAMS\MyGame
CreateShortCut "$SMPROGRAMS\MyGame\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
CreateShortCut "$SMPROGRAMS\MyGame\MyGame.lnk" "$INSTDIR\Game.exe"
SectionEnd
Section "Desktop Shortcut" Section_Desktop
CreateShortCut "$DESKTOP\MyGame.lnk" "$INSTDIR\MyGame.exe"
SectionEnd
; The uninstall section
Section "Uninstall"
Delete "$INSTDIR\Uninstall.exe"
; Remove the game files
RMDir /r "$INSTDIR"
; Remove the Start menu shortcuts
Delete "$SMPROGRAMS\MyGame\Uninstall.lnk"
Delete "$SMPROGRAMS\MyGame\MyGame.lnk"
RMDir "$SMPROGRAMS\MyGame"
; Remove the desktop shortcut if it exists
Delete "$DESKTOP\MyGame.lnk"
; Remove the registry entries
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyGame"
SectionEnd
; Define the uninstaller
Function un.onInit
MessageBox MB_OK "This will uninstall MyGame from your computer."
FunctionEnd
Function .onInit
; Check if application is already installed
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyGame" "InstallLocation"
StrCmp $R0 "" done
MessageBox MB_OK|MB_ICONSTOP "MyGame is already installed. Please uninstall the previous version first."
Abort
done:
FunctionEnd
; Define the installer's sections that will act as the pages
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
; Define the language for the installer
!insertmacro MUI_LANGUAGE "English"
; Solid file compression
SetCompress auto
SetCompressor /SOLID lzma
In this example, we define the installation properties, such as the output file, installation directory, and some default page settings. We then define the components for installation, including copying the game files, shortcuts, and uninstaller information. Finally, we specify the installer's sections and language for the installation process.
Not yet included in a published release.