- The icon pass also walks the start menus' folders, so a shortcut kept in one (and a later icon change) is not missed. - The install folder and icon path reach PowerShell through the environment: a folder name with an apostrophe broke the whole command. A failure is now a line in the install details. - InstallDirRegKey read the 32-bit registry view before .onInit switched to the 64-bit one where the folder is written, so a silent update of Jarvis installed elsewhere put a second copy in Program Files. .onInit now reads the 64-bit key; a folder given with /D wins. - Version 0.1.12. Checked on the Windows VM with Jarvis 0.1.6 in C:\Tools\Kim's Jarvis and shortcuts on both desktops and in start menu subfolders: 0.1.11 left the desktop and subfolder shortcuts old; 0.1.12 (no /D) updated that folder and every shortcut, and a fresh 0.1.12 still goes to Program Files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
344 lines
13 KiB
NSIS
344 lines
13 KiB
NSIS
; The Jarvis installer (admin.spec.md, "Installer"). Built on Linux by installer.sh with makensis:
|
|
; makensis -DVERSION=0.1.0 -DSRC=<Jarvis folder> -DOUT=<setup.exe> -DICON=<icon.ico> -DICON_FILE=<jarvis-<hash>.ico> -DWEBVIEW2=<bootstrapper>
|
|
; -DUNINSTALL_LIST=<the Delete/RMDir lines of the installed files> installer.nsi
|
|
; Program Files, one administrator prompt; the data folder is chosen by the app's first-run wizard
|
|
; and never touched here. /S installs silently (the app's updates: /S /RUN starts the app afterwards).
|
|
|
|
Unicode true
|
|
SetCompressor /SOLID lzma
|
|
!include "MUI2.nsh"
|
|
!include "x64.nsh"
|
|
!include "LogicLib.nsh"
|
|
!include "FileFunc.nsh"
|
|
|
|
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\JarvisBot"
|
|
!ifndef WEBVIEW2_KEY ; a test build points it elsewhere to act as a PC without the runtime
|
|
!define WEBVIEW2_KEY "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
|
|
!endif
|
|
|
|
Name "Jarvis"
|
|
OutFile "${OUT}"
|
|
InstallDir "$PROGRAMFILES64\Jarvis"
|
|
RequestExecutionLevel admin
|
|
BrandingText "Jarvis ${VERSION}"
|
|
VIProductVersion "${VERSION}.0"
|
|
VIAddVersionKey /LANG=0 "ProductName" "Jarvis"
|
|
VIAddVersionKey /LANG=0 "FileVersion" "${VERSION}"
|
|
VIAddVersionKey /LANG=0 "FileDescription" "Jarvis 설치"
|
|
VIAddVersionKey /LANG=0 "LegalCopyright" "MIT"
|
|
|
|
!define MUI_ICON "${ICON}"
|
|
!define MUI_UNICON "${ICON}"
|
|
!define MUI_ABORTWARNING
|
|
!define MUI_FINISHPAGE_RUN
|
|
!define MUI_FINISHPAGE_RUN_TEXT "Jarvis 실행"
|
|
!define MUI_FINISHPAGE_RUN_FUNCTION RunAsUser
|
|
!insertmacro MUI_PAGE_DIRECTORY
|
|
!insertmacro MUI_PAGE_COMPONENTS
|
|
!insertmacro MUI_PAGE_INSTFILES
|
|
!insertmacro MUI_PAGE_FINISH
|
|
!insertmacro MUI_UNPAGE_CONFIRM
|
|
!insertmacro MUI_UNPAGE_INSTFILES
|
|
!insertmacro MUI_LANGUAGE "Korean"
|
|
|
|
; Whether jarvis.exe runs (any user's), from tasklist's answer: OUT = 1 or 0.
|
|
!macro JarvisRuns PREFIX OUT
|
|
nsExec::ExecToStack 'tasklist /FI "IMAGENAME eq jarvis.exe" /NH'
|
|
Pop $0
|
|
Call ${PREFIX}StrHasJarvis
|
|
Pop ${OUT}
|
|
!macroend
|
|
|
|
!macro StrHasJarvisFn PREFIX
|
|
Function ${PREFIX}StrHasJarvis
|
|
Exch $R0
|
|
Push $R1
|
|
Push $R2
|
|
Push $R3
|
|
StrCpy $R1 0
|
|
StrCpy $R2 0
|
|
loop:
|
|
StrCpy $R3 $R0 10 $R1
|
|
StrCmp $R3 "" done
|
|
StrCmp $R3 "jarvis.exe" found
|
|
IntOp $R1 $R1 + 1
|
|
Goto loop
|
|
found:
|
|
StrCpy $R2 1
|
|
done:
|
|
StrCpy $R0 $R2
|
|
Pop $R3
|
|
Pop $R2
|
|
Pop $R1
|
|
Exch $R0
|
|
FunctionEnd
|
|
!macroend
|
|
!insertmacro StrHasJarvisFn ""
|
|
!insertmacro StrHasJarvisFn "un."
|
|
|
|
; Wait until Jarvis has closed: silently up to 60 s (an update closes it itself), else ask.
|
|
!macro WaitClosed PREFIX
|
|
StrCpy $5 0
|
|
${Do}
|
|
!insertmacro JarvisRuns "${PREFIX}" $4
|
|
${If} $4 == 0
|
|
${Break}
|
|
${EndIf}
|
|
${If} ${Silent}
|
|
${If} $5 >= 60
|
|
Abort
|
|
${EndIf}
|
|
Sleep 1000
|
|
IntOp $5 $5 + 1
|
|
${Else}
|
|
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Jarvis가 실행 중입니다. Jarvis 창을 닫은 뒤 다시 시도를 눌러 주세요." IDRETRY +2
|
|
Abort
|
|
${EndIf}
|
|
${Loop}
|
|
!macroend
|
|
|
|
; The driver's result file (why it failed) as text: the app writes it in UTF-8, which FileRead
|
|
; would take for the system's ANSI code page. OUT is empty when there is no file.
|
|
!macro ReadUtf8 FILE OUT
|
|
StrCpy ${OUT} ""
|
|
System::Call 'kernel32::CreateFileW(w "${FILE}", i 0x80000000, i 1, p 0, i 3, i 0, p 0) p .r7'
|
|
${If} $7 P<> -1
|
|
System::Alloc 1024 ; zeroed, and at most 1023 bytes read: always ends with a NUL
|
|
Pop $6
|
|
System::Call 'kernel32::ReadFile(p r7, p r6, i 1023, *i .r5, p 0)'
|
|
System::Call 'kernel32::CloseHandle(p r7)'
|
|
System::Call 'kernel32::MultiByteToWideChar(i 65001, i 0, p r6, i -1, w .s, i ${NSIS_MAX_STRLEN})'
|
|
Pop ${OUT}
|
|
System::Free $6
|
|
${EndIf}
|
|
!macroend
|
|
|
|
; The installer's lock: Jarvis does not start while it is held (app/src/setup_lock.rs); taken
|
|
; before waiting for a running Jarvis, closed once every change is done (before the app is started
|
|
; again). Another installer or uninstaller holding it (or a lock that cannot be made) means this
|
|
; one stops at once: silently with exit code 5.
|
|
!macro TakeLock
|
|
System::Call 'kernel32::CreateMutexW(p 0, i 1, w "Global\JarvisBotSetup") p .r9 ?e'
|
|
Pop $8
|
|
${If} $9 == 0
|
|
${OrIf} $8 == 183 ; ERROR_ALREADY_EXISTS
|
|
${If} $9 != 0
|
|
System::Call 'kernel32::CloseHandle(p r9)'
|
|
${EndIf}
|
|
${IfNot} ${Silent}
|
|
MessageBox MB_ICONSTOP "다른 Jarvis 설치나 제거가 진행 중입니다. 끝난 뒤 다시 실행해 주세요."
|
|
${EndIf}
|
|
SetErrorLevel 5
|
|
Abort
|
|
${EndIf}
|
|
!macroend
|
|
|
|
; Closing the only handle removes the lock (the sections run on another thread than .onInit, so
|
|
; ReleaseMutex would not be allowed there; the handle count is what counts).
|
|
!macro DropLock
|
|
${If} $9 != 0
|
|
System::Call 'kernel32::CloseHandle(p r9)'
|
|
StrCpy $9 0
|
|
${EndIf}
|
|
!macroend
|
|
|
|
Function .onInit
|
|
${IfNot} ${RunningX64}
|
|
MessageBox MB_ICONSTOP "Jarvis는 64비트 Windows 10/11에서만 실행됩니다."
|
|
Abort
|
|
${EndIf}
|
|
SetRegView 64
|
|
; An update goes where Jarvis is installed (the key is in the 64-bit view, which InstallDirRegKey
|
|
; would not read); a folder given with /D wins.
|
|
ReadRegStr $0 HKLM "Software\JarvisBot" "InstallDir"
|
|
${If} $0 != ""
|
|
${AndIf} $INSTDIR == "$PROGRAMFILES64\Jarvis"
|
|
StrCpy $INSTDIR $0
|
|
${EndIf}
|
|
; Shortcuts for every user of the PC, like the Program Files install itself.
|
|
SetShellVarContext all
|
|
!insertmacro TakeLock
|
|
!insertmacro WaitClosed ""
|
|
FunctionEnd
|
|
|
|
Function un.onInit
|
|
SetRegView 64
|
|
SetShellVarContext all
|
|
!insertmacro TakeLock
|
|
!insertmacro WaitClosed "un."
|
|
FunctionEnd
|
|
|
|
; The window needs the WebView2 runtime (Windows 11 has it; an older Windows 10 may not). Checked
|
|
; before any file is copied: without it nothing is installed (and /RUN starts nothing).
|
|
Function WebView2Present
|
|
ReadRegStr $0 HKLM "${WEBVIEW2_KEY}" "pv"
|
|
ReadRegStr $1 HKCU "${WEBVIEW2_KEY}" "pv"
|
|
StrCpy $2 0
|
|
${If} $0 != ""
|
|
${AndIf} $0 != "0.0.0.0"
|
|
StrCpy $2 1
|
|
${EndIf}
|
|
${If} $1 != ""
|
|
${AndIf} $1 != "0.0.0.0"
|
|
StrCpy $2 1
|
|
${EndIf}
|
|
Push $2
|
|
FunctionEnd
|
|
|
|
Function EnsureWebView2
|
|
Call WebView2Present
|
|
Pop $2
|
|
${If} $2 == 1
|
|
Return
|
|
${EndIf}
|
|
SetOutPath "$PLUGINSDIR"
|
|
File "/oname=webview2.exe" "${WEBVIEW2}"
|
|
${Do}
|
|
DetailPrint "WebView2 런타임 설치"
|
|
ExecWait '"$PLUGINSDIR\webview2.exe" /silent /install' $0
|
|
Call WebView2Present
|
|
Pop $2
|
|
${If} $2 == 1
|
|
Return
|
|
${EndIf}
|
|
DetailPrint "WebView2 런타임을 설치하지 못했습니다 (결과 $0)"
|
|
${If} ${Silent}
|
|
SetErrorLevel 3
|
|
Abort "WebView2 런타임을 설치하지 못했습니다."
|
|
${EndIf}
|
|
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Jarvis 창에 필요한 WebView2 런타임을 설치하지 못했습니다. 인터넷 연결을 확인하고 다시 시도해 주세요." IDRETRY +3
|
|
SetErrorLevel 3
|
|
Abort "WebView2 런타임이 없어 설치하지 않았습니다."
|
|
${Loop}
|
|
FunctionEnd
|
|
|
|
; Started from this elevated installer the app would run as administrator; Explorer starts it as
|
|
; the signed-in user.
|
|
Function RunAsUser
|
|
Exec '"$WINDIR\explorer.exe" "$INSTDIR\jarvis.exe"'
|
|
FunctionEnd
|
|
|
|
Section "Jarvis (필수)" SecMain
|
|
SectionIn RO
|
|
; Again right before changing anything: a Jarvis started since the first look closes first.
|
|
!insertmacro WaitClosed ""
|
|
Call EnsureWebView2
|
|
SetOutPath "$INSTDIR"
|
|
File "${SRC}/jarvis.exe"
|
|
File "${SRC}/WebView2Loader.dll"
|
|
; The shortcuts' icon, named by its content: Windows keeps an icon it has shown by the file's path,
|
|
; so a changed icon under the old path would stay the old one on the desktop and in search.
|
|
Delete "$INSTDIR\jarvis-*.ico"
|
|
File "/oname=${ICON_FILE}" "${ICON}"
|
|
File /r "${SRC}/python-src"
|
|
File /r "${SRC}/display-driver"
|
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
|
WriteRegStr HKLM "Software\JarvisBot" "InstallDir" "$INSTDIR"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "Jarvis"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${VERSION}"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "Jarvis"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\jarvis.exe"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "InstallLocation" "$INSTDIR"
|
|
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
|
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
|
|
WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" 1
|
|
WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" 1
|
|
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" ${SIZE_KB}
|
|
SectionEnd
|
|
|
|
Section "시작 메뉴 바로 가기" SecStart
|
|
CreateShortCut "$SMPROGRAMS\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
|
|
SectionEnd
|
|
|
|
Section /o "바탕 화면 바로 가기" SecDesktop
|
|
CreateShortCut "$DESKTOP\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
|
|
SectionEnd
|
|
|
|
; Every shortcut to jarvis.exe on the desktops and in the start menus, their folders included (the
|
|
; person's own too, and the installer's from an earlier version, which an update does not make
|
|
; again) shows this version's icon file; then Explorer redraws its icons. The paths go in through
|
|
; the environment, so no install folder name can break the command. The 64-bit PowerShell
|
|
; (SysNative from this 32-bit installer): a 32-bit one reads a link to Program Files as one to
|
|
; Program Files (x86).
|
|
Section "-Icons"
|
|
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_EXE", t "$INSTDIR\jarvis.exe")'
|
|
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_ICON", t "$INSTDIR\${ICON_FILE},0")'
|
|
nsExec::Exec `"$WINDIR\SysNative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -Command "$$w = New-Object -ComObject WScript.Shell; foreach ($$d in 'Desktop', 'CommonDesktopDirectory', 'Programs', 'CommonPrograms') { Get-ChildItem -LiteralPath ([Environment]::GetFolderPath($$d)) -Filter *.lnk -Recurse:($$d -like '*Programs') -EA 0 | ForEach-Object { $$l = $$w.CreateShortcut($$_.FullName); if ($$l.TargetPath -ieq $$env:JARVIS_EXE) { $$l.IconLocation = $$env:JARVIS_ICON; $$l.Save() } } }"`
|
|
Pop $0
|
|
${If} $0 != 0
|
|
DetailPrint "바로 가기 아이콘을 바꾸지 못했습니다 ($0)"
|
|
${EndIf}
|
|
System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)' ; SHCNE_ASSOCCHANGED
|
|
SectionEnd
|
|
|
|
Section "가상 모니터 드라이버" SecDriver
|
|
; The app's own elevated half (admin.spec.md, "Virtual monitor"); Windows asks once whether to
|
|
; trust the SignPath Foundation. It can also be installed later from the features screen. Not in
|
|
; a silent install (the app's updates): an update never asks Windows' question and never brings
|
|
; back a driver the person removed.
|
|
${If} ${Silent}
|
|
Return
|
|
${EndIf}
|
|
ExecWait '"$INSTDIR\jarvis.exe" --display-driver install --result "$PLUGINSDIR\vdd.txt"' $0
|
|
${If} $0 != 0
|
|
!insertmacro ReadUtf8 "$PLUGINSDIR\vdd.txt" $2
|
|
DetailPrint "가상 모니터 드라이버를 설치하지 못했습니다: $2"
|
|
${IfNot} ${Silent}
|
|
MessageBox MB_ICONEXCLAMATION "가상 모니터 드라이버를 설치하지 못했습니다. 나중에 기능 화면에서 다시 설치할 수 있습니다.$\r$\n$2"
|
|
${EndIf}
|
|
${EndIf}
|
|
SectionEnd
|
|
|
|
; Last: every change is done, so the lock goes before the app starts again (silent updates with
|
|
; /RUN here, the finish page's "Jarvis 실행" after this).
|
|
Section "-Done"
|
|
!insertmacro DropLock
|
|
${GetParameters} $0
|
|
ClearErrors
|
|
${GetOptions} $0 "/RUN" $1
|
|
${IfNot} ${Errors}
|
|
Call RunAsUser
|
|
${EndIf}
|
|
SectionEnd
|
|
|
|
LangString DESC_Main ${LANG_KOREAN} "관리 앱과 음성 워커·두뇌 소스입니다. 모델과 런타임은 첫 실행 때 고른 데이터 폴더에 받습니다."
|
|
LangString DESC_Driver ${LANG_KOREAN} "봇용 크롬창을 실제 모니터에 보이지 않는 가상 모니터에 두어 디스코드 화면 공유에서 고를 수 있게 합니다. Windows가 장치 소프트웨어 설치를 한 번 묻습니다."
|
|
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
|
|
!insertmacro MUI_DESCRIPTION_TEXT ${SecMain} $(DESC_Main)
|
|
!insertmacro MUI_DESCRIPTION_TEXT ${SecDriver} $(DESC_Driver)
|
|
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
|
|
|
Section "Uninstall"
|
|
!insertmacro WaitClosed "un."
|
|
; The virtual monitor's driver goes with the app when this app installed it (code 0). Code 2:
|
|
; nothing of this app's to remove (none, or another program's copy). Anything else: it stays,
|
|
; so the uninstall stops here and keeps the app, which can remove it or try again.
|
|
ExecWait '"$INSTDIR\jarvis.exe" --display-driver uninstall --result "$TEMP\jarvis-vdd-uninstall.txt"' $0
|
|
${If} $0 != 0
|
|
${AndIf} $0 != 2
|
|
!insertmacro ReadUtf8 "$TEMP\jarvis-vdd-uninstall.txt" $2
|
|
Delete "$TEMP\jarvis-vdd-uninstall.txt"
|
|
DetailPrint "가상 모니터 드라이버를 지우지 못했습니다 ($0): $2"
|
|
${IfNot} ${Silent}
|
|
MessageBox MB_ICONSTOP "가상 모니터 드라이버를 지우지 못해 제거를 멈췄습니다. Jarvis의 기능 화면에서 드라이버를 제거한 뒤 다시 시도해 주세요.$\r$\n$2"
|
|
${EndIf}
|
|
SetErrorLevel 4
|
|
Abort "가상 모니터 드라이버를 지우지 못했습니다."
|
|
${EndIf}
|
|
Delete "$TEMP\jarvis-vdd-uninstall.txt"
|
|
; Only the files the installer put there (the list is made from the package at build time): a
|
|
; folder the person chose may hold other things; folders go only when empty.
|
|
Delete "$INSTDIR\jarvis.exe"
|
|
Delete "$INSTDIR\WebView2Loader.dll"
|
|
Delete "$INSTDIR\jarvis-*.ico"
|
|
!include "${UNINSTALL_LIST}"
|
|
Delete "$INSTDIR\uninstall.exe"
|
|
RMDir "$INSTDIR"
|
|
Delete "$SMPROGRAMS\Jarvis.lnk"
|
|
Delete "$DESKTOP\Jarvis.lnk"
|
|
DeleteRegKey HKLM "${UNINST_KEY}"
|
|
DeleteRegKey HKLM "Software\JarvisBot"
|
|
DetailPrint "데이터 폴더(모델, 대화 기록, 설정)는 지우지 않았습니다."
|
|
!insertmacro DropLock
|
|
SectionEnd
|