1; Script based on generated HM NIS Edit Script Wizard.
2; Forgive me, i am new at this. -- {paul,ian}@cypherpunks.ca
3;
4; known issue. installer induced uninstaller abortion causes overwrite
5; by installer without uninstall.
6; v4.0.2   - New source version.
7; v4.0.1   - New source version.
8; v4.0.0-1 - Include linker hardening [DEP, ALSR] for Windows build
9; v4.0.0   - New source version.
10; v3.2.0   - New source version.
11; v3.1.0   - New source version.  Install and uninstall i18n files.
12; v3.0.0   - Version for pidgin-2.0.0
13; v3.0.0   - Bump version number.
14; v2.0.2   - Bump version number.
15; v2.0.1   - Bump version number.
16; v2.0.0-2 - linking to libotr-2.0.1
17; v2.0.0   - Bump version number. Fixed upgrading gaim2-otr (it didn't overwrite the dll)
18;            bug reported by Aldert Hazenberg <aldert@xelerance.com>
19;          - Added many safeguards and fixed conditions of failures when gaim is running
20;             during install, or failed to (un)install previously.
21;           - Removed popup signifying gaim is found
22; v1.99.0-1 - Bump version number, install Protocol.txt file
23; v1.0.3-2  - Fix for detecting gaim if not installed by Administrator
24;             bug report by Joanna Rutkowska <joanna@mailsnare.net>
25;           - Fix for uninstalling the dll when not installed as Administrator
26; v1.0.3    - Initial version
27
28
29; todo: SetBrandingImage
30; HM NIS Edit Wizard helper defines
31!define PRODUCT_NAME "pidgin-otr"
32!define PRODUCT_VERSION "4.0.2"
33!define PRODUCT_PUBLISHER "Cypherpunks CA"
34!define PRODUCT_WEB_SITE "https://otr.cypherpunks.ca/"
35!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
36!define PRODUCT_UNINST_ROOT_KEY "HKLM"
37
38; MUI 1.67 compatible ------
39!include "MUI.nsh"
40
41; MUI Settings
42!define MUI_ABORTWARNING
43!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
44!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
45
46; Welcome page
47!insertmacro MUI_PAGE_WELCOME
48; License page
49!insertmacro MUI_PAGE_LICENSE "../../win32_export/COPYING.txt"
50; Directory page
51!insertmacro MUI_PAGE_DIRECTORY
52; Instfiles page
53!insertmacro MUI_PAGE_INSTFILES
54; Finish page
55!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.txt"
56!insertmacro MUI_PAGE_FINISH
57
58; Uninstaller pages
59!insertmacro MUI_UNPAGE_INSTFILES
60
61; Language files
62!insertmacro MUI_LANGUAGE "English"
63
64; MUI end ------
65
66Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
67OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
68InstallDir "$PROGRAMFILES\pidgin-otr"
69InstallDirRegKey HKEY_LOCAL_MACHINE SOFTWARE\pidgin-otr "Install_Dir"
70;WriteRegStr HKLM "SOFTWARE\pidgin-otr" "pidgindir" ""
71
72Var "PidginDir"
73
74ShowInstDetails show
75ShowUnInstDetails show
76
77Section "MainSection" SEC01
78    ;InstallDir "$PROGRAMFILES\Pidgin\plugins"
79
80    ; uninstall previous pidgin-otr install if found.
81    Call UnInstOld
82    ;Check for pidgin installation
83    Call GetPidginInstPath
84    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "SOFTWARE\pidgin-otr" "pidgindir" "$PidginDir"
85
86    SetOutPath "$PidginDir\locale"
87    SetOverwrite on
88    ; What the next line means is to recursively search /usr/share/locale
89    ; and install all files under there named pidgin-otr.mo
90    File /r "../../win32_export/locale/pidgin-otr.mo"
91
92    SetOutPath "$INSTDIR"
93    SetOverwrite on
94    File "../../win32_export/pidgin-otr.dll"
95    ; move to pidgin plugin directory, check if not busy (pidgin is running)
96    call CopyDLL
97    ; hard part is done, do the rest now.
98    SetOverwrite on
99    File "../../win32_export/README.Toolkit.txt"
100    File "../../win32_export/README.txt"
101    File "../../win32_export/COPYING.txt"
102    File "../../win32_export/COPYING.LIB.txt"
103    File "../../win32_export/Protocol-v3.html"
104    File "../../win32_export/otr_mackey.exe"
105    File "../../win32_export/otr_modify.exe"
106    File "../../win32_export/otr_parse.exe"
107    File "../../win32_export/otr_readforge.exe"
108    File "../../win32_export/otr_remac.exe"
109    File "../../win32_export/otr_sesskeys.exe"
110    File "pidgin-otr.nsi"
111SectionEnd
112
113Section -AdditionalIcons
114  CreateDirectory "$SMPROGRAMS\pidgin-otr"
115  CreateShortCut "$SMPROGRAMS\pidgin-otr\Uninstall.lnk" "$INSTDIR\pidgin-otr-uninst.exe"
116SectionEnd
117
118Section -Post
119  WriteUninstaller "$INSTDIR\pidgin-otr-uninst.exe"
120  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
121  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\pidgin-otr-uninst.exe"
122  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
123  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
124  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
125SectionEnd
126
127Function un.onUninstSuccess
128  HideWindow
129	MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." /SD IDOK
130FunctionEnd
131
132Function un.onInit
133	MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" /SD IDYES IDYES +2
134  Abort
135FunctionEnd
136
137Section Uninstall
138  Delete "$INSTDIR\pidgin-otr-uninst.exe"
139  Delete "$INSTDIR\README.Toolkit.txt"
140  Delete "$INSTDIR\README.txt"
141  Delete "$INSTDIR\Protocol-v3.html"
142  Delete "$INSTDIR\Protocol-v2.html" ;Left behind by v3.2.0 uninstaller
143  Delete "$INSTDIR\COPYING.txt"
144  Delete "$INSTDIR\COPYING.LIB.txt"
145  Delete "$INSTDIR\otr_mackey.exe"
146  Delete "$INSTDIR\otr_modify.exe"
147  Delete "$INSTDIR\otr_parse.exe"
148  Delete "$INSTDIR\otr_readforge.exe"
149  Delete "$INSTDIR\otr_remac.exe"
150  Delete "$INSTDIR\otr_sesskeys.exe"
151  Delete "$INSTDIR\pidgin-otr.nsi"
152  Delete "$SMPROGRAMS\pidgin-otr\Uninstall.lnk"
153  RMDir "$SMPROGRAMS\pidgin-otr"
154  RMDir "$INSTDIR"
155
156	ReadRegStr $PidginDir HKLM Software\pidgin-otr "pidgindir"
157	IfFileExists "$PidginDir\plugins\pidgin-otr.dll" dodelete
158  ReadRegStr $PidginDir HKCU Software\pidgin-otr "pidgindir"
159	IfFileExists "$PidginDir\plugins\pidgin-otr.dll" dodelete
160
161  ReadRegStr $PidginDir HKLM Software\pidgin-otr "pidgindir"
162	IfFileExists "$PidginDir\plugins\pidgin-otr.dll" dodelete
163  ReadRegStr $PidginDir HKCU Software\Pidgin-otr "pidgindir"
164	IfFileExists "$PidginDir\plugins\pidgin-otr.dll" dodelete
165	MessageBox MB_OK|MB_ICONINFORMATION "Could not find pidgin plugin directory, pidgin-otr.dll not uninstalled!" /SD IDOK IDOK ok
166dodelete:
167	Delete "$PidginDir\plugins\pidgin-otr.dll"
168
169	; Find all the language dirs and delete pidgin-otr.mo in all of them
170	Push $0
171	Push $1
172	FindFirst $0 $1 $PidginDir\locale\*
173	loop:
174		StrCmp $1 "" loopdone
175		Delete $PidginDir\locale\$1\LC_MESSAGES\pidgin-otr.mo
176		FindNext $0 $1
177		Goto loop
178	loopdone:
179	Pop $1
180	Pop $0
181
182	IfFileExists "$PidginDir\plugins\pidgin-otr.dll" 0 +2
183		MessageBox MB_OK|MB_ICONINFORMATION "pidgin-otr.dll is busy. Probably Pidgin is still running. Please delete $PidginDir\plugins\pidgin-otr.dll manually." /SD IDOK
184
185  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
186  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "SOFTWARE\pidgin-otr\pidgindir"
187ok:
188SetAutoClose true
189SectionEnd
190
191Function GetPidginInstPath
192  Push $0
193  ReadRegStr $0 HKLM "Software\pidgin" ""
194	IfFileExists "$0\pidgin.exe" cont
195	ReadRegStr $0 HKCU "Software\pidgin" ""
196	IfFileExists "$0\pidgin.exe" cont
197		MessageBox MB_OK|MB_ICONINFORMATION "Failed to find Pidgin installation." /SD IDOK
198		Abort "Failed to find Pidgin installation. Please install Pidgin first."
199cont:
200	StrCpy $PidginDir $0
201	;MessageBox MB_OK|MB_ICONINFORMATION "Pidgin plugin directory found at $PidginDir\plugins ." /SD IDOK
202  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "SOFTWARE\pidgin-otr" "pidgindir" "$PidginDir"
203FunctionEnd
204
205Function UnInstOld
206	  Push $0
207	  ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
208		IfFileExists "$0" deinst cont
209	deinst:
210		MessageBox MB_OK|MB_ICONEXCLAMATION  "pidgin-otr was already found on your system and will first be uninstalled" /SD IDOK
211		; the uninstaller copies itself to temp and execs itself there, so it can delete
212		; everything including its own original file location. To prevent the installer and
213		; uninstaller racing you can't simply ExecWait.
214		; We hide the uninstall because otherwise it gets really confusing window-wise
215		;HideWindow
216		  ClearErrors
217		IfSilent olduninstsilent
218			ExecWait '"$0" _?=$INSTDIR'
219			IfErrors 0 cont
220			MessageBox MB_OK|MB_ICONEXCLAMATION  "Uninstall failed or aborted" /SD IDOK
221			Abort "Uninstalling of the previous version gave an error. Install aborted."
222olduninstsilent:
223		ExecWait '"$0" /S _?=$INSTDIR'
224		IfErrors 0 cont
225				Abort "Uninstalling of the previous version gave an error. Install aborted."
226		;BringToFront
227	cont:
228		;MessageBox MB_OK|MB_ICONINFORMATION "No old pidgin-otr found, continuing." /SD IDOK
229
230FunctionEnd
231
232Function CopyDLL
233SetOverwrite try
234ClearErrors
235; 3 hours wasted so you guys don't need a reboot!
236; Rename /REBOOTOK "$INSTDIR\pidgin-otr.dll" "$PidginDir\plugins\pidgin-otr.dll"
237IfFileExists "$PidginDir\plugins\pidgin-otr.dll" 0 copy ; remnant or uninstall prev version failed
238Delete "$PidginDir\plugins\pidgin-otr.dll"
239copy:
240ClearErrors
241Rename "$INSTDIR\pidgin-otr.dll" "$PidginDir\plugins\pidgin-otr.dll"
242IfErrors dllbusy
243	Return
244dllbusy:
245	MessageBox MB_RETRYCANCEL "pidgin-otr.dll is busy. Please close Pidgin (including tray icon) and try again" /SD IDCANCEL IDCANCEL cancel
246	Delete "$PidginDir\plugins\pidgin-otr.dll"
247	Goto copy
248	Return
249cancel:
250	Abort "Installation of pidgin-otr aborted"
251FunctionEnd
252