team-ljyzipelo

공개
455줄16 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-windows-x64-setup.exe"
9!define INSTALLROOT "$LOCALAPPDATA\Programs\Zipelo"
10InstallDir "${INSTALLROOT}"
11RequestExecutionLevel user
12SetCompressor /SOLID lzma
13SetOverwrite off
14AllowSkipFiles off
15ShowInstDetails show
16!define MUI_ICON "zipelo.ico"
17!define MUI_UNICON "zipelo.ico"
18!define MUI_ABORTWARNING
19!define MUI_CUSTOMFUNCTION_ABORT Rollback
20!insertmacro MUI_PAGE_WELCOME
21!insertmacro MUI_PAGE_INSTFILES
22Page custom FinishCreate
23!insertmacro MUI_UNPAGE_CONFIRM
24!insertmacro MUI_UNPAGE_INSTFILES
25!insertmacro MUI_LANGUAGE "Korean"
26Var Dialog
27Var ApplyButton
28Var Mutex
29Var RootOwned
30Var ShortcutOwned
31Var UninstallOwned
32Var InstallComplete
33Var Upgrading
34Var StageDir
35Var BackupBits
36Var PublishedBits
37Var RestoreFailed
38Var OldVersion
39Var VersionChanged
40!define APPKEY "Software\Zipelo"
41!define PROGKEY "Software\Classes\Zipelo.Archive"
42!define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo"
43
44; 기존 앱을 먼저 치우고 새 앱은 마지막에 공개하여 버전 혼합 실행을 줄임.
45!macro BackupFile NAME BIT
46 ClearErrors
47 Rename "$INSTDIR\${NAME}" "$StageDir\previous\${NAME}"
48 IfErrors failed
49 IntOp $BackupBits $BackupBits | ${BIT}
50!macroend
51
52!macro PublishFile NAME BIT
53 ClearErrors
54 Rename "$StageDir\${NAME}" "$INSTDIR\${NAME}"
55 IfErrors failed
56 IntOp $PublishedBits $PublishedBits | ${BIT}
57!macroend
58
59!macro RestoreFile NAME BIT
60 IntOp $0 $PublishedBits & ${BIT}
61 ${If} $0 != 0
62 ClearErrors
63 Delete "$INSTDIR\${NAME}"
64 ${If} ${Errors}
65 StrCpy $RestoreFailed 1
66 ${Else}
67 IntOp $PublishedBits $PublishedBits ^ ${BIT}
68 ${EndIf}
69 ${EndIf}
70 IntOp $0 $BackupBits & ${BIT}
71 ${If} $0 != 0
72 ClearErrors
73 Rename "$StageDir\previous\${NAME}" "$INSTDIR\${NAME}"
74 ${If} ${Errors}
75 StrCpy $RestoreFailed 1
76 ${Else}
77 IntOp $BackupBits $BackupBits ^ ${BIT}
78 ${EndIf}
79 ${EndIf}
80!macroend
81
82!macro CleanupStageFile NAME
83 Delete "$StageDir\${NAME}"
84 ${If} $InstallComplete == 1
85 Delete "$StageDir\previous\${NAME}"
86 ${EndIf}
87!macroend
88
89!macro CheckInstalledFile NAME
90 System::Call 'kernel32::GetFileAttributesW(w "$INSTDIR\${NAME}") i.r0'
91 ${If} $0 == -1
92 Goto failed
93 ${EndIf}
94 IntOp $0 $0 & 0x410
95 ${If} $0 != 0
96 Goto failed
97 ${EndIf}
98!macroend
99
100Function .onInit
101 ${IfNot} ${RunningX64}
102 MessageBox MB_OK|MB_ICONSTOP "64비트 Windows가 필요합니다."
103 Abort
104 ${EndIf}
105 SetShellVarContext current
106 SetRegView 64
107 System::Call 'kernel32::SetLastError(i 0)'
108 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloSetup") p.r0 ?e'
109 Pop $1
110 StrCpy $Mutex $0
111 ${If} $0 == 0
112 ${OrIf} $1 != 0
113 MessageBox MB_OK "다른 설치나 제거를 마친 뒤 다시 실행하세요."
114 Abort
115 ${EndIf}
116FunctionEnd
117
118Section "Zipelo"
119 ; /D로 바뀐 경로를 파일 쓰기 전에 고정하여 제거 경로와 일치시킴.
120 StrCpy $INSTDIR "${INSTALLROOT}"
121 ; 설치 표식과 제거 등록이 일치하는 기존 설치만 업데이트함.
122 IfFileExists "$INSTDIR" upgrade
123 Goto fresh
124upgrade:
125 System::Call 'kernel32::GetFileAttributesW(w "$INSTDIR") i.r0'
126 IntOp $0 $0 & 0x410
127 IntCmp $0 0x10 0 failed failed
128 ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location"
129 StrCmp $0 $INSTDIR 0 failed
130 ReadRegStr $0 HKCU "${UNKEY}" "UninstallString"
131 StrCmp $0 '$\"$INSTDIR\Uninstall.exe$\"' 0 failed
132 !insertmacro CheckInstalledFile "Zipelo.exe"
133 !insertmacro CheckInstalledFile "zipelo-archive-worker.exe"
134 !insertmacro CheckInstalledFile "LICENSE"
135 !insertmacro CheckInstalledFile "THIRD-PARTY-LICENSES.txt"
136 !insertmacro CheckInstalledFile "BUILD-INFO.json"
137 !insertmacro CheckInstalledFile "Uninstall.exe"
138 !insertmacro CheckInstalledFile "install.ini"
139 ClearErrors
140 ReadRegStr $OldVersion HKCU "${UNKEY}" "DisplayVersion"
141 IfErrors failed
142 StrCpy $Upgrading 1
143 Goto prepare
144fresh:
145 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${APPKEY}", i 0, i 0x20119, *p.r1) i.r0'
146 ${If} $0 == 0
147 System::Call 'advapi32::RegCloseKey(p r1)'
148 Goto failed
149 ${ElseIf} $0 != 2
150 Goto failed
151 ${EndIf}
152 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${PROGKEY}", i 0, i 0x20119, *p.r1) i.r0'
153 ${If} $0 == 0
154 System::Call 'advapi32::RegCloseKey(p r1)'
155 Goto failed
156 ${ElseIf} $0 != 2
157 Goto failed
158 ${EndIf}
159 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${UNKEY}", i 0, i 0x20119, *p.r1) i.r0'
160 ${If} $0 == 0
161 System::Call 'advapi32::RegCloseKey(p r1)'
162 Goto failed
163 ${ElseIf} $0 != 2
164 Goto failed
165 ${EndIf}
166 ; 공유 등록 값이 이미 있으면 형식과 관계없이 보존함.
167 System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\RegisteredApplications", i 0, i 0x20119, *p.r1) i.r0'
168 ${If} $0 == 0
169 System::Call 'advapi32::RegQueryValueExW(p r1, w "Zipelo", p 0, p 0, p 0, p 0) i.r2'
170 System::Call 'advapi32::RegCloseKey(p r1)'
171 ${If} $2 != 2
172 Goto failed
173 ${EndIf}
174 ${ElseIf} $0 != 2
175 Goto failed
176 ${EndIf}
177 IfFileExists "$SMPROGRAMS\Zipelo.lnk" failed
178 ClearErrors
179 CreateDirectory "$LOCALAPPDATA\Programs"
180 IfErrors failed
181 System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0'
182 IntCmp $0 0 failed
183 StrCpy $RootOwned 1
184prepare:
185 ; 같은 볼륨에 새 파일을 모두 준비한 뒤에만 기존 파일을 이동함.
186 ClearErrors
187 GetTempFileName $StageDir "$LOCALAPPDATA\Programs"
188 IfErrors failed
189 Delete "$StageDir"
190 System::Call 'kernel32::CreateDirectoryW(w "$StageDir", p 0) i.r0'
191 ${If} $0 == 0
192 StrCpy $StageDir ""
193 Goto failed
194 ${EndIf}
195 SetOutPath "$StageDir"
196 ClearErrors
197 File "payload\Zipelo.exe"
198 File "payload\zipelo-archive-worker.exe"
199 File "payload\LICENSE"
200 File "payload\THIRD-PARTY-LICENSES.txt"
201 File "payload\BUILD-INFO.json"
202 IfErrors failed
203 WriteUninstaller "$StageDir\Uninstall.exe"
204 IfErrors failed
205 WriteINIStr "$StageDir\install.ini" "Zipelo" "Location" "$INSTDIR"
206 IfErrors failed
207 ${If} $Upgrading == 1
208 ; 준비 후 취소하면 기존 설치와 연결은 전혀 바뀌지 않음.
209 MessageBox MB_OKCANCEL|MB_ICONINFORMATION "업데이트 준비가 끝났습니다. Zipelo와 압축 작업을 닫고 [확인]을 누르세요. [취소]를 누르면 기존 설치를 유지합니다." /SD IDOK IDCANCEL cancelled
210 CreateDirectory "$StageDir\previous"
211 IfErrors failed
212 !insertmacro BackupFile "Zipelo.exe" 1
213 !insertmacro BackupFile "zipelo-archive-worker.exe" 2
214 !insertmacro BackupFile "LICENSE" 4
215 !insertmacro BackupFile "THIRD-PARTY-LICENSES.txt" 8
216 !insertmacro BackupFile "BUILD-INFO.json" 16
217 !insertmacro BackupFile "Uninstall.exe" 32
218 !insertmacro BackupFile "install.ini" 64
219 ${EndIf}
220 !insertmacro PublishFile "zipelo-archive-worker.exe" 2
221 !insertmacro PublishFile "LICENSE" 4
222 !insertmacro PublishFile "THIRD-PARTY-LICENSES.txt" 8
223 !insertmacro PublishFile "BUILD-INFO.json" 16
224 !insertmacro PublishFile "Uninstall.exe" 32
225 !insertmacro PublishFile "install.ini" 64
226 !insertmacro PublishFile "Zipelo.exe" 1
227 ${If} $Upgrading == 1
228 StrCpy $VersionChanged 1
229 ClearErrors
230 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0"
231 IfErrors failed
232 Goto committed
233 ${EndIf}
234 StrCpy $ShortcutOwned 1
235 CreateShortcut "$SMPROGRAMS\Zipelo.lnk" "$INSTDIR\Zipelo.exe"
236 IfErrors failed
237 StrCpy $UninstallOwned 1
238 WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo"
239 WriteRegStr HKCU "${UNKEY}" "DisplayIcon" '$\"$INSTDIR\Zipelo.exe$\",0'
240 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0"
241 WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"'
242 IfErrors failed
243committed:
244 StrCpy $InstallComplete 1
245 Call CleanupStage
246 Goto done
247cancelled:
248 Call Rollback
249 SetErrorLevel 2
250 Abort "업데이트를 취소했습니다"
251failed:
252 Call Rollback
253 SetErrorLevel 1
254 MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. Zipelo와 압축 작업을 닫고 여유 공간과 쓰기 권한을 확인하세요. 복원하지 못한 파일이 있으면 상세 보기의 백업 경로를 보존하고 다시 설치하지 마세요." /SD IDOK
255 Abort
256 done:
257SectionEnd
258
259Function Rollback
260 ${If} $InstallComplete == 1
261 Return
262 ${EndIf}
263 ${If} $Upgrading == 1
264 SetOutPath "$TEMP"
265 !insertmacro RestoreFile "zipelo-archive-worker.exe" 2
266 !insertmacro RestoreFile "LICENSE" 4
267 !insertmacro RestoreFile "THIRD-PARTY-LICENSES.txt" 8
268 !insertmacro RestoreFile "BUILD-INFO.json" 16
269 !insertmacro RestoreFile "Uninstall.exe" 32
270 !insertmacro RestoreFile "install.ini" 64
271 !insertmacro RestoreFile "Zipelo.exe" 1
272 ${If} $VersionChanged == 1
273 ClearErrors
274 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "$OldVersion"
275 ${If} ${Errors}
276 StrCpy $RestoreFailed 1
277 ${Else}
278 StrCpy $VersionChanged 0
279 ${EndIf}
280 ${EndIf}
281 ${If} $RestoreFailed == 1
282 DetailPrint "복원 실패: 백업 폴더 $StageDir\previous 를 보존하세요."
283 ${EndIf}
284 Call CleanupStage
285 Return
286 ${EndIf}
287 Call CleanupStage
288 ${If} $RootOwned != 1
289 Return
290 ${EndIf}
291 SetOutPath "$TEMP"
292 ${If} $ShortcutOwned == 1
293 Delete "$SMPROGRAMS\Zipelo.lnk"
294 ${EndIf}
295 ${If} $UninstallOwned == 1
296 DeleteRegValue HKCU "${UNKEY}" "DisplayIcon"
297 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
298 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
299 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
300 DeleteRegKey /ifempty HKCU "${UNKEY}"
301 ${EndIf}
302 Delete "$INSTDIR\Zipelo.exe"
303 Delete "$INSTDIR\zipelo-archive-worker.exe"
304 Delete "$INSTDIR\LICENSE"
305 Delete "$INSTDIR\THIRD-PARTY-LICENSES.txt"
306 Delete "$INSTDIR\BUILD-INFO.json"
307 Delete "$INSTDIR\install.ini"
308 Delete "$INSTDIR\Uninstall.exe"
309 RMDir "$INSTDIR"
310 StrCpy $RootOwned 0
311FunctionEnd
312
313Function CleanupStage
314 ${If} $StageDir == ""
315 Return
316 ${EndIf}
317 SetOutPath "$TEMP"
318 !insertmacro CleanupStageFile "Zipelo.exe"
319 !insertmacro CleanupStageFile "zipelo-archive-worker.exe"
320 !insertmacro CleanupStageFile "LICENSE"
321 !insertmacro CleanupStageFile "THIRD-PARTY-LICENSES.txt"
322 !insertmacro CleanupStageFile "BUILD-INFO.json"
323 !insertmacro CleanupStageFile "Uninstall.exe"
324 !insertmacro CleanupStageFile "install.ini"
325 RMDir "$StageDir\previous"
326 ClearErrors
327 RMDir "$StageDir"
328 ${If} ${Errors}
329 DetailPrint "임시 파일 또는 복원 백업이 남아 있음: $StageDir"
330 ${Else}
331 StrCpy $StageDir ""
332 ${EndIf}
333FunctionEnd
334
335Function .onInstFailed
336 Call Rollback
337 SetErrorLevel 1
338FunctionEnd
339
340Function FinishCreate
341 GetDlgItem $0 $HWNDPARENT 1
342 SendMessage $0 ${WM_SETTEXT} 0 "STR:마침"
343 GetDlgItem $0 $HWNDPARENT 3
344 EnableWindow $0 0
345 nsDialogs::Create 1018
346 Pop $Dialog
347 ${If} $Dialog == error
348 Abort
349 ${EndIf}
350 ${NSD_CreateLabel} 0 0 100% 28u "Zipelo 설치가 끝났습니다."
351 Pop $0
352 ${NSD_CreateLabel} 0 32u 100% 40u "[적용]을 누르면 Zipelo를 연결 프로그램으로 등록하고 Windows 기본 앱 설정을 엽니다. 기본 앱은 설정에서 직접 선택하세요."
353 Pop $0
354 ${NSD_CreateButton} 0 84u 100% 26u "적용"
355 Pop $ApplyButton
356 ${NSD_OnClick} $ApplyButton ApplyAssociations
357 nsDialogs::Show
358FunctionEnd
359
360Function ApplyAssociations
361 Pop $0
362 ClearErrors
363 WriteRegStr HKCU "${PROGKEY}" "" "Zipelo 압축파일"
364 WriteRegStr HKCU "${PROGKEY}\DefaultIcon" "" '$\"$INSTDIR\Zipelo.exe$\",0'
365 WriteRegStr HKCU "${PROGKEY}\shell\open\command" "" '$\"$INSTDIR\Zipelo.exe$\" $\"%1$\"'
366 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationName" "Zipelo"
367 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationDescription" "압축파일 열기와 풀기"
368 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" "Zipelo.Archive"
369 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z" "Zipelo.Archive"
370 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" "Zipelo.Archive"
371 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" "Zipelo.Archive"
372 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" "Zipelo.Archive"
373 WriteRegStr HKCU "Software\RegisteredApplications" "Zipelo" "${APPKEY}\Capabilities"
374 IfErrors register_failed
375 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
376 ExecShell "open" "ms-settings:defaultapps"
377 IfErrors settings_failed
378 Return
379register_failed:
380 MessageBox MB_OK|MB_ICONSTOP "연결 프로그램을 등록하지 못했습니다. 쓰기 권한을 확인한 뒤 다시 적용하세요."
381 Return
382settings_failed:
383 MessageBox MB_OK "Windows 설정을 열지 못했습니다. 설정에서 앱 > 기본 앱을 직접 열어주세요."
384FunctionEnd
385
386Function un.onInit
387 SetShellVarContext current
388 SetRegView 64
389 System::Call 'kernel32::SetLastError(i 0)'
390 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloSetup") p.r0 ?e'
391 Pop $1
392 StrCpy $Mutex $0
393 ${If} $0 == 0
394 ${OrIf} $1 != 0
395 Abort
396 ${EndIf}
397 StrCmp $INSTDIR "${INSTALLROOT}" 0 invalid
398 ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location"
399 StrCmp $0 $INSTDIR 0 invalid
400 Return
401invalid:
402 MessageBox MB_OK|MB_ICONSTOP "설치 위치를 확인하지 못했습니다. 파일을 삭제하지 않습니다."
403 Abort
404FunctionEnd
405
406Section "Uninstall"
407 SetOutPath "$TEMP"
408 ClearErrors
409 Delete "$INSTDIR\Zipelo.exe"
410 Delete "$INSTDIR\zipelo-archive-worker.exe"
411 IfErrors uninstall_failed
412 Delete "$INSTDIR\LICENSE"
413 Delete "$INSTDIR\THIRD-PARTY-LICENSES.txt"
414 Delete "$INSTDIR\BUILD-INFO.json"
415 Delete "$SMPROGRAMS\Zipelo.lnk"
416 IfErrors uninstall_failed
417 ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함.
418 ReadRegStr $0 HKCU "Software\RegisteredApplications" "Zipelo"
419 ${If} $0 == "${APPKEY}\Capabilities"
420 DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo"
421 ${EndIf}
422 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip"
423 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z"
424 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar"
425 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz"
426 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz"
427 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationName"
428 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationDescription"
429 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities\FileAssociations"
430 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities"
431 DeleteRegKey /ifempty HKCU "${APPKEY}"
432 DeleteRegValue HKCU "${PROGKEY}\shell\open\command" ""
433 DeleteRegValue HKCU "${PROGKEY}\DefaultIcon" ""
434 DeleteRegKey /ifempty HKCU "${PROGKEY}\DefaultIcon"
435 DeleteRegValue HKCU "${PROGKEY}" ""
436 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open\command"
437 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open"
438 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell"
439 DeleteRegKey /ifempty HKCU "${PROGKEY}"
440 DeleteRegValue HKCU "${UNKEY}" "DisplayIcon"
441 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
442 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
443 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
444 DeleteRegKey /ifempty HKCU "${UNKEY}"
445 Delete "$INSTDIR\install.ini"
446 Delete "$INSTDIR\Uninstall.exe"
447 RMDir "$INSTDIR"
448 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
449 Goto un_done
450uninstall_failed:
451 SetErrorLevel 1
452 MessageBox MB_OK|MB_ICONSTOP "Zipelo와 작업자를 닫은 뒤 제거 프로그램을 다시 실행하세요."
453 Abort
454un_done:
455SectionEnd