Creating a mod exe installer guide
Jump to navigation
Jump to search

Installation folder step with Witcher Kings installer
This guide explains how to create a Windows .exe installer for a CK2 mod, with NSIS.
An installer will prevent the most frequent causes of a mod not working, reducing the support needed:
- forgetting to remove previous mod version
- unzipping in wrong folder
- black flags due to an outdated gfx cache
But it may have some drawbacks:
- .exe files may cause false positive with some antivirus
- .exe files may be restricted to upload (ex: forum)
Steps[edit | edit source]
- Install NSIS-2.46.5-Unicode
- Create a setup.nsi file in same folder as .mod file (see #Sample script)
- Right-click and select Compile NSIS Unicode script
- Rename the .exe with version number, if needed.
Sample script[edit | edit source]
This script is based on When The World Stopped Making Sense setup.nsi script, replacing the mod name by MyMod.
Comments start with ; character.
Note that ;!insertmacro MUI_PAGE_COMPONENTS
may be uncommented to display an intermediate page to let user select modules to install. Same behavior can be achieved by installing everything, and letting player select the sub-mods to activate in the launcher.
; Simple CK2 mod manual installer for Windows ; To generate the installer, download NSIS Unicode 2.46.5 from https://code.google.com/p/unsis/downloads/list ; and launch "Compile NSIS Unicode script" from context menu. ; Unicode is needed to support French accents. ; NSIS documentation: ; - MUI: http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html ; - Scripting reference: http://nsis.sourceforge.net/Docs/Chapter4.html !include "MUI2.nsh" ; Mod configuration defined in .mod file, to know which folders to cleanup. !define mod_path "MyMod" !define mod_user_dir "MyMod" ; The name of the installer Name "MyMod" ; The file to write OutFile "MyMod-setup.exe" ; The default installation directory InstallDir "$DOCUMENTS\Paradox Interactive\Crusader Kings II\mod" ; Request application privileges for Windows Vista RequestExecutionLevel user ; --------------------------- ; Interface settings (optional) ; --------------------------- !define MUI_ICON "MyMod.ico" ; Bitmap for the Welcome page and the Finish page (164x314 pixels) !define MUI_WELCOMEFINISHPAGE_BITMAP "MyMod.bmp" !define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH ; --------------------------- ; Pages: Language -> Welcome -> Directory -> Install -> Finish ; --------------------------- !define MUI_WELCOMEPAGE_TITLE $(MUI_WELCOMEPAGE_TITLE) !define MUI_WELCOMEPAGE_TITLE_3LINES !define MUI_WELCOMEPAGE_TEXT $(MUI_WELCOMEPAGE_TEXT) !insertmacro MUI_PAGE_WELCOME ; To simplify, do not display components page: all are installed ;!insertmacro MUI_PAGE_COMPONENTS !define MUI_DIRECTORYPAGE_TEXT_DESTINATION $(MUI_DIRECTORYPAGE_TEXT_DESTINATION) !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_FINISHPAGE_TITLE $(MUI_FINISHPAGE_TITLE) !define MUI_FINISHPAGE_TEXT $(MUI_FINISHPAGE_TEXT) !define MUI_FINISHPAGE_TEXT_LARGE !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\ChangeLog.txt" ;!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !define MUI_FINISHPAGE_SHOWREADME_TEXT $(MUI_FINISHPAGE_SHOWREADME_TEXT) !define MUI_FINISHPAGE_LINK $(MUI_FINISHPAGE_LINK) !define MUI_FINISHPAGE_LINK_LOCATION "http://MyModPage" !define MUI_FINISHPAGE_NOREBOOTSUPPORT !insertmacro MUI_PAGE_FINISH ;Languages - needs to be after page declarations !insertmacro MUI_LANGUAGE English ;First language is the default if a better match is not found !insertmacro MUI_LANGUAGE French ; Display Language selection dialog Function .onInit !insertmacro MUI_LANGDLL_DISPLAY FunctionEnd ; Un-install main mod Section "Uninstall previous" ; Remove directories and files recursively ; Only delete <path> folder of main mod, in case some files are removed from folders ; .mod files and other sub-mod files will always get overwritten during install. RMDir /r "$INSTDIR\${mod_path}" SectionEnd ; Clean gfx cache Section "Clean gfx cache" ; Delete <user_dir>/gfx folder RMDir /r "$INSTDIR\..\${mod_user_dir}\gfx" SectionEnd ;-------------------------------- ; Install mod and sub-mods Section "Install" ; Set output path to the installation directory. SetOutPath "$INSTDIR" ; Copy mod files (excluding configuration files) File "ChangeLog.txt" ; Copy changelog to open it after installation File "*.mod" ; Copy all .mod descriptors File /r /x "*.exe" "${mod_path}*" ; Note: sub-mod paths start with same as main mod path SectionEnd ; --------------------------- ; Localization ; --------------------------- ; English LangString MUI_WELCOMEPAGE_TITLE ${LANG_ENGLISH} "MyMod$" LangString MUI_WELCOMEPAGE_TEXT ${LANG_ENGLISH} "This installer will:$\r$\n \ 1) Remove any previously installed version of the mod$\r$\n \ 2) Clean the mod gfx cache$\r$\n \ 3) Install the mod to your mod folder$\r$\n" LangString MUI_DIRECTORYPAGE_TEXT_DESTINATION ${LANG_ENGLISH} "Please select your CK2 mod folder" LangString MUI_FINISHPAGE_TITLE ${LANG_ENGLISH} "MyMod has been installed" LangString MUI_FINISHPAGE_TEXT ${LANG_ENGLISH} "To play:$\r$\n \ - Open CK2 launcher.$\r$\n \ - Select the mod 'MyMod' in the Mod tab of the launcher.$\r$\n \ - Enjoy !$\r$\n" LangString MUI_FINISHPAGE_SHOWREADME_TEXT ${LANG_ENGLISH} "Open the Changelog" LangString MUI_FINISHPAGE_LINK ${LANG_ENGLISH} "Go to MyMod forum" ; French LangString MUI_WELCOMEPAGE_TITLE ${LANG_FRENCH} "MyMod" LangString MUI_WELCOMEPAGE_TEXT ${LANG_FRENCH} "Cet installateur va:$\r$\n \ 1) Supprimer toute ancienne version du mod precédement installée$\r$\n \ 2) Vider votre cache de gfx du mod$\r$\n \ 3) Installer le mod dans votre répertoire de mods$\r$\n" LangString MUI_DIRECTORYPAGE_TEXT_DESTINATION ${LANG_FRENCH} "Merci de sélectionner votre répertoire de mods CK2" LangString MUI_FINISHPAGE_TITLE ${LANG_FRENCH} "MyMod a été installé" LangString MUI_FINISHPAGE_TEXT ${LANG_FRENCH} "Pour jouer:$\r$\n \ - Lancez CK2.$\r$\n \ - Sélectionnez le mod 'MyMod' dans la section Mod.$\r$\n \ - Sélectionnez UNIQUEMENT les sous-mods graphiques pour MyMod pour lesquels vous possédez les DLCs requis.$\r$\n \ - Profitez !$\r$\n" LangString MUI_FINISHPAGE_SHOWREADME_TEXT ${LANG_FRENCH} "Ouvrir le Changelog (en anglais)" LangString MUI_FINISHPAGE_LINK ${LANG_FRENCH} "Accéder au forum MyMod"