team-ljyzipelo

공개
269줄10.0 KB
1Unicode true
2!include "MUI2.nsh"
3!include "nsDialogs.nsh"
4!include "LogicLib.nsh"
5!include "x64.nsh"
6!include "FileFunc.nsh"
7Name "Zipelo 개발판"
8OutFile "Zipelo-0.1.0-dev-windows-x64-setup.exe"
9!define INSTALLROOT "$LOCALAPPDATA\Programs\Zipelo-Dev"
10InstallDir "${INSTALLROOT}"
11RequestExecutionLevel user
12SetCompressor /SOLID lzma
13SetOverwrite off
14AllowSkipFiles off
15ShowInstDetails show
16!define MUI_ABORTWARNING
17!define MUI_CUSTOMFUNCTION_ABORT Rollback
18!insertmacro MUI_PAGE_WELCOME
19!insertmacro MUI_PAGE_INSTFILES
20Page custom FinishCreate
21!insertmacro MUI_UNPAGE_CONFIRM
22!insertmacro MUI_UNPAGE_INSTFILES
23!insertmacro MUI_LANGUAGE "Korean"
24Var Dialog
25Var ApplyButton
26Var Mutex
27Var RootOwned
28Var ShortcutOwned
29Var UninstallOwned
30Var InstallComplete
31!define APPKEY "Software\Zipelo-Dev"
32!define PROGKEY "Software\Classes\ZipeloDev.Archive"
33!define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo-Dev"
34
35Function .onInit
36 ${IfNot} ${RunningX64}
37 MessageBox MB_OK|MB_ICONSTOP "64비트 Windows가 필요합니다."
38 Abort
39 ${EndIf}
40 SetShellVarContext current
41 SetRegView 64
42 System::Call 'kernel32::SetLastError(i 0)'
43 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e'
44 Pop $1
45 StrCpy $Mutex $0
46 ${If} $0 == 0
47 ${OrIf} $1 != 0
48 MessageBox MB_OK "다른 설치나 제거를 마친 뒤 다시 실행하세요."
49 Abort
50 ${EndIf}
51FunctionEnd
52
53Section "Zipelo"
54 ; /D로 바뀐 경로를 파일 쓰기 전에 고정하여 제거 경로와 일치시킴.
55 StrCpy $INSTDIR "${INSTALLROOT}"
56 ; 기존 설치와 등록을 덮어쓰지 않음.
57 IfFileExists "$INSTDIR" failed
58 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${APPKEY}", i 0, i 0x20119, *p.r1) i.r0'
59 ${If} $0 == 0
60 System::Call 'advapi32::RegCloseKey(p r1)'
61 Goto failed
62 ${ElseIf} $0 != 2
63 Goto failed
64 ${EndIf}
65 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${PROGKEY}", i 0, i 0x20119, *p.r1) i.r0'
66 ${If} $0 == 0
67 System::Call 'advapi32::RegCloseKey(p r1)'
68 Goto failed
69 ${ElseIf} $0 != 2
70 Goto failed
71 ${EndIf}
72 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${UNKEY}", i 0, i 0x20119, *p.r1) i.r0'
73 ${If} $0 == 0
74 System::Call 'advapi32::RegCloseKey(p r1)'
75 Goto failed
76 ${ElseIf} $0 != 2
77 Goto failed
78 ${EndIf}
79 ; 공유 등록 값이 이미 있으면 형식과 관계없이 보존함.
80 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\RegisteredApplications", i 0, i 0x20119, *p.r1) i.r0'
81 ${If} $0 == 0
82 System::Call 'advapi32::RegQueryValueExW(p r1, w "Zipelo 개발판", p 0, p 0, p 0, p 0) i.r2'
83 System::Call 'advapi32::RegCloseKey(p r1)'
84 ${If} $2 != 2
85 Goto failed
86 ${EndIf}
87 ${ElseIf} $0 != 2
88 Goto failed
89 ${EndIf}
90 IfFileExists "$SMPROGRAMS\Zipelo 개발판.lnk" failed
91 ClearErrors
92 CreateDirectory "$LOCALAPPDATA\Programs"
93 IfErrors failed
94 System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0'
95 IntCmp $0 0 failed
96 StrCpy $RootOwned 1
97 SetOutPath "$INSTDIR"
98 ClearErrors
99 File "payload\Zipelo.exe"
100 File "payload\zipelo-archive-worker.exe"
101 File "payload\LICENSE"
102 File "payload\THIRD-PARTY-LICENSES.txt"
103 File "payload\BUILD-INFO.json"
104 IfErrors failed
105 WriteUninstaller "$INSTDIR\Uninstall.exe"
106 IfErrors failed
107 WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR"
108 IfErrors failed
109 StrCpy $ShortcutOwned 1
110 CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe"
111 IfErrors failed
112 StrCpy $UninstallOwned 1
113 WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판"
114 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev"
115 WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"'
116 IfErrors failed
117 StrCpy $InstallComplete 1
118 Goto done
119failed:
120 Call Rollback
121 SetErrorLevel 1
122 MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 이번 설치 항목을 정리했으며, 사용 중이라 지우지 못한 항목은 상세 보기에서 확인하세요."
123 Abort
124 done:
125SectionEnd
126
127Function Rollback
128 ${If} $InstallComplete == 1
129 ${OrIf} $RootOwned != 1
130 Return
131 ${EndIf}
132 SetOutPath "$TEMP"
133 ${If} $ShortcutOwned == 1
134 Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
135 ${EndIf}
136 ${If} $UninstallOwned == 1
137 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
138 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
139 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
140 DeleteRegKey /ifempty HKCU "${UNKEY}"
141 ${EndIf}
142 Delete "$INSTDIR\Zipelo.exe"
143 Delete "$INSTDIR\zipelo-archive-worker.exe"
144 Delete "$INSTDIR\LICENSE"
145 Delete "$INSTDIR\THIRD-PARTY-LICENSES.txt"
146 Delete "$INSTDIR\BUILD-INFO.json"
147 Delete "$INSTDIR\install.ini"
148 Delete "$INSTDIR\Uninstall.exe"
149 RMDir "$INSTDIR"
150 StrCpy $RootOwned 0
151FunctionEnd
152
153Function .onInstFailed
154 Call Rollback
155 SetErrorLevel 1
156FunctionEnd
157
158Function FinishCreate
159 GetDlgItem $0 $HWNDPARENT 1
160 SendMessage $0 ${WM_SETTEXT} 0 "STR:마침"
161 GetDlgItem $0 $HWNDPARENT 3
162 EnableWindow $0 0
163 nsDialogs::Create 1018
164 Pop $Dialog
165 ${If} $Dialog == error
166 Abort
167 ${EndIf}
168 ${NSD_CreateLabel} 0 0 100% 28u "Zipelo 설치가 끝났습니다."
169 Pop $0
170 ${NSD_CreateLabel} 0 32u 100% 40u "[적용]을 누르면 Zipelo를 연결 프로그램으로 등록하고 Windows 기본 앱 설정을 엽니다. 기본 앱은 설정에서 직접 선택하세요."
171 Pop $0
172 ${NSD_CreateButton} 0 84u 100% 26u "적용"
173 Pop $ApplyButton
174 ${NSD_OnClick} $ApplyButton ApplyAssociations
175 nsDialogs::Show
176FunctionEnd
177
178Function ApplyAssociations
179 Pop $0
180 ClearErrors
181 WriteRegStr HKCU "${PROGKEY}" "" "Zipelo 압축파일"
182 WriteRegStr HKCU "${PROGKEY}\shell\open\command" "" '$\"$INSTDIR\Zipelo.exe$\" $\"%1$\"'
183 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationName" "Zipelo 개발판"
184 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationDescription" "압축파일 열기와 풀기"
185 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" "ZipeloDev.Archive"
186 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z" "ZipeloDev.Archive"
187 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" "ZipeloDev.Archive"
188 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" "ZipeloDev.Archive"
189 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" "ZipeloDev.Archive"
190 WriteRegStr HKCU "Software\RegisteredApplications" "Zipelo 개발판" "${APPKEY}\Capabilities"
191 IfErrors register_failed
192 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
193 ExecShell "open" "ms-settings:defaultapps"
194 IfErrors settings_failed
195 Return
196register_failed:
197 MessageBox MB_OK|MB_ICONSTOP "연결 프로그램을 등록하지 못했습니다. 쓰기 권한을 확인한 뒤 다시 적용하세요."
198 Return
199settings_failed:
200 MessageBox MB_OK "Windows 설정을 열지 못했습니다. 설정에서 앱 > 기본 앱을 직접 열어주세요."
201FunctionEnd
202
203Function un.onInit
204 SetShellVarContext current
205 SetRegView 64
206 System::Call 'kernel32::SetLastError(i 0)'
207 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e'
208 Pop $1
209 StrCpy $Mutex $0
210 ${If} $0 == 0
211 ${OrIf} $1 != 0
212 Abort
213 ${EndIf}
214 StrCmp $INSTDIR "${INSTALLROOT}" 0 invalid
215 ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location"
216 StrCmp $0 $INSTDIR 0 invalid
217 Return
218invalid:
219 MessageBox MB_OK|MB_ICONSTOP "설치 위치를 확인하지 못했습니다. 파일을 삭제하지 않습니다."
220 Abort
221FunctionEnd
222
223Section "Uninstall"
224 SetOutPath "$TEMP"
225 ClearErrors
226 Delete "$INSTDIR\Zipelo.exe"
227 Delete "$INSTDIR\zipelo-archive-worker.exe"
228 IfErrors uninstall_failed
229 Delete "$INSTDIR\LICENSE"
230 Delete "$INSTDIR\THIRD-PARTY-LICENSES.txt"
231 Delete "$INSTDIR\BUILD-INFO.json"
232 Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
233 IfErrors uninstall_failed
234 ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함.
235 ReadRegStr $0 HKCU "Software\RegisteredApplications" "Zipelo 개발판"
236 ${If} $0 == "${APPKEY}\Capabilities"
237 DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판"
238 ${EndIf}
239 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip"
240 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z"
241 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar"
242 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz"
243 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz"
244 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationName"
245 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationDescription"
246 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities\FileAssociations"
247 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities"
248 DeleteRegKey /ifempty HKCU "${APPKEY}"
249 DeleteRegValue HKCU "${PROGKEY}\shell\open\command" ""
250 DeleteRegValue HKCU "${PROGKEY}" ""
251 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open\command"
252 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open"
253 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell"
254 DeleteRegKey /ifempty HKCU "${PROGKEY}"
255 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
256 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
257 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
258 DeleteRegKey /ifempty HKCU "${UNKEY}"
259 Delete "$INSTDIR\install.ini"
260 Delete "$INSTDIR\Uninstall.exe"
261 RMDir "$INSTDIR"
262 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
263 Goto un_done
264uninstall_failed:
265 SetErrorLevel 1
266 MessageBox MB_OK|MB_ICONSTOP "Zipelo와 작업자를 닫은 뒤 제거 프로그램을 다시 실행하세요."
267 Abort
268un_done:
269SectionEnd