aboutsummaryrefslogtreecommitdiff
path: root/nsis/sylpheed.nsi
blob: 86ae32a1d201cfd6023cc0f54d19cb804a003b71 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
; Script generated by the HM NIS Edit Script Wizard.
; Modified by Ikuya Awashiro <ikuya@fruitsbasket.info>
; Modified by Hiroyuki Yamamoto <hiro-y@kcn.ne.jp>

; This script requires NsProcess plugin:
; http://nsis.sourceforge.net/NsProcess_plugin

!include "sylpheed-defs.nsh"

SetCompressor /SOLID lzma

!include "nsProcess.nsh"
!include "Memento.nsh"

; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "Sections.nsh"
!include "LogicLib.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-blue.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall-blue.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE $(license)
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
;!define MUI_FINISHPAGE_RUN "$INSTDIR\sylpheed.exe"
;!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.txt"
;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README-win32.txt"
;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README-win32-ja.txt"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION "ShowReadme"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(readme)"
!define MUI_FINISHPAGE_LINK "$(jump)"
!define MUI_FINISHPAGE_LINK_LOCATION ${PRODUCT_WEB_SITE}
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_WELCOME
!define MUI_UNCONFIRMPAGE_TEXT_TOP "$(un_confirmpage_text_top)"
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_COMPONENTS
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

; Language files
!insertmacro MUI_LANGUAGE "English" # ${LANG_ENGLISH}
!insertmacro MUI_LANGUAGE "Spanish" # ${LANG_SPANISH}
!insertmacro MUI_LANGUAGE "Japanese" # ${LANG_JAPANESE}

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
ReserveFile "${NSISDIR}\Plugins\nsProcess.dll"

; MUI end ------

!include "English.nsh"
!include "Spanish.nsh"
!include "Japanese.nsh"

Var ISSILENT

;Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
;OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}_setup.exe"
Name "${INST_NAME} ${INST_VERSION}"
OutFile "${INST_FILENAME}-${INST_VERSION}_setup.exe"
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
RequestExecutionLevel admin
ShowInstDetails hide
ShowUnInstDetails hide
XPStyle on
BrandingText "${INST_NAME} ${INST_VERSION}"

${MementoSection} "!Sylpheed" sec_sylpheed
  SetShellVarContext all
  SectionIn RO
  SetOutPath "$INSTDIR"
  File /r "Sylpheed\"
  CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"

  ${If} $LANGUAGE = "${LANG_JAPANESE}"
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_manual_lnk).lnk" "$INSTDIR\doc\manual\ja\Sylpheed.html"
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\README.lnk" "$INSTDIR\README-win32-ja.txt"
    File /oname=README.txt "Sylpheed\README-win32-ja.txt"
  ${ElseIf} $LANGUAGE = "${LANG_SPANISH}"
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_manual_lnk).lnk" "$INSTDIR\doc\manual\en\Sylpheed.html"
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\README.lnk" "$INSTDIR\README-win32-es.txt"
    File /oname=README.txt "Sylpheed\README-win32-es.txt"
  ${Else}
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_manual_lnk).lnk" "$INSTDIR\doc\manual\en\Sylpheed.html"
    CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\README.lnk" "$INSTDIR\README-win32.txt"
    File /oname=README.txt "Sylpheed\README-win32.txt"
  ${EndIf}

  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed.lnk" "$INSTDIR\sylpheed.exe"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_debug_mode_lnk).lnk" "$INSTDIR\sylpheed.exe" "--debug"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_safe_mode_lnk).lnk" "$INSTDIR\sylpheed.exe" "--safe-mode"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_all_quit_lnk).lnk" "$INSTDIR\sylpheed.exe" "--exit"
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${ORIG_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_homepage_lnk).lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\$(uninstall_lnk).lnk" "$INSTDIR\uninst.exe"
${MementoSectionEnd}

SectionGroup /e "$(plugins)" sec_plugins

!ifdef SYLPHEED_PRO
${MementoSection} "Sylpheed Pro" sec_sylpheed_pro
  SetShellVarContext all
  SetOutPath "$INSTDIR"
  File /r "Sylpheed-Pro\"
  WriteIniStr "$INSTDIR\${INST_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed Pro Homepage.lnk" "$INSTDIR\${INST_NAME}.url"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed Pro Manual.lnk" "$INSTDIR\doc\manual\sylpheed-pro\ja\search-plugin.html"
${MementoSectionEnd}
!endif

${MementoSection} "$(attachment_tool_plugin)" sec_attachment_tool_plugin
  SetOutPath "$INSTDIR\plugins"
  File "plugins\plugins\attachment_tool.dll"
  SetOutPath "$INSTDIR\doc\plugins"
  File "plugins\doc\plugins\README.attachment_tool.txt"
${MementoSectionEnd}

!ifdef HAVE_AUTOENC_PLUGIN
${MementoSection} "$(autoenc_plugin)" sec_autoenc_plugin
  SetOutPath "$INSTDIR"
  File /r "autoenc\"
${MementoSectionEnd}
!endif

SectionGroupEnd

${MementoSection} "sylfilter" sec_sylfilter
  SetOutPath "$INSTDIR"
  File /r "sylfilter\"
${MementoSectionEnd}

${MementoSection} "bsfilter" sec_bsfilter
  SetOutPath "$INSTDIR"
  File /r "bsfilter\"
${MementoSectionEnd}

${MementoSection} "$(desktop_shortcut)" sec_desktop_shortcut
  SetShellVarContext current
  CreateShortCut "$DESKTOP\Sylpheed.lnk" "$INSTDIR\sylpheed.exe"
${MementoSectionEnd}

${MementoUnselectedSection} "$(quick_shortcut)" sec_quick_shortcut
  SetShellVarContext current
  CreateShortCut "$QUICKLAUNCH\Sylpheed.lnk" "$INSTDIR\sylpheed.exe"
${MementoSectionEnd}

${MementoSection} "$(handler)" sec_handler
   ; HKLM
   ; .eml
   WriteRegStr HKLM "Software\Classes\Sylpheed.EML" "" "Sylpheed Message"
   WriteRegDWORD HKLM "Software\Classes\Sylpheed.EML" "EditFlags" 0x00000002
   WriteRegStr HKLM "Software\Classes\Sylpheed.EML" "FriendlyTypeName" "Sylpheed Message"
   WriteRegStr HKLM "Software\Classes\Sylpheed.EML\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Classes\Sylpheed.EML\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --open $\"%1$\""

   ; mailto:
   WriteRegStr HKLM "Software\Classes\mailto" "" "URL:MailTo Protocol"
   WriteRegDWORD HKLM "Software\Classes\mailto" "EditFlags" 0x00000002
   WriteRegStr HKLM "Software\Classes\mailto" "FriendlyTypeName" "Sylpheed MailTo"
   WriteRegStr HKLM "Software\Classes\mailto" "URL Protocol" ""
   WriteRegStr HKLM "Software\Classes\mailto\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Classes\mailto\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --compose $\"%1$\""

   WriteRegStr HKLM "Software\Classes\Sylpheed.Url.MailTo" "" "URL:MailTo Protocol"
   WriteRegDWORD HKLM "Software\Classes\Sylpheed.Url.MailTo" "EditFlags" 0x00000002
   WriteRegStr HKLM "Software\Classes\Sylpheed.Url.MailTo" "FriendlyTypeName" "Sylpheed MailTo"
   WriteRegStr HKLM "Software\Classes\Sylpheed.Url.MailTo" "URL Protocol" ""
   WriteRegStr HKLM "Software\Classes\Sylpheed.Url.MailTo\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Classes\Sylpheed.Url.MailTo\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --compose $\"%1$\""

   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed" "" "Sylpheed"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Protocols\mailto" "" "URL:MailTo Protocol"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Protocols\mailto" "URL Protocol" ""
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Protocols\mailto\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Protocols\mailto\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --compose $\"%1$\""
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\""

   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities" "ApplicationName" "Sylpheed"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities" "ApplicationIcon" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities" "ApplicationDescription" "Sylpheed - lightweight and user-friendly e-mail client"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities\FileAssociations" ".eml" "Sylpheed.EML"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities\URLAssociations" "mailto" "Sylpheed.Url.MailTo"
   WriteRegStr HKLM "Software\Clients\Mail\Sylpheed\Capabilities\StartMenu" "Mail" "Sylpheed"

   WriteRegStr HKLM "Software\RegisteredApplications" "Sylpheed" "SOFTWARE\Clients\Mail\Sylpheed\Capabilities"

   ; HKCU
   WriteRegStr HKCU "Software\Clients\Mail" "" "Sylpheed"

   WriteRegStr HKCU "Software\Microsoft\Windows\Shell\Associations\URLAssociations\mailto\UserChoice" "Progid" "Sylpheed.Url.MailTo"
   DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.eml\UserChoice"
   WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.eml\UserChoice" "Progid" "Sylpheed.EML"

   ; .eml
   WriteRegStr HKCU "Software\Classes\.eml" "" "Sylpheed.EML"

   WriteRegStr HKCU "Software\Classes\Sylpheed.EML" "" "Sylpheed Message"
   WriteRegDWORD HKCU "Software\Classes\Sylpheed.EML" "EditFlags" 0x00000002
   WriteRegStr HKCU "Software\Classes\Sylpheed.EML" "FriendlyTypeName" "Sylpheed Message"
   WriteRegStr HKCU "Software\Classes\Sylpheed.EML\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKCU "Software\Classes\Sylpheed.EML\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --open $\"%1$\""

   ; mailto:
   WriteRegStr HKCU "Software\Classes\mailto" "" "URL:MailTo Protocol"
   WriteRegDWORD HKCU "Software\Classes\mailto" "EditFlags" 0x00000002
   WriteRegStr HKCU "Software\Classes\mailto" "FriendlyTypeName" "Sylpheed MailTo"
   WriteRegStr HKCU "Software\Classes\mailto" "URL Protocol" ""
   WriteRegStr HKCU "Software\Classes\mailto\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKCU "Software\Classes\mailto\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --compose $\"%1$\""

   WriteRegStr HKCU "Software\Classes\Sylpheed.Url.MailTo" "" "URL:MailTo Protocol"
   WriteRegDWORD HKCU "Software\Classes\Sylpheed.Url.MailTo" "EditFlags" 0x00000002
   WriteRegStr HKCU "Software\Classes\Sylpheed.Url.MailTo" "FriendlyTypeName" "Sylpheed MailTo"
   WriteRegStr HKCU "Software\Classes\Sylpheed.Url.MailTo" "URL Protocol" ""
   WriteRegStr HKCU "Software\Classes\Sylpheed.Url.MailTo\DefaultIcon" "" "$INSTDIR\sylpheed.exe,0"
   WriteRegStr HKCU "Software\Classes\Sylpheed.Url.MailTo\shell\open\command" "" "$\"$INSTDIR\sylpheed.exe$\" --compose $\"%1$\""
${MementoSectionEnd}

${MementoSectionDone}

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\sylpheed.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\sylpheed.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Section "!un.Sylpheed" sec_un_sylpheed
  SetShellVarContext all
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_manual_lnk).lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\README.lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed.lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_debug_mode_lnk).lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_safe_mode_lnk).lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_all_quit_lnk).lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(sylpheed_homepage_lnk).lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\$(uninstall_lnk).lnk"
  SetShellVarContext current

  Delete "$INSTDIR\curl.exe"
  Delete "$INSTDIR\gpgme-w32spawn.exe"
  Delete "$INSTDIR\gspawn-win32-helper-console.exe"
  Delete "$INSTDIR\gspawn-win32-helper.exe"
  Delete "$INSTDIR\iconv.dll"
  Delete "$INSTDIR\intl.dll"
  Delete "$INSTDIR\jpeg62.dll"
  Delete "$INSTDIR\libasprintf-0.dll"
  Delete "$INSTDIR\libassuan-0.dll"
  Delete "$INSTDIR\libatk-1.0-0.dll"
  Delete "$INSTDIR\libcairo-2.dll"
  Delete "$INSTDIR\libcompface.dll"
  Delete "$INSTDIR\libeay32.dll"
  Delete "$INSTDIR\libffi-6.dll"
  Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
  Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
  Delete "$INSTDIR\libgio-2.0-0.dll"
  Delete "$INSTDIR\libglib-2.0-0.dll"
  Delete "$INSTDIR\libgmodule-2.0-0.dll"
  Delete "$INSTDIR\libgobject-2.0-0.dll"
  Delete "$INSTDIR\libgpg-error-0.dll"
  Delete "$INSTDIR\libgpgme-11.dll"
  Delete "$INSTDIR\libgthread-2.0-0.dll"
  Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
  Delete "$INSTDIR\libonig.dll"
  Delete "$INSTDIR\libpango-1.0-0.dll"
  Delete "$INSTDIR\libpangocairo-1.0-0.dll"
  Delete "$INSTDIR\libpangowin32-1.0-0.dll"
  Delete "$INSTDIR\libpng14-14.dll"
  Delete "$INSTDIR\libsylph-0-1.dll"
  Delete "$INSTDIR\libsylpheed-plugin-0-1.dll"
  Delete "$INSTDIR\ssleay32.dll"
  Delete "$INSTDIR\sylpheed.exe"
  Delete "$INSTDIR\wabread.exe"
  Delete "$INSTDIR\zlib1.dll"

  Delete "$INSTDIR\README-win32-es.txt"
  Delete "$INSTDIR\README-win32-ja.txt"
  Delete "$INSTDIR\README-win32.txt"
  Delete "$INSTDIR\README.txt"

  Delete "$INSTDIR\sample-sylpheed.ini"

  Delete "$INSTDIR\sylpheed-128x128.png"
  Delete "$INSTDIR\sylpheed-64x64.png"
  Delete "$INSTDIR\sylpheed-mailto-protocol_admin.reg"
  Delete "$INSTDIR\sylpheed-mailto-protocol_user.reg"
  Delete "$INSTDIR\sylpheed.png"
  Delete "$INSTDIR\${PRODUCT_NAME}.url"

  Delete "$INSTDIR\plugin-updater.exe"
  Delete "$INSTDIR\update-manager.exe"
  Delete "$INSTDIR\uninst.exe"

  RMDir /r "$INSTDIR\doc"
  RMDir /r "$INSTDIR\etc"
  RMDir /r "$INSTDIR\lib"
  RMDir /r "$INSTDIR\share\locale"
  RMDir /r "$INSTDIR\share\themes"
  RMDir "$INSTDIR\share"
SectionEnd

SectionGroup /e "un.$(plugins)" sec_un_plugins

!ifdef SYLPHEED_PRO
Section "un.Sylpheed Pro" sec_un_sylpheed_pro
  SetShellVarContext all
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed Pro Homepage.lnk"
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\Sylpheed Pro Manual.lnk"
  SetShellVarContext current

  ; Sylpheed Pro components
  Delete "$INSTDIR\bzip2.dll"
  Delete "$INSTDIR\dbimport-ext.exe"
  Delete "$INSTDIR\dts-indexer.exe"
  Delete "$INSTDIR\libarchive2.dll"
  Delete "$INSTDIR\libmecab.dll"
  Delete "$INSTDIR\libpq.dll"
  Delete "$INSTDIR\mecabrc"
  Delete "$INSTDIR\Sylpheed Pro.url"
  Delete "$INSTDIR\plugins\dbimport.dll"
  Delete "$INSTDIR\plugins\scheduler.dll"
  RMDir /r "$INSTDIR\dic"
  RMDir /r "$INSTDIR\pgsql"
  RMDir /r "$INSTDIR\pgsql83"
  RMDir /r "$INSTDIR\share\sylpheed-pro"
  RMDir "$INSTDIR\share"
SectionEnd
!endif

Section "un.$(attachment_tool_plugin)" sec_un_attachment_tool_plugin
  Delete "$INSTDIR\plugins\attachment_tool.dll"
  Delete "$INSTDIR\doc\plugins\README.attachment_tool.txt"
SectionEnd

!ifdef HAVE_AUTOENC_PLUGIN
Section "un.$(autoenc_plugin)" sec_un_autoenc_plugin
  Delete "$INSTDIR\plugins\autoenc.dll"
  Delete "$INSTDIR\doc\autoenc\COPYING.txt"
  Delete "$INSTDIR\doc\autoenc\README.autoenc.txt"
  Delete "$INSTDIR\doc\autoenc\LICENSE.7-zip.txt"
  RMDir "$INSTDIR\doc\autoenc"
  Delete "$INSTDIR\7z.dll"
  Delete "$INSTDIR\7z.exe"
SectionEnd
!endif

SectionGroupEnd

Section "un.sylfilter" sec_un_sylfilter
  ; sylfilter components
  Delete "$INSTDIR\sylfilter.exe"
  Delete "$INSTDIR\sylfilter-cui.exe"
SectionEnd

Section "un.bsfilter" sec_un_bsfilter
  ; bsfilter components
  Delete "$INSTDIR\bsfilter"
  Delete "$INSTDIR\bsfilterw.exe"
SectionEnd

Section "un.$(desktop_shortcut)" sec_un_desktop_shortcut
  SetShellVarContext current
  Delete "$DESKTOP\Sylpheed.lnk"
SectionEnd

Section "un.$(quick_shortcut)" sec_un_quick_shortcut
  SetShellVarContext current
  Delete "$QUICKLAUNCH\Sylpheed.lnk"
SectionEnd

Section "-un.install"
  SetShellVarContext all
  RMDir "$SMPROGRAMS\Sylpheed"
  SetShellVarContext current

  ; remove plug-ins dir only when empty
  RMDir "$INSTDIR\plugins"
  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_DIR_REGKEY}"
  DeleteRegKey HKLM "Software\Classes\Sylpheed.EML"
  DeleteRegKey HKLM "Software\Classes\Sylpheed.Url.MailTo"
  DeleteRegKey HKLM "Software\Clients\Mail\Sylpheed"
  DeleteRegValue HKLM "Software\RegisteredApplications" "Sylpheed"
  DeleteRegKey HKCU "Software\Classes\Sylpheed.EML"
  DeleteRegKey HKCU "Software\Classes\Sylpheed.Url.MailTo"
  DeleteRegKey ${MEMENTO_REGISTRY_ROOT} "${MEMENTO_REGISTRY_KEY}"

  SetAutoClose true
SectionEnd

; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_sylpheed} "$(sylpheed_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_plugins} "$(plugins_description)"
!ifdef SYLPHEED_PRO
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_sylpheed_pro} "$(sylpheed_pro_description)"
!endif
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_attachment_tool_plugin} "$(attachment_tool_plugin_description)"
!ifdef HAVE_AUTOENC_PLUGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_autoenc_plugin} "$(autoenc_plugin_description)"
!endif
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_sylfilter} "$(sylfilter_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_bsfilter} "$(bsfilter_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_desktop_shortcut} "$(desktop_shortcut_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_quick_shortcut} "$(quick_shortcut_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_handler} "$(handler_description)"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_sylpheed} "$(un_sylpheed_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_plugins} "$(un_plugins_description)"
!ifdef SYLPHEED_PRO
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_sylpheed_pro} "$(un_sylpheed_pro_description)"
!endif
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_attachment_tool_plugin} "$(un_attachment_tool_plugin_description)"
!ifdef HAVE_AUTOENC_PLUGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_autoenc_plugin} "$(un_autoenc_plugin_description)"
!endif
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_sylfilter} "$(un_sylfilter_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_bsfilter} "$(un_bsfilter_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_desktop_shortcut} "$(un_desktop_shortcut_description)"
  !insertmacro MUI_DESCRIPTION_TEXT ${sec_un_quick_shortcut} "$(un_quick_shortcut_description)"
  ; handler is not uninstallable.
!insertmacro MUI_UNFUNCTION_DESCRIPTION_END

Function .onInit
  ${MementoSectionRestore}

  StrCpy $1 ${sec_sylpheed}

; Prevent install while Sylpheed is running
check_app_running:
  ${nsProcess::FindProcess} "sylpheed.exe" $R0
  StrCmp $R0 "0" 0 +3
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$(app_running)" IDOK check_app_running
  Abort

; Auto-uninstall old before installing new
; http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new
  ReadRegStr $R0 HKLM \
  "${PRODUCT_UNINST_KEY}" "UninstallString"
  StrCmp $R0 "" done_
 
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  "$(delete_caution)" \
  /SD IDOK \
  IDOK uninst
  Abort
  
;Run the uninstaller
uninst:
  ClearErrors
  StrCpy $ISSILENT "/S"
  IfSilent +2
    StrCpy $ISSILENT ""
  ExecWait '$R0 $ISSILENT _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
 
  IfErrors no_remove_uninstaller done_
  no_remove_uninstaller:
  Abort
  
; label "done" used in MementoSectionRestore
done_:
FunctionEnd

Function .onInstSuccess
  ${MementoSectionSave}
FunctionEnd

Function .onSelChange
  !insertmacro StartRadioButtons $1
    !insertmacro RadioButton ${sec_sylpheed}
  !insertmacro EndRadioButtons
FunctionEnd

Function un.onInit
check_app_running:
  ; Prevent uninstall while Sylpheed is running
  ${nsProcess::FindProcess} "sylpheed.exe" $R0
  StrCmp $R0 "0" 0 +3
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "$(app_running_uninst)" IDOK check_app_running
  Abort

  ${nsProcess::KillProcess} "sylpheed.exe" $R0
  ${nsProcess::KillProcess} "dts-indexer.exe" $R0
  ${nsProcess::KillProcess} "postgres.exe" $R0

  SetShellVarContext current

  IfFileExists "$INSTDIR\sylpheed.exe" sylpheed_file_exists
  !insertmacro UnselectSection ${sec_un_sylpheed}
  sylpheed_file_exists:
  !insertmacro SetSectionFlag ${sec_un_sylpheed} ${SF_RO}

!ifdef SYLPHEED_PRO
  IfFileExists "$INSTDIR\plugins\dbimport.dll" sylpheed_pro_file_exists
  !insertmacro UnselectSection ${sec_un_sylpheed_pro}
  !insertmacro SetSectionFlag ${sec_un_sylpheed_pro} ${SF_RO}
  sylpheed_pro_file_exists:
!endif

  IfFileExists "$INSTDIR\plugins\attachment_tool.dll" attachment_tool_plugin_file_exists
  !insertmacro UnselectSection ${sec_un_attachment_tool_plugin}
  !insertmacro SetSectionFlag ${sec_un_attachment_tool_plugin} ${SF_RO}
  attachment_tool_plugin_file_exists:

!ifdef HAVE_AUTOENC_PLUGIN
  IfFileExists "$INSTDIR\plugins\autoenc.dll" autoenc_plugin_file_exists
  !insertmacro UnselectSection ${sec_un_autoenc_plugin}
  !insertmacro SetSectionFlag ${sec_un_autoenc_plugin} ${SF_RO}
  autoenc_plugin_file_exists:
!endif

  IfFileExists "$INSTDIR\sylfilter.exe" sylfilter_file_exists
  !insertmacro UnselectSection ${sec_un_sylfilter}
  !insertmacro SetSectionFlag ${sec_un_sylfilter} ${SF_RO}
  sylfilter_file_exists:

  IfFileExists "$INSTDIR\bsfilter" bsfilter_file_exists
  !insertmacro UnselectSection ${sec_un_bsfilter}
  !insertmacro SetSectionFlag ${sec_un_bsfilter} ${SF_RO}
  bsfilter_file_exists:

  SetShellVarContext current
  IfFileExists "$DESKTOP\Sylpheed.lnk" desktop_shortcut_file_exists
  !insertmacro UnselectSection ${sec_un_desktop_shortcut}
  !insertmacro SetSectionFlag ${sec_un_desktop_shortcut} ${SF_RO}
  desktop_shortcut_file_exists:

  SetShellVarContext current
  IfFileExists "$QUICKLAUNCH\Sylpheed.lnk" quick_shortcut_file_exists
  !insertmacro UnselectSection ${sec_un_quick_shortcut}
  !insertmacro SetSectionFlag ${sec_un_quick_shortcut} ${SF_RO}
  quick_shortcut_file_exists:
FunctionEnd

Function ShowReadme
  ExecShell open "$INSTDIR\README.txt"
!ifdef SYLPHEED_PRO
  ${If} $LANGUAGE = "${LANG_JAPANESE}"
    IfFileExists "$INSTDIR\doc\manual\sylpheed-pro\ja\search-plugin.html" 0 +2
      ExecShell open "$INSTDIR\doc\manual\sylpheed-pro\ja\search-plugin.html"
  ${EndIf}
!endif
FunctionEnd