-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows_setup.nsi
112 lines (110 loc) · 3.38 KB
/
windows_setup.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
; Includes
!include "MUI2.nsh"
!include nsDialogs.nsh
!include "logiclib.nsh"
!include "FileAssociation.nsh"
; Custom defines
!define NAME "Chess-CLI"
!define APPFILE "chess-cli.exe"
!define VERSION "0.6.0"
!define SLUG "${NAME} v${VERSION}"
; General
Name "${NAME}"
OutFile "${NAME}-setup.exe"
InstallDir "$PROGRAMFILES\${NAME}"
InstallDirRegKey HKCU "Software\${NAME}" ""
RequestExecutionLevel admin
; Variables
; nsDialogs HWND variables
var Dialog
var Checkbox
var SetFileAssociationsCheckbox
; UI
!define MUI_WELCOMEPAGE_TITLE "${SLUG} Setup"
; Pages
; Installer pages
!insertmacro MUI_PAGE_WELCOME
;!insertmacro MUI_PAGE_LICENSE "license.txt"
Page custom FileAssociations FileAssociationsLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
; Set UI language
!insertmacro MUI_LANGUAGE "English"
; Section - Install App
Section "-hidden app"
SectionIn RO
SetOutPath "$INSTDIR"
File /r "chess-cli.dist\*.*"
File "path_ed\PathEd.exe"
WriteRegStr HKCU "Software\${NAME}" "" $INSTDIR
WriteUninstaller "$INSTDIR\Uninstall.exe"
;Create shortcuts
CreateShortCut "$DESKTOP\${NAME}.lnk" "$INSTDIR\${APPFILE}"
CreateShortcut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\${APPFILE}"
CreateShortcut "$SMPROGRAMS\${NAME} Uninstall.lnk" "$INSTDIR\Uninstall.exe"
;Set file associations
${If} $SetFileAssociationsCheckbox == ${BST_CHECKED}
${registerExtension} "$INSTDIR\${APPFILE}" ".pgn" "PGN_File"
${registerExtension} "$INSTDIR\${APPFILE}" ".fen" "FEN_File"
${EndIf}
;Add to PATH
ExecWait '$INSTDIR\PathEd.exe add "$INSTDIR"'
SectionEnd
Function FileAssociations
!insertmacro MUI_HEADER_TEXT "File Associations" "Set file associations for common chess formats"
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateCheckbox} 0 30u 100% 10u "Register PGN and FEN files to be opened by Chess-CLI."
Pop $Checkbox
${NSD_Check} $Checkbox
nsDialogs::Show
FunctionEnd
Function FileAssociationsLeave
${NSD_GetState} $Checkbox $SetFileAssociationsCheckbox
FunctionEnd
; RMDirUP is used to recursively delete empty parent folders of a given folder.
; This function is used with uninstaller. The command RMDir /r "$INSTDIR" cant remove parent folder.
; Remove empty parent directories
Function un.RMDirUP
!define RMDirUP '!insertmacro RMDirUPCall'
!macro RMDirUPCall _PATH
push '${_PATH}'
Call un.RMDirUP
!macroend
; $0 - current folder
ClearErrors
Exch $0
;DetailPrint "ASDF - $0\.."
RMDir "$0\.."
IfErrors Skip
${RMDirUP} "$0\.."
Skip:
Pop $0
FunctionEnd
; Section - Uninstaller
Section "Uninstall"
;Delete Shortcuts
Delete "$DESKTOP\${NAME}.lnk"
Delete "$SMPROGRAMS\${NAME}.lnk"
Delete "$SMPROGRAMS\${NAME} Uninstall.lnk"
;Remove file associations
${unregisterExtension} ".pgn" "PGN_File"
${unregisterExtension} ".fen" "FEN_File"
;Delete Uninstall
Delete "$INSTDIR\Uninstall.exe"
;Remove from PATH
ExecWait '$INSTDIR\PathEd.exe remove "$INSTDIR"'
;Remove PathEd
Delete "$INSTDIR\PathEd.exe"
;Delete Folder
RMDir /r "$INSTDIR"
${RMDirUP} "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\${NAME}"
SectionEnd