; CSM Client Installer (NSIS) ; --------------------------- ; Build: makensis /DVERSION=0.2.0 installer\client.nsi ; Silent install: csm-client-0.2.0-setup.exe /S /SERVER=192.168.1.10:9999 !define PRODUCT_NAME "CSM Client" !define PRODUCT_PUBLISHER "CSM" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_SERVICE_NAME "CSMClient" ; Use LZMA compression for smaller installer SetCompressor lzma Name "${PRODUCT_NAME} ${VERSION}" OutFile "release\v${VERSION}\csm-client-${VERSION}-setup.exe" InstallDir "$PROGRAMFILES64\${PRODUCT_NAME}" RequestExecutionLevel admin ; --- Pages --- Page directory Page custom ServerPage ServerPageLeave Page instfiles UninstPage uninstConfirm UninstPage instfiles ; --- Variables --- Var ServerAddress ; --- Custom page for server address input --- Function ServerPage !insertmacro MUI_HEADER_TEXT "Server Configuration" "Enter the CSM server address" nsDialogs::Create 1018 Pop $0 ${NSD_CreateLabel} 0 0 100% 12u "CSM Server Address (host:port):" Pop $0 ${NSD_CreateText} 0 14u 100% 12u "127.0.0.1:9999" Pop $1 nsDialogs::Show FunctionEnd Function ServerPageLeave ${NSD_GetText} $1 $ServerAddress ${If} $ServerAddress == "" MessageBox MB_ICONEXCLAMATION "Please enter a server address" Abort ${EndIf} FunctionEnd ; --- Install Section --- Section "Install" SetOutPath $INSTDIR ; Stop service if running nsExec::ExecToLog 'net stop ${PRODUCT_SERVICE_NAME}' Sleep 2000 ; Copy binary File "release\v${VERSION}\csm-client-${VERSION}.exe" ; Write config file FileOpen $0 "$INSTDIR\client.env" w FileWrite $0 "CSM_SERVER=$ServerAddress$\r$\n" FileClose $0 ; Register as Windows service nsExec::ExecToLog '"$INSTDIR\csm-client-${VERSION}.exe" --install' Sleep 1000 ; Start service nsExec::ExecToLog 'net start ${PRODUCT_SERVICE_NAME}' ; Write uninstaller WriteUninstaller "$INSTDIR\uninstall.exe" ; Registry entries WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${VERSION}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "EstimatedSize" 5120 ; Create Start Menu shortcut CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}" CreateShortcut "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" SectionEnd ; --- Uninstall Section --- Section "Uninstall" ; Stop and remove service nsExec::ExecToLog 'net stop ${PRODUCT_SERVICE_NAME}' Sleep 2000 nsExec::ExecToLog '"$INSTDIR\csm-client-${VERSION}.exe" --uninstall' Sleep 1000 ; Remove files Delete "$INSTDIR\csm-client-*.exe" Delete "$INSTDIR\client.env" Delete "$INSTDIR\csm_client_service.log" Delete "$INSTDIR\uninstall.exe" RMDir "$INSTDIR" ; Remove shortcuts Delete "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" RMDir "$SMPROGRAMS\${PRODUCT_NAME}" ; Remove registry DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}" SectionEnd