在卸载模式下使用嵌套到宏中的 StrLoc
Use of StrLoc nested into a macro in uninstall mode
我不是 NSIS 的专家用户...在编译脚本时收到以下错误:
!insertmacro: FUNCTION_STRING_StrLoc_Call
Call must be used with function names starting with "un." in the uninstall section.
卸载时调用以下函数:
Function un.Uninstall
; some code
${un.GetMsOfficeVersion} $R0
; some code
FunctionEnd
反过来,下面的和平代码也被调用:
!macro GetMsOfficeVersion
; some code
StrCpy $R0 0
loop:
ClearErrors
EnumRegValue $R1 HKCU "Microsoft\Office.0\Common\Licensing\LastKnownC2RProductReleaseId" $R0
IfErrors done
IntOp $R0 $R0 + 1
ReadRegStr $R2 HKCU "Microsoft\Office.0\Common\Licensing\LastKnownC2RProductReleaseId" $R1
${StrLoc} $R1 "$R2" "365" ">"
StrCmp $R1 "" +3 0 ;+3 if substring is not found
StrCpy $R1 "16.0"
Goto found
${StrLoc} $R1 "$R2" "2019" ">"
StrCmp $R1 "" loop 0 ;loop if substring is not found
StrCpy $R1 "16.0"
Goto found
done:
; other code
!macroend
!macro _GetMsOfficeVersion Result
${CallArtificialFunction} GetMsOfficeVersion
Pop "${Result}"
!macroend
; Insert function as an installer and uninstaller function.
!define GetMsOfficeVersion "!insertmacro _GetMsOfficeVersion"
!define un.GetMsOfficeVersion "!insertmacro _GetMsOfficeVersion"
我知道问题是因为调用了 ${StrLoc}
函数。安装模式和卸载模式应该是不同的,相应的是${StrLoc}
和${un.StrLoc}
,但是我不知道如何使用这个代码结构
任何帮助将不胜感激...提前致谢
您可以检查 __UNINSTALL__
定义来判断您是否在卸载程序代码中:
!include StrFunc.nsh
${StrLoc}
${UnStrLoc}
!macro testmacro
!ifdef __UNINSTALL__
!define /ReDef MyUn "un"
!else
!define /ReDef MyUn ""
!endif
StrCpy $R2 "3654321"
${${MyUn}StrLoc} $R1 "$R2" "365" ">"
DetailPrint $R1
!macroend
Section
!insertmacro testmacro
Goto +2
WriteUninstaller $Temp\Un.exe
SectionEnd
Section Uninstall
!insertmacro testmacro
SectionEnd
这不太理想,我将看看能否在下一个版本中让 StrFunc 使用 CallArtificialFunction。
我不是 NSIS 的专家用户...在编译脚本时收到以下错误:
!insertmacro: FUNCTION_STRING_StrLoc_Call
Call must be used with function names starting with "un." in the uninstall section.
卸载时调用以下函数:
Function un.Uninstall
; some code
${un.GetMsOfficeVersion} $R0
; some code
FunctionEnd
反过来,下面的和平代码也被调用:
!macro GetMsOfficeVersion
; some code
StrCpy $R0 0
loop:
ClearErrors
EnumRegValue $R1 HKCU "Microsoft\Office.0\Common\Licensing\LastKnownC2RProductReleaseId" $R0
IfErrors done
IntOp $R0 $R0 + 1
ReadRegStr $R2 HKCU "Microsoft\Office.0\Common\Licensing\LastKnownC2RProductReleaseId" $R1
${StrLoc} $R1 "$R2" "365" ">"
StrCmp $R1 "" +3 0 ;+3 if substring is not found
StrCpy $R1 "16.0"
Goto found
${StrLoc} $R1 "$R2" "2019" ">"
StrCmp $R1 "" loop 0 ;loop if substring is not found
StrCpy $R1 "16.0"
Goto found
done:
; other code
!macroend
!macro _GetMsOfficeVersion Result
${CallArtificialFunction} GetMsOfficeVersion
Pop "${Result}"
!macroend
; Insert function as an installer and uninstaller function.
!define GetMsOfficeVersion "!insertmacro _GetMsOfficeVersion"
!define un.GetMsOfficeVersion "!insertmacro _GetMsOfficeVersion"
我知道问题是因为调用了 ${StrLoc}
函数。安装模式和卸载模式应该是不同的,相应的是${StrLoc}
和${un.StrLoc}
,但是我不知道如何使用这个代码结构
任何帮助将不胜感激...提前致谢
您可以检查 __UNINSTALL__
定义来判断您是否在卸载程序代码中:
!include StrFunc.nsh
${StrLoc}
${UnStrLoc}
!macro testmacro
!ifdef __UNINSTALL__
!define /ReDef MyUn "un"
!else
!define /ReDef MyUn ""
!endif
StrCpy $R2 "3654321"
${${MyUn}StrLoc} $R1 "$R2" "365" ">"
DetailPrint $R1
!macroend
Section
!insertmacro testmacro
Goto +2
WriteUninstaller $Temp\Un.exe
SectionEnd
Section Uninstall
!insertmacro testmacro
SectionEnd
这不太理想,我将看看能否在下一个版本中让 StrFunc 使用 CallArtificialFunction。