-
-
Notifications
You must be signed in to change notification settings - Fork 200
/
installer.nsi
145 lines (115 loc) · 4.31 KB
/
installer.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
!define AppName "<%= name %>"
!define DisplayName "<%= displayname %>"
!define Author "<%= author %>"
!define Homepage "<%= homepage %>"
!define ReleaseVersion "<%= version %>"
!define ReleaseNotes "${Homepage}/releases/v${ReleaseVersion}"
!define Arch "<%= arch %>"
!define AppDir "${DisplayName}"
!define AppFile "${AppName}.exe"
!define InstallerFile "<%= filename %>"
!define UninstallerFile "Uninstall ${DisplayName}.exe"
!define RegKeyInstall "SOFTWARE\${AppName}"
!define RegKeyUninstall "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}"
!define KillCmd 'cmd /c taskkill /f /im "${AppFile}" /fi "WINDOWTITLE eq ${DisplayName}"'
# Modules
!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "x64.nsh"
# Installer/Uninstaller params
Name "${DisplayName}"
Caption "${DisplayName} - v${ReleaseVersion}"
BrandingText "${DisplayName} - v${ReleaseVersion}"
ShowInstDetails show
ShowUninstDetails show
InstallDir ""
InstallDirRegKey HKLM "${RegKeyInstall}" "InstallPath"
# Package params
CRCCheck on
SetCompressor /SOLID lzma
# NSIS Installer output dir
OutFile "<%= diroutput %>/${InstallerFile}"
# Metadata params
VIProductVersion "${ReleaseVersion}.0"
VIAddVersionKey "ProductName" "${DisplayName}"
VIAddVersionKey "ProductVersion" "${ReleaseVersion}"
VIAddVersionKey "FileDescription" "${DisplayName}"
VIAddVersionKey "FileVersion" "${ReleaseVersion}"
VIAddVersionKey "LegalCopyright" "${Author}"
# GUI
!define MUI_ICON "<%= dirroot %>/build/resources/icons/icon-16-32-48-256.ico"
!define MUI_WELCOMEPAGE_TITLE "${DisplayName} - v${ReleaseVersion}"
!define MUI_WELCOMEPAGE_TITLE_3LINES
!define MUI_ABORTWARNING
!define MUI_ABORTWARNING_CANCEL_DEFAULT
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN_TEXT "Launch ${DisplayName}"
!define MUI_FINISHPAGE_RUN "$INSTDIR\${AppFile}"
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
!define MUI_FINISHPAGE_SHOWREADME "${ReleaseNotes}"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Open release notes in web browser"
!define MUI_UNICON "${NSISDIR}/Contrib/Graphics/Icons/modern-uninstall.ico"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
# Installer
Section "<%= displayname %>" SEC_DEFAULT
DetailPrint '${KillCmd}'
nsExec::Exec /TIMEOUT=3000 '${KillCmd}'
SetOutPath $INSTDIR
File /r "<%= dirinput %>\*"
WriteUninstaller "$INSTDIR\${UninstallerFile}"
WriteRegStr HKLM "${RegKeyInstall}" "InstallPath" "$INSTDIR"
WriteRegStr HKLM "${RegKeyUninstall}" "DisplayName" "${DisplayName}"
WriteRegStr HKLM "${RegKeyUninstall}" "UninstallString" "$INSTDIR\${UninstallerFile}"
WriteRegStr HKLM "${RegKeyUninstall}" "DisplayIcon" "$INSTDIR\${AppFile}"
WriteRegStr HKLM "${RegKeyUninstall}" "DisplayVersion" "${ReleaseVersion}"
WriteRegStr HKLM "${RegKeyUninstall}" "Publisher" "${Author}"
WriteRegStr HKLM "${RegKeyUninstall}" "URLInfoAbout" "${Homepage}"
WriteRegStr HKLM "${RegKeyUninstall}" "HelpLink" "${Homepage}"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "${RegKeyUninstall}" "EstimatedSize" "$0"
SectionEnd
Section "Create desktop shortcut" SEC_SHORTCUT_DESKTOP
${If} ${SectionIsSelected} ${SEC_SHORTCUT_DESKTOP}
SetOutPath $INSTDIR
CreateShortCut "$DESKTOP\${DisplayName}.lnk" "$INSTDIR\${AppFile}"
${EndIf}
SectionEnd
# Uninstaller
Section "Uninstall"
DetailPrint '${KillCmd}'
nsExec::Exec /TIMEOUT=3000 '${KillCmd}'
# Gracefully remove all files and directories
<% JSON.parse( files ).files.forEach(function( file ) { %>Delete "$INSTDIR\<%= file %>"
<% }) %>
<% JSON.parse( files ).directories.forEach(function( dir ) { %>RMDir "$INSTDIR\<%= dir %>"
<% }) %>
Delete "$INSTDIR\${UninstallerFile}"
RMDir "$INSTDIR"
Delete "$DESKTOP\${DisplayName}.lnk"
DeleteRegKey HKLM "${RegKeyInstall}"
DeleteRegKey HKLM "${RegKeyUninstall}"
SectionEnd
# Functions
Function .onInit
# set default section as read only
SectionSetFlags ${SEC_DEFAULT} 17
${If} $InstDir == ""
${If} ${RunningX64}
StrCpy $InstDir "$PROGRAMFILES64\${AppDir}\"
${Else}
StrCpy $InstDir "$PROGRAMFILES32\${AppDir}\"
${EndIf}
${EndIf}
FunctionEnd