team-ljyzipelo

공개
266줄9.8 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\BUILD-INFO.json"
103 IfErrors failed
104 WriteUninstaller "$INSTDIR\Uninstall.exe"
105 IfErrors failed
106 WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR"
107 IfErrors failed
108 StrCpy $ShortcutOwned 1
109 CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe"
110 IfErrors failed
111 StrCpy $UninstallOwned 1
112 WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판"
113 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev"
114 WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"'
115 IfErrors failed
116 StrCpy $InstallComplete 1
117 Goto done
118failed:
119 Call Rollback
120 SetErrorLevel 1
121 MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 이번 설치 항목을 정리했으며, 사용 중이라 지우지 못한 항목은 상세 보기에서 확인하세요."
122 Abort
123 done:
124SectionEnd
125
126Function Rollback
127 ${If} $InstallComplete == 1
128 ${OrIf} $RootOwned != 1
129 Return
130 ${EndIf}
131 SetOutPath "$TEMP"
132 ${If} $ShortcutOwned == 1
133 Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
134 ${EndIf}
135 ${If} $UninstallOwned == 1
136 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
137 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
138 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
139 DeleteRegKey /ifempty HKCU "${UNKEY}"
140 ${EndIf}
141 Delete "$INSTDIR\Zipelo.exe"
142 Delete "$INSTDIR\zipelo-archive-worker.exe"
143 Delete "$INSTDIR\LICENSE"
144 Delete "$INSTDIR\BUILD-INFO.json"
145 Delete "$INSTDIR\install.ini"
146 Delete "$INSTDIR\Uninstall.exe"
147 RMDir "$INSTDIR"
148 StrCpy $RootOwned 0
149FunctionEnd
150
151Function .onInstFailed
152 Call Rollback
153 SetErrorLevel 1
154FunctionEnd
155
156Function FinishCreate
157 GetDlgItem $0 $HWNDPARENT 1
158 SendMessage $0 ${WM_SETTEXT} 0 "STR:마침"
159 GetDlgItem $0 $HWNDPARENT 3
160 EnableWindow $0 0
161 nsDialogs::Create 1018
162 Pop $Dialog
163 ${If} $Dialog == error
164 Abort
165 ${EndIf}
166 ${NSD_CreateLabel} 0 0 100% 28u "Zipelo 설치가 끝났습니다."
167 Pop $0
168 ${NSD_CreateLabel} 0 32u 100% 40u "[적용]을 누르면 Zipelo를 연결 프로그램으로 등록하고 Windows 기본 앱 설정을 엽니다. 기본 앱은 설정에서 직접 선택하세요."
169 Pop $0
170 ${NSD_CreateButton} 0 84u 100% 26u "적용"
171 Pop $ApplyButton
172 ${NSD_OnClick} $ApplyButton ApplyAssociations
173 nsDialogs::Show
174FunctionEnd
175
176Function ApplyAssociations
177 Pop $0
178 ClearErrors
179 WriteRegStr HKCU "${PROGKEY}" "" "Zipelo 압축파일"
180 WriteRegStr HKCU "${PROGKEY}\shell\open\command" "" '$\"$INSTDIR\Zipelo.exe$\" $\"%1$\"'
181 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationName" "Zipelo 개발판"
182 WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationDescription" "압축파일 열기와 풀기"
183 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" "ZipeloDev.Archive"
184 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z" "ZipeloDev.Archive"
185 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" "ZipeloDev.Archive"
186 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" "ZipeloDev.Archive"
187 WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" "ZipeloDev.Archive"
188 WriteRegStr HKCU "Software\RegisteredApplications" "Zipelo 개발판" "${APPKEY}\Capabilities"
189 IfErrors register_failed
190 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
191 ExecShell "open" "ms-settings:defaultapps"
192 IfErrors settings_failed
193 Return
194register_failed:
195 MessageBox MB_OK|MB_ICONSTOP "연결 프로그램을 등록하지 못했습니다. 쓰기 권한을 확인한 뒤 다시 적용하세요."
196 Return
197settings_failed:
198 MessageBox MB_OK "Windows 설정을 열지 못했습니다. 설정에서 앱 > 기본 앱을 직접 열어주세요."
199FunctionEnd
200
201Function un.onInit
202 SetShellVarContext current
203 SetRegView 64
204 System::Call 'kernel32::SetLastError(i 0)'
205 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e'
206 Pop $1
207 StrCpy $Mutex $0
208 ${If} $0 == 0
209 ${OrIf} $1 != 0
210 Abort
211 ${EndIf}
212 StrCmp $INSTDIR "${INSTALLROOT}" 0 invalid
213 ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location"
214 StrCmp $0 $INSTDIR 0 invalid
215 Return
216invalid:
217 MessageBox MB_OK|MB_ICONSTOP "설치 위치를 확인하지 못했습니다. 파일을 삭제하지 않습니다."
218 Abort
219FunctionEnd
220
221Section "Uninstall"
222 SetOutPath "$TEMP"
223 ClearErrors
224 Delete "$INSTDIR\Zipelo.exe"
225 Delete "$INSTDIR\zipelo-archive-worker.exe"
226 IfErrors uninstall_failed
227 Delete "$INSTDIR\LICENSE"
228 Delete "$INSTDIR\BUILD-INFO.json"
229 Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
230 IfErrors uninstall_failed
231 ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함.
232 ReadRegStr $0 HKCU "Software\RegisteredApplications" "Zipelo 개발판"
233 ${If} $0 == "${APPKEY}\Capabilities"
234 DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판"
235 ${EndIf}
236 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip"
237 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".7z"
238 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar"
239 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz"
240 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz"
241 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationName"
242 DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationDescription"
243 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities\FileAssociations"
244 DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities"
245 DeleteRegKey /ifempty HKCU "${APPKEY}"
246 DeleteRegValue HKCU "${PROGKEY}\shell\open\command" ""
247 DeleteRegValue HKCU "${PROGKEY}" ""
248 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open\command"
249 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open"
250 DeleteRegKey /ifempty HKCU "${PROGKEY}\shell"
251 DeleteRegKey /ifempty HKCU "${PROGKEY}"
252 DeleteRegValue HKCU "${UNKEY}" "DisplayName"
253 DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
254 DeleteRegValue HKCU "${UNKEY}" "UninstallString"
255 DeleteRegKey /ifempty HKCU "${UNKEY}"
256 Delete "$INSTDIR\install.ini"
257 Delete "$INSTDIR\Uninstall.exe"
258 RMDir "$INSTDIR"
259 System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)'
260 Goto un_done
261uninstall_failed:
262 SetErrorLevel 1
263 MessageBox MB_OK|MB_ICONSTOP "Zipelo와 작업자를 닫은 뒤 제거 프로그램을 다시 실행하세요."
264 Abort
265un_done:
266SectionEnd