Skip to content

Commit

Permalink
Add NSIS installer creation script
Browse files Browse the repository at this point in the history
  • Loading branch information
YorVeX committed Jul 22, 2023
1 parent a98098a commit 470d82b
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 67 deletions.
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"gruntfuggly.todo-tree",
"idleberg.nsis"
]
}
155 changes: 88 additions & 67 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,90 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "publish (win-x64)",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Release",
"-o",
"publish\\win-x64",
"-r",
"win-x64",
"/p:DefineConstants=WINDOWS",
"/p:NativeLib=Shared",
"/p:SelfContained=true"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "publish and release (WSL linux-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts/wsl"
},
"command": ".\\build-linux-x64-wsl.cmd"
},
{
"label": "test (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\test.local.cmd"
},
{
"label": "publish and test (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\test.local.cmd",
"dependsOrder": "sequence",
"dependsOn": [
"publish (win-x64)"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish and release (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\release-win-x64.cmd",
"dependsOrder": "sequence",
"dependsOn": [
"publish (win-x64)"
],
"problemMatcher": "$msCompile"
}
]
"version": "2.0.0",
"tasks": [
{
"label": "publish (win-x64)",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Release",
"-o",
"publish\\win-x64",
"-r",
"win-x64",
"/p:DefineConstants=WINDOWS",
"/p:NativeLib=Shared",
"/p:SelfContained=true"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "publish and release (WSL linux-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts/wsl"
},
"command": ".\\build-linux-x64-wsl.cmd"
},
{
"label": "test (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\test.local.cmd"
},
{
"label": "publish and test (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\test.local.cmd",
"dependsOrder": "sequence",
"dependsOn": [
"publish (win-x64)"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish and release (win-x64)",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/scripts"
},
"command": ".\\release-win-x64.cmd",
"dependsOrder": "sequence",
"dependsOn": [
"publish (win-x64)"
],
"problemMatcher": "$msCompile"
},
{
"label": "Build win-x64 Installer",
"type": "shell",
"command": "makensis",
"args": [
"/V3",
"scripts\\xObsBrowserAutoRefresh-Installer.nsi"
],
"group": "build"
},
{
"label": "Build win-x64 Installer (strict)",
"type": "shell",
"command": "makensis",
"args": [
"/V3",
"/WX",
"scripts\\xObsBrowserAutoRefresh-Installer.nsi"
],
"group": "build"
}
]
}
Binary file added img/xObsBrowserAutoRefresh-Icon.ico
Binary file not shown.
Binary file added img/xObsBrowserAutoRefresh-SplashScreen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 147 additions & 0 deletions scripts/xObsBrowserAutoRefresh-Installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
Unicode True

!define AUTHOR "YorVeX"

; Automatically detect the name of the parent directory to use it as the app name
!tempfile MYINCFILE
!system 'for %I in (..\.) do echo !define APPNAME "%~nxI" > "${MYINCFILE}"'
!include "${MYINCFILE}"
!delfile "${MYINCFILE}"
!define APPDISPLAYNAME "${APPNAME} OBS Plugin"

; Automatically detect the version of the library in the publish folder to use it as the app version
!getdllversion "..\publish\win-x64\${APPNAME}.dll" ver
!define VERSION "${ver1}.${ver2}.${ver3}.${ver4}"
!define DISPLAY_VERSION "v${ver1}.${ver2}.${ver3}"
VIProductVersion "${VERSION}"
VIAddVersionKey "ProductName" "${APPNAME}"
VIAddVersionKey "FileVersion" "${VERSION}"
VIAddVersionKey "VIProductVersion" "${VERSION}"
VIAddVersionKey "LegalCopyright" "Copyright (c) 2023 ${AUTHOR}, https://github.com/${AUTHOR}"
VIAddVersionKey "FileDescription" "${APPDISPLAYNAME}"

; Main install settings
Name "${APPDISPLAYNAME} ${DISPLAY_VERSION}"
Caption "Automatic browser source refresh plugin for OBS Studio"
Icon "..\img\${APPNAME}-Icon.ico"
UninstallIcon "..\img\${APPNAME}-Icon.ico"
InstallDirRegKey HKLM "Software\${APPNAME}" ""
InstallDir "$PROGRAMFILES64\obs-studio"
OutFile "..\release\win-x64\${APPNAME}-win-x64-installer.exe"
SetCompressor LZMA

; Define splash screen
Function .onInit
InitPluginsDir
SetOutPath "$PLUGINSDIR"

File "/oname=$PLUGINSDIR\Splash.jpg" "..\img\${APPNAME}-SplashScreen.jpg"
; Need to download and install this plugin for this to work: https://nsis.sourceforge.io/NewAdvSplash_plug-in (the default plugins can only use BMP files)
newadvsplash::show 1500 500 500 0x04025C /NOCANCEL "$PLUGINSDIR\Splash.jpg"
Delete "$PLUGINSDIR\Splash.jpg"
FunctionEnd

; Modern interface settings
!include "MUI.nsh"

!define MUI_ABORTWARNING
!define MUI_ICON "..\img\${APPNAME}-Icon.ico"
!define MUI_UNICON "..\img\${APPNAME}-Icon.ico"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; Set languages (first is default language)
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_RESERVEFILE_LANGDLL

Var INSTALL_BASE_DIR
Var OBS_INSTALL_DIR

Section "${APPDISPLAYNAME}" Section1
StrCpy $INSTALL_BASE_DIR "$PROGRAMFILES64\obs-studio"

ReadRegStr $OBS_INSTALL_DIR HKLM "SOFTWARE\OBS Studio" ""

!if "$OBS_INSTALL_DIR" != ""
StrCpy $INSTALL_BASE_DIR "$OBS_INSTALL_DIR"
!endif

StrCpy $InstDir "$INSTALL_BASE_DIR"

IfFileExists "$INSTDIR\*.*" +3
MessageBox MB_OK|MB_ICONSTOP "OBS directory doesn't exist!"
Abort

!define UNINSTALLER "$INSTDIR\obs-plugins\uninstall-${APPNAME}-win-x64.exe"

; Set Section properties
SetOverwrite on
AllowSkipFiles off

; Set Section Files and Shortcuts
SetOutPath "$INSTDIR\obs-plugins\64bit\"
File /r "..\publish\win-x64\*.*" ; DLL and PDB file

SetOutPath "$INSTDIR\data\obs-plugins\${APPNAME}\locale\"
File /r "..\locale\*.*" ; locale files

CreateDirectory "$SMPROGRAMS\${APPDISPLAYNAME}"
CreateShortCut "$SMPROGRAMS\${APPDISPLAYNAME}\Uninstall ${APPDISPLAYNAME}.lnk" "${UNINSTALLER}"

SectionEnd

Section -FinishSection

WriteRegStr HKLM "Software\${APPNAME}" "InstallDir" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPDISPLAYNAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "${UNINSTALLER}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "${AUTHOR}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "https://github.com/${AUTHOR}/${APPNAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${DISPLAY_VERSION}"
WriteUninstaller "${UNINSTALLER}"

SectionEnd

; Modern install component descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} "Install the ${APPDISPLAYNAME} to your installed OBS Studio version"
!insertmacro MUI_FUNCTION_DESCRIPTION_END

UninstallText "This will uninstall the ${APPDISPLAYNAME} from your system"

;Uninstall section
Section Uninstall
SectionIn RO
AllowSkipFiles off

;Remove from registry...
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
DeleteRegKey HKLM "SOFTWARE\${APPNAME}"

; Clean up the plugin files
Delete /REBOOTOK "$INSTDIR\64bit\${APPNAME}.dll"
Delete /REBOOTOK "$INSTDIR\64bit\${APPNAME}.pdb"
; Clean up the data (including locale) files
RMDir /r /REBOOTOK "$INSTDIR\..\data\obs-plugins\${APPNAME}"

; Delete self
Delete "$INSTDIR\uninstall-${APPNAME}-win-x64.exe"

; Delete Shortcuts
RMDir /r "$SMPROGRAMS\${APPDISPLAYNAME}"

SectionEnd

0 comments on commit 470d82b

Please sign in to comment.