-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnsis_installer_script.nsi
188 lines (147 loc) · 6.41 KB
/
nsis_installer_script.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
;
; This is an NSIS installer script for DesktopSaver
;
!include MUI.nsh
!include x64.nsh
!include FileFunc.nsh
!define VERSION 3.2
Name "DesktopSaver ${VERSION}"
OutFile "DesktopSaver-${VERSION}-installer.exe"
InstallDir $PROGRAMFILES\DesktopSaver
BrandingText " "
VIProductVersion ${VERSION}.0.0
VIAddVersionKey ProductName "DesktopSaver ${VERSION}"
VIAddVersionKey CompanyName "Nicholas Piegdon"
VIAddVersionKey LegalCopyright "Copyright (c) Nicholas Piegdon"
VIAddVersionKey FileDescription "DesktopSaver ${VERSION} Installer"
VIAddVersionKey FileVersion ${VERSION}.0.0
VIAddVersionKey ProductVersion ${VERSION}.0.0
VIAddVersionKey InternalName "DesktopSaver ${VERSION} Installer"
SetCompressor /SOLID lzma
!define MUI_ABORTWARNING
!define MUI_COMPONENTSPAGE_SMALLDESC
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARE\DesktopSaver "Install_Dir"
ComponentText "This will install DesktopSaver to your computer."
DirText "Choose a directory to install in to:"
!include WinMessages.nsh
Function CloseProgram
Exch $1
Push $0
loop:
FindWindow $0 $1
IntCmp $0 0 done
SendMessage $0 ${WM_CLOSE} 0 0
Sleep 100
Goto loop
done:
Pop $0
Pop $1
FunctionEnd
Function un.CloseProgram
Exch $1
Push $0
loop:
FindWindow $0 $1
IntCmp $0 0 done
SendMessage $0 ${WM_CLOSE} 0 0
Sleep 100
Goto loop
done:
Pop $0
Pop $1
FunctionEnd
Section "!DesktopSaver" MainApp
SectionIn RO
; stop the application if it's running (this only works on WinXP+)
DetailPrint "Attempting to stop any old versions of DesktopSaver before installing..."
Push "desktop_saver"
Call CloseProgram
Sleep 1000
SetOutPath $INSTDIR
${If} ${RunningX64}
DetailPrint "Deploying 64-bit DesktopSaver."
File x64\Release\DesktopSaver.exe
${Else}
DetailPrint "Deploying 32-bit DesktopSaver."
File Release\DesktopSaver.exe
${EndIf}
File license.txt
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\DesktopSaver "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "DisplayName" "DesktopSaver (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteUninstaller "uninstall.exe"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "DisplayName" "DesktopSaver"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "DisplayIcon" '"$INSTDIR\DesktopSaver.exe",0'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "Publisher" "Nicholas Piegdon"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "URLInfoAbout" 'http://github.com/npiegdon/desktop-saver'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "DisplayVersion" '${VERSION}'
WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "NoModify" 1
WriteRegDword HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "NoRepair" 1
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver" "EstimatedSize" "$0"
SectionEnd
Section "Start Menu Shortcuts" Shortcuts
SetShellVarContext all
CreateShortCut "$SMPROGRAMS\DesktopSaver.lnk" "$INSTDIR\DesktopSaver.exe" "" "$INSTDIR\DesktopSaver.exe" 0
SectionEnd
Section "Run After Install" RunPostInstall
Exec '"$INSTDIR\DesktopSaver.exe"'
SectionEnd
Section /o "Always Run at Startup" AlwaysRun
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "DesktopSaver" '"$INSTDIR\DesktopSaver.exe"'
SectionEnd
UninstallText "This will uninstall DesktopSaver. Hit next to continue."
Section "Uninstall"
; stop the application if it's running (this only works on WinXP)
DetailPrint "Attempting to stop DesktopSaver before uninstalling..."
Push "desktop_saver"
Call un.CloseProgram
Sleep 1000
; remove registry keys
;
; NOTE: this intentionally leaves the "Install_Dir"
; entry in HKLM\SOFTWARE\DesktopSaver in the event of
; subsequent reinstalls/upgrades
;
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DesktopSaver"
DeleteRegKey HKCU SOFTWARE\DesktopSaver
; remove the "run at startup" entry
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "DesktopSaver"
; delete program files
Delete $INSTDIR\readme.txt
Delete $INSTDIR\license.txt
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\DesktopSaver.exe
; remove Start Menu shortcuts
SetShellVarContext all
Delete $SMPROGRAMS\DesktopSaver.lnk
; delete left over icon history file
Delete "$APPDATA\DesktopSaver\*.*"
RmDir "$APPDATA\DesktopSaver"
RMDir /r "$INSTDIR"
SectionEnd
LangString DESC_MainApp ${LANG_ENGLISH} "Installs main DesktopSaver application files."
LangString DESC_Shortcuts ${LANG_ENGLISH} "Adds a DesktopSaver Start Menu group to the 'All Programs' section of your Start Menu."
LangString DESC_RunPostInstall ${LANG_ENGLISH} "Starts DesktopSaver immediately after install is complete."
LangString DESC_AlwaysRun ${LANG_ENGLISH} "Causes DesktopSaver to run each time Windows starts."
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${MainApp} $(DESC_MainApp)
!insertmacro MUI_DESCRIPTION_TEXT ${Shortcuts} $(DESC_Shortcuts)
!insertmacro MUI_DESCRIPTION_TEXT ${RunPostInstall} $(DESC_RunPostInstall)
!insertmacro MUI_DESCRIPTION_TEXT ${AlwaysRun} $(DESC_AlwaysRun)
!insertmacro MUI_FUNCTION_DESCRIPTION_END