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