| 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-dev-windows-x64-setup.exe" |
| 9 | InstallDir "$LOCALAPPDATA\Programs\Zipelo-Dev" |
| 10 | RequestExecutionLevel user |
| 11 | SetCompressor /SOLID lzma |
| 12 | SetOverwrite off |
| 13 | AllowSkipFiles off |
| 14 | ShowInstDetails show |
| 15 | !define MUI_ABORTWARNING |
| 16 | !insertmacro MUI_PAGE_WELCOME |
| 17 | !insertmacro MUI_PAGE_INSTFILES |
| 18 | Page custom FinishCreate |
| 19 | !insertmacro MUI_UNPAGE_CONFIRM |
| 20 | !insertmacro MUI_UNPAGE_INSTFILES |
| 21 | !insertmacro MUI_LANGUAGE "Korean" |
| 22 | Var Dialog |
| 23 | Var ApplyButton |
| 24 | Var Mutex |
| 25 | !define APPKEY "Software\Zipelo-Dev" |
| 26 | !define PROGKEY "Software\Classes\ZipeloDev.Archive" |
| 27 | !define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo-Dev" |
| 28 | |
| 29 | Function .onInit |
| 30 | ${IfNot} ${RunningX64} |
| 31 | MessageBox MB_OK|MB_ICONSTOP "64비트 Windows가 필요합니다." |
| 32 | Abort |
| 33 | ${EndIf} |
| 34 | SetShellVarContext current |
| 35 | SetRegView 64 |
| 36 | System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' |
| 37 | Pop $1 |
| 38 | StrCpy $Mutex $0 |
| 39 | ${If} $0 == 0 |
| 40 | ${OrIf} $1 != 0 |
| 41 | MessageBox MB_OK "다른 설치나 제거를 마친 뒤 다시 실행하세요." |
| 42 | Abort |
| 43 | ${EndIf} |
| 44 | FunctionEnd |
| 45 | |
| 46 | Section "Zipelo" |
| 47 | ; 기존 설치와 등록을 덮어쓰지 않음. |
| 48 | IfFileExists "$INSTDIR" failed |
| 49 | System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${APPKEY}", i 0, i 0x20119, *p.r1) i.r0' |
| 50 | ${If} $0 == 0 |
| 51 | System::Call 'advapi32::RegCloseKey(p r1)' |
| 52 | Goto failed |
| 53 | ${ElseIf} $0 != 2 |
| 54 | Goto failed |
| 55 | ${EndIf} |
| 56 | System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${PROGKEY}", i 0, i 0x20119, *p.r1) i.r0' |
| 57 | ${If} $0 == 0 |
| 58 | System::Call 'advapi32::RegCloseKey(p r1)' |
| 59 | Goto failed |
| 60 | ${ElseIf} $0 != 2 |
| 61 | Goto failed |
| 62 | ${EndIf} |
| 63 | System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${UNKEY}", i 0, i 0x20119, *p.r1) i.r0' |
| 64 | ${If} $0 == 0 |
| 65 | System::Call 'advapi32::RegCloseKey(p r1)' |
| 66 | Goto failed |
| 67 | ${ElseIf} $0 != 2 |
| 68 | Goto failed |
| 69 | ${EndIf} |
| 70 | IfFileExists "$SMPROGRAMS\Zipelo 개발판.lnk" failed |
| 71 | ClearErrors |
| 72 | CreateDirectory "$LOCALAPPDATA\Programs" |
| 73 | IfErrors failed |
| 74 | System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0' |
| 75 | IntCmp $0 0 failed |
| 76 | SetOutPath "$INSTDIR" |
| 77 | ClearErrors |
| 78 | File "payload\Zipelo.exe" |
| 79 | File "payload\zipelo-archive-worker.exe" |
| 80 | File "payload\LICENSE" |
| 81 | File "payload\BUILD-INFO.json" |
| 82 | IfErrors failed |
| 83 | WriteUninstaller "$INSTDIR\Uninstall.exe" |
| 84 | IfErrors failed |
| 85 | WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR" |
| 86 | IfErrors failed |
| 87 | CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe" |
| 88 | IfErrors failed |
| 89 | WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판" |
| 90 | WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev" |
| 91 | WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"' |
| 92 | IfErrors failed |
| 93 | Goto done |
| 94 | failed: |
| 95 | SetErrorLevel 1 |
| 96 | MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 새로 복사한 파일이 남았다면 해당 폴더의 제거 프로그램을 사용하세요." |
| 97 | Abort |
| 98 | done: |
| 99 | SectionEnd |
| 100 | |
| 101 | Function FinishCreate |
| 102 | GetDlgItem $0 $HWNDPARENT 1 |
| 103 | SendMessage $0 ${WM_SETTEXT} 0 "STR:마침" |
| 104 | GetDlgItem $0 $HWNDPARENT 3 |
| 105 | EnableWindow $0 0 |
| 106 | nsDialogs::Create 1018 |
| 107 | Pop $Dialog |
| 108 | ${If} $Dialog == error |
| 109 | Abort |
| 110 | ${EndIf} |
| 111 | ${NSD_CreateLabel} 0 0 100% 28u "Zipelo 설치가 끝났습니다." |
| 112 | Pop $0 |
| 113 | ${NSD_CreateLabel} 0 32u 100% 40u "[적용]을 누르면 Zipelo를 연결 프로그램으로 등록하고 Windows 기본 앱 설정을 엽니다. 기본 앱은 설정에서 직접 선택하세요." |
| 114 | Pop $0 |
| 115 | ${NSD_CreateButton} 0 84u 100% 26u "적용" |
| 116 | Pop $ApplyButton |
| 117 | ${NSD_OnClick} $ApplyButton ApplyAssociations |
| 118 | nsDialogs::Show |
| 119 | FunctionEnd |
| 120 | |
| 121 | Function ApplyAssociations |
| 122 | Pop $0 |
| 123 | ClearErrors |
| 124 | WriteRegStr HKCU "${PROGKEY}" "" "Zipelo 압축파일" |
| 125 | WriteRegStr HKCU "${PROGKEY}\shell\open\command" "" '$\"$INSTDIR\Zipelo.exe$\" $\"%1$\"' |
| 126 | WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationName" "Zipelo 개발판" |
| 127 | WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationDescription" "압축파일 열기와 풀기" |
| 128 | WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" "ZipeloDev.Archive" |
| 129 | WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" "ZipeloDev.Archive" |
| 130 | WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" "ZipeloDev.Archive" |
| 131 | WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" "ZipeloDev.Archive" |
| 132 | WriteRegStr HKCU "Software\RegisteredApplications" "Zipelo 개발판" "${APPKEY}\Capabilities" |
| 133 | IfErrors register_failed |
| 134 | System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)' |
| 135 | ExecShell "open" "ms-settings:defaultapps" |
| 136 | IfErrors settings_failed |
| 137 | Return |
| 138 | register_failed: |
| 139 | MessageBox MB_OK|MB_ICONSTOP "연결 프로그램을 등록하지 못했습니다. 쓰기 권한을 확인한 뒤 다시 적용하세요." |
| 140 | Return |
| 141 | settings_failed: |
| 142 | MessageBox MB_OK "Windows 설정을 열지 못했습니다. 설정에서 앱 > 기본 앱을 직접 열어주세요." |
| 143 | FunctionEnd |
| 144 | |
| 145 | Function un.onInit |
| 146 | SetShellVarContext current |
| 147 | SetRegView 64 |
| 148 | System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' |
| 149 | Pop $1 |
| 150 | StrCpy $Mutex $0 |
| 151 | ${If} $0 == 0 |
| 152 | ${OrIf} $1 != 0 |
| 153 | Abort |
| 154 | ${EndIf} |
| 155 | StrCmp $INSTDIR "$LOCALAPPDATA\Programs\Zipelo-Dev" 0 invalid |
| 156 | ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location" |
| 157 | StrCmp $0 $INSTDIR 0 invalid |
| 158 | Return |
| 159 | invalid: |
| 160 | MessageBox MB_OK|MB_ICONSTOP "설치 위치를 확인하지 못했습니다. 파일을 삭제하지 않습니다." |
| 161 | Abort |
| 162 | FunctionEnd |
| 163 | |
| 164 | Section "Uninstall" |
| 165 | SetOutPath "$TEMP" |
| 166 | ClearErrors |
| 167 | Delete "$INSTDIR\Zipelo.exe" |
| 168 | Delete "$INSTDIR\zipelo-archive-worker.exe" |
| 169 | IfErrors uninstall_failed |
| 170 | Delete "$INSTDIR\LICENSE" |
| 171 | Delete "$INSTDIR\BUILD-INFO.json" |
| 172 | Delete "$SMPROGRAMS\Zipelo 개발판.lnk" |
| 173 | ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함. |
| 174 | DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판" |
| 175 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" |
| 176 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" |
| 177 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" |
| 178 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" |
| 179 | DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationName" |
| 180 | DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationDescription" |
| 181 | DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities\FileAssociations" |
| 182 | DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities" |
| 183 | DeleteRegKey /ifempty HKCU "${APPKEY}" |
| 184 | DeleteRegValue HKCU "${PROGKEY}\shell\open\command" "" |
| 185 | DeleteRegValue HKCU "${PROGKEY}" "" |
| 186 | DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open\command" |
| 187 | DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open" |
| 188 | DeleteRegKey /ifempty HKCU "${PROGKEY}\shell" |
| 189 | DeleteRegKey /ifempty HKCU "${PROGKEY}" |
| 190 | DeleteRegValue HKCU "${UNKEY}" "DisplayName" |
| 191 | DeleteRegValue HKCU "${UNKEY}" "DisplayVersion" |
| 192 | DeleteRegValue HKCU "${UNKEY}" "UninstallString" |
| 193 | DeleteRegKey /ifempty HKCU "${UNKEY}" |
| 194 | Delete "$INSTDIR\install.ini" |
| 195 | Delete "$INSTDIR\Uninstall.exe" |
| 196 | RMDir "$INSTDIR" |
| 197 | System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)' |
| 198 | Goto un_done |
| 199 | uninstall_failed: |
| 200 | SetErrorLevel 1 |
| 201 | MessageBox MB_OK|MB_ICONSTOP "Zipelo와 작업자를 닫은 뒤 제거 프로그램을 다시 실행하세요." |
| 202 | Abort |
| 203 | un_done: |
| 204 | SectionEnd |