简体   繁体   中英

NSIS - Installer: Compare Kit Version with Header file define variable and update if wrong define variable value

I'm new to NSIS installer scripting. I have created a NSIS script to replace our WISE installer script. I want to write a logic to compare Kit version(Folder name say A1.2.3 where A denotes Alhpa kit) with,define APP_Version(on header) file during compile time and if define variable is wrong. I want to update Header file with correct value. Here is the logic I came up with but I don't know how to update the update the header file.

Section

System::Call "kernel32::GetCurrentDirectory(i ${NSIS_MAX_STRLEN}, t .r0)"

${WordFind} "$0" "\" "-1" $R0

!if "$R0" != "${APP_CLASSKIT}${APP_VERSION}"
    MessageBox MB_OK "No Match: $R0"
    !undef verifykit
    !define APP_VERSION "$R0"
    
!else
    MessageBox MB_OK "Match: ${APP_CLASSKIT}${APP_VERSION}"
    !undef verifykit
    !define APP_VERSION "${APP_CLASSKIT}${APP_VERSION}"
!endif

SectionEnd

You can't mix and match run-time and compile-time instructions like that. If you want to detect this on the machine you are compiling on you can only use the instructions starting with ! .

If you just want to detect the problem:

!macro PrepareExample
!system 'mkdir ".\A1.2.3"'
!macroend
!insertmacro PrepareExample ; For Stackoverflow


!define APP_CLASSKIT A 
!define APP_VERSION 1.2.3

!if ! /FileExists ".\${APP_CLASSKIT}${APP_VERSION}\*"
!error "Incorrect kit version, ${APP_CLASSKIT}${APP_VERSION} not found!"
!endif

Section
SetOutPath $InstDir
File /r ".\${APP_CLASSKIT}${APP_VERSION}"
SectionEnd

The compile-time part of the compiler is not really suited to search for folders with a specific pattern. It is much better to invoke a batch/powershell/wsh script and let that create a.nsh file you can include:

!macro PrepareExample
!system 'mkdir ".\A1.2.3"'
!delfile 'findkit.bat'
!appendfile 'findkit.bat' '@echo off$\r$\n'
!appendfile 'findkit.bat' 'echo.TODO: Use FOR or some other batch command to find the correct kit folder.$\r$\n'
!appendfile 'findkit.bat' 'for /D %%A in (??.*) do ($\r$\n'
!appendfile 'findkit.bat' ' echo.This batch file just fakes it$\r$\n'
!appendfile 'findkit.bat' ' echo !define APP_CLASSKIT A >> "%~1"$\r$\n'
!appendfile 'findkit.bat' ' echo !define APP_VERSION 1.2.3 >> "%~1"$\r$\n'
!appendfile 'findkit.bat' ')$\r$\n'
!macroend
!insertmacro PrepareExample ; For Stackoverflow


!tempfile KitNsh
!system '"findkit.bat" "${KitNsh}"'
!include "${KitNsh}"
!delfile "${KitNsh}"
!ifndef APP_CLASSKIT | APP_VERSION
  !error "No kit detected"
!endif
!echo "Using kit ${APP_CLASSKIT}${APP_VERSION}"

Section
...
SectionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM