diff --git a/windows/scripts/build.nsi b/windows/scripts/build.nsi new file mode 100644 index 0000000000000000000000000000000000000000..9aca140f7eb07e84bf4471d9962400e2e64477ea --- /dev/null +++ b/windows/scripts/build.nsi @@ -0,0 +1,173 @@ +; *************************************************************** +; * Authors: +; * Konstantin Papizh <papizh.konstantin@demlabs.net> +; * DeM Labs Inc. https://demlabs.net +; * Cellframe Project https://gitlab.demlabs.net/cellframe +; * Copyright (c) 2020 +; * All rights reserved. +; *************************************************************** + +!define MULTIUSER_EXECUTIONLEVEL Admin +;!include "MultiUser.nsh" +!include "MUI2.nsh" +!include "x64.nsh" +!include "Nsis.defines.nsh" +!include "modifyConfig.nsh" + +!define MUI_ICON "icon_win32.ico" +!define MUI_UNICON "icon_win32.ico" + +!define NODE_NAME "cellframe-node" +!define EXE_NAME "${APP_NAME}.exe" +!define PUBLISHER "Cellframe Network" + +!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" + +!define MUI_COMPONENTSPAGE_TEXT_TOP "" + +Unicode true +Name "${APP_NAME} ${APP_VER}" +OutFile "${APP_NAME} ${APP_VER}.exe" +BrandingText "${APP_NAME} by ${PUBLISHER}" + +!define MUI_FINISHPAGE_NOAUTOCLOSE + +Var CommonDocuments +Var ConfigPath + +VIProductVersion "${APP_VERSION}" +VIAddVersionKey "ProductName" "${APP_NAME}" +VIAddVersionKey "CompanyName" "${PUBLISHER}" +VIAddVersionKey "LegalCopyright" "${PUBLISHER} Š 2021" +VIAddVersionKey "FileDescription" "Cellframe Dashboard Application" +VIAddVersionKey "FileVersion" "${APP_VER}" + +Function .onInit + ${If} ${RunningX64} + ${EnableX64FSRedirection} + SetRegView 64 + ${else} + MessageBox MB_OK "${APP_NAME} supports x64 architectures only" + Abort + ${EndIf} + ReadRegStr $CommonDocuments HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common Documents" + StrCpy $ConfigPath "$CommonDocuments\${NODE_NAME}" +FunctionEnd + +Function UninstPrev + ReadRegStr $R0 HKLM "${UNINSTALL_PATH}" "UninstallString" + ${If} $R0 == "" + Goto Fin + ${EndIf} + DetailPrint "Uninstall older version" + ExecWait '"$R0" /S' + Fin: +FunctionEnd +!insertmacro MUI_PAGE_WELCOME +!insertmacro MUI_PAGE_DIRECTORY +!insertmacro MUI_PAGE_INSTFILES +!insertmacro MUI_PAGE_FINISH + +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES + +!insertmacro MUI_LANGUAGE "English" +!insertmacro MUI_LANGUAGE "Russian" + +!macro varPaths + IfFileExists "$ConfigPath\var\log" yesLog 0 + CreateDirectory "$ConfigPath\var\log" +yesLog: + IfFileExists "$ConfigPath\var\lib\global_db" yesDb 0 + CreateDirectory "$ConfigPath\var\lib\global_db" +yesDb: + IfFileExists "$ConfigPath\var\lib\wallet" yesWallet 0 + CreateDirectory "$ConfigPath\var\lib\wallet" +yesWallet: + IfFileExists "$ConfigPath\var\lib\ca" yesCa 0 + CreateDirectory "$ConfigPath\var\lib\ca" +yesCa: + IfFileExists "$ConfigPath\log" yesDashLog 0 + CreateDirectory "$CommonDocuments\CellframeDashboard\log" +yesDashLog: + IfFileExists "$ConfigPath\data" yesDashData 0 + CreateDirectory "$CommonDocuments\CellframeDashboard\data" +yesDashData: +!macroend + +!insertmacro AdvReplace + +!macro killAll + nsExec::ExecToLog /OEM 'taskkill /f /im ${EXE_NAME}' + nsExec::ExecToLog /OEM 'taskkill /f /im ${APP_NAME}Service.exe' + nsExec::ExecToLog /OEM 'taskkill /f /im ${NODE_NAME}.exe' + nsExec::ExecToLog /OEM 'schtasks /Delete /TN "${APP_NAME}Service" /F' + nsExec::ExecToLog /OEM 'schtasks /Delete /TN "${NODE_NAME}" /F' +!macroend + +InstallDir "$PROGRAMFILES64\${APP_NAME}" + +Section -UninstallPrevious + Call UninstPrev +SectionEnd + +Section "${APP_NAME}" CORE + SectionIn RO + SetOutPath "$INSTDIR" +!insertmacro killAll + File "${APP_NAME}.exe" + File "${APP_NAME}Service.exe" + File "${NODE_NAME}.exe" + File "${NODE_NAME}-cli.exe" + File "${NODE_NAME}-tool.exe" +!insertmacro varPaths + SetOutPath "$ConfigPath" + File /r "dist\" + Rename "$ConfigPath\etc\${NODE_NAME}.cfg.tpl" "$ConfigPath\etc\${NODE_NAME}.cfg" + Var /GLOBAL net1 + StrCpy $net1 "private" + Rename "$ConfigPath\etc\network\$net1.cfg.tpl" "$ConfigPath\etc\network\$net1.cfg" +!insertmacro modifyConfigFiles + WriteRegStr HKLM "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME} ${APP_VER}" + WriteRegStr HKLM "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\Uninstall.exe" + WriteRegStr HKLM "${UNINSTALL_PATH}" "DisplayVersion" "${APP_VERSION}" + WriteRegStr HKLM "${UNINSTALL_PATH}" "Publisher" "${PUBLISHER}" + WriteRegStr HKLM "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${EXE_NAME}" + + WriteRegStr HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\${NODE_NAME}.exe" "RUNASADMIN" + WriteRegStr HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\${APP_NAME}Service.exe" "RUNASADMIN" + WriteUninstaller "$INSTDIR\Uninstall.exe" + CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${EXE_NAME}" + ${DisableX64FSRedirection} + nsExec::ExecToLog /OEM 'schtasks /Create /F /RL highest /SC onlogon /TR "$INSTDIR\${NODE_NAME}.exe" /TN "${NODE_NAME}"' + nsExec::ExecToLog /OEM 'schtasks /Create /F /RL highest /SC onlogon /TR "$INSTDIR\${APP_NAME}Service.exe" /TN "${APP_NAME}Service"' + ;CreateShortCut "$DESKTOP\${APP_NAME}Service.lnk" "$INSTDIR\${APP_NAME}Service.exe" +SectionEnd + +Section -startNode + nsExec::ExecToLog /OEM 'dism /online /enable-feature /featurename:MSMQ-Container /featurename:MSMQ-Server /featurename:MSMQ-Multicast' + ${EnableX64FSRedirection} + Exec '"$INSTDIR\${NODE_NAME}.exe"' + Exec '"$INSTDIR\${APP_NAME}Service.exe"' +SectionEnd + +Section "Uninstall" + SetRegView 64 + !insertmacro killAll + Delete "$INSTDIR\${APP_NAME}.exe" + Delete "$INSTDIR\${APP_NAME}Service.exe" + Delete "$INSTDIR\${NODE_NAME}.exe" + Delete "$INSTDIR\${NODE_NAME}-tool.exe" + Delete "$INSTDIR\${NODE_NAME}-cli.exe" + ${DisableX64FSRedirection} + nsExec::ExecToLog /OEM 'schtasks /Delete /TN "${APP_NAME}Service" /F' + nsExec::ExecToLog /OEM 'schtasks /Delete /TN "${NODE_NAME}" /F' + ${EnableX64FSRedirection} + DeleteRegKey HKLM "${UNINSTALL_PATH}" + DeleteRegKey HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\$INSTDIR\${NODE_NAME}.exe" + DeleteRegKey HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\$INSTDIR\${APP_NAME}Service.exe" + Delete "$INSTDIR\Uninstall.exe" + Delete "$DESKTOP\${APP_NAME}.lnk" + ;Delete "$DESKTOP\${APP_NAME}Service.lnk" + RMDir "$INSTDIR" +SectionEnd \ No newline at end of file diff --git a/windows/scripts/modifyConfig.nsh b/windows/scripts/modifyConfig.nsh new file mode 100644 index 0000000000000000000000000000000000000000..c9305b3a32d74293633471cd3a40444f83fbf862 --- /dev/null +++ b/windows/scripts/modifyConfig.nsh @@ -0,0 +1,136 @@ +!macro AdvReplace +Function AdvReplaceInFile + Exch $0 + Exch + Exch $1 + Exch + Exch 2 + Exch $2 + Exch 2 + Exch 3 + Exch $3 + Exch 3 + Exch 4 + Exch $4 + Exch 4 + Push $5 + Push $6 + Push $7 + Push $8 + Push $9 + Push $R0 + Push $R1 + Push $R2 + Push $R3 + Push $R4 + Push $R5 + Push $R6 + + GetFullPathName $R1 $0\.. + + GetTempFileName $R6 $R1 + FileOpen $R1 $0 r + FileOpen $R0 $R6 w + StrLen $R3 $4 + StrCpy $R4 -1 + StrCpy $R5 -1 +loop_read: + ClearErrors + FileRead $R1 $R2 + IfErrors exit + StrCpy $5 0 + StrCpy $7 $R2 +loop_filter: + IntOp $5 $5 - 1 + StrCpy $6 $7 $R3 $5 + StrCmp $6 "" file_write2 + StrCmp $6 $4 0 loop_filter + StrCpy $8 $7 $5 + IntOp $6 $5 + $R3 + StrCpy $9 $7 "" $6 + StrLen $6 $7 + StrCpy $7 $8$3$9 + StrCmp -$6 $5 0 loop_filter + IntOp $R4 $R4 + 1 + StrCmp $2 all file_write1 + StrCmp $R4 $2 0 file_write2 + IntOp $R4 $R4 - 1 + IntOp $R5 $R5 + 1 + StrCmp $1 all file_write1 + StrCmp $R5 $1 0 file_write1 + IntOp $R5 $R5 - 1 + Goto file_write2 +file_write1: + FileWrite $R0 $7 + Goto loop_read +file_write2: + FileWrite $R0 $7 + Goto loop_read +exit: + FileClose $R0 + FileClose $R1 + SetDetailsPrint none + Delete $0 + Rename $R6 $0 + Delete $R6 + SetDetailsPrint both + + Pop $R6 + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Pop $R1 + Pop $R0 + Pop $9 + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + + +!macroend + + + +!macro modifyConfigEntry Parameter Value Filename + push `${Parameter}` + push `${Value}` + push all + push all + push `${Filename}` + Call AdvReplaceInFile +!macroend + +!macro modifyConfigFiles + +!insertmacro modifyConfigEntry "{DEBUG_MODE}" "false" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{DEBUG_STREAM_HEADERS}" "false" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{AUTO_ONLINE}" "false" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{SERVER_ENABLED}" "true" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{SERVER_ADDR}" "0.0.0.0" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{SERVER_PORT}" "8079" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{NODE_TYPE}" "master" "$ConfigPath\etc\network\private.cfg" +!insertmacro modifyConfigEntry "{NODE_TYPE}" "master" "$ConfigPath\etc\network\core-t.cfg.tpl" + +!insertmacro modifyConfigEntry "listen_unix_socket_path" "#listen_unix_socket_path" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "#listen_port_tcp=12345" "listen_port_tcp=12345" "$ConfigPath\etc\${NODE_NAME}.cfg" + +!insertmacro modifyConfigEntry "{PREFIX}" "$ConfigPath" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "{PREFIX}" "$ConfigPath" "$ConfigPath\etc\network\core-t\chain-0.cfg" +!insertmacro modifyConfigEntry "{PREFIX}" "$ConfigPath" "$ConfigPath\etc\network\core-t\chain-plasma.cfg" +!insertmacro modifyConfigEntry "/opt/cellframe-node" "$ConfigPath" "$ConfigPath\etc\network\core-t\chain-0.cfg" +!insertmacro modifyConfigEntry "/opt/cellframe-node" "$ConfigPath" "$ConfigPath\etc\network\core-t\chain-plasma.cfg" + +!insertmacro modifyConfigEntry "/" "\" "$ConfigPath\etc\${NODE_NAME}.cfg" +!insertmacro modifyConfigEntry "/" "\" "$ConfigPath\etc\network\core-t\chain-0.cfg" +!insertmacro modifyConfigEntry "/" "\" "$ConfigPath\etc\network\core-t\chain-plasma.cfg" + +!macroend +