如何在NSIS脚本中使用nsdialogs删除或修复功能?



我的安装程序在没有nsdialogs的情况下工作正常,如果我添加nsdialogs,它不能正常工作。我无法在正确的位置调用 nsdialog。我需要在哪里调用 nsdialog?

Var hwnd
Var Dialog
Page custom checkinstall 
Page custom nsDialogsPage
.
.
.
Function .onInit
!define MUI_LANGDLL_ALWAYSSHOW
!insertmacro MUI_LANGDLL_DISPLAY
SetShellVarContext all
!insertmacro VerifyUserIsAdmin
FunctionEnd

函数 un.onInit !插入宏MUI_UNGETLANGUAGE SetShellVarContext all

SetRebootFlag true
MessageBox MB_OKCANCEL "Are you sure you want to uninstall 
${APPNAME}?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
FunctionEnd

Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed 
from your computer."
FunctionEnd
Function Repair
Call .onInit
FunctionEnd
Function Remove
ExecWait "$INSTDIRUninstall.exe"
FunctionEnd
Function checkinstall
ReadRegStr $R0 HKLM 
"SoftwareMicrosoftWindowsCurrentVersionUninstall${PRODUCT_NAME}" 
"UninstallString"
IfFileExists $R0 +1 NotInstalled
Call nsDialogsPage
NotInstalled:
FunctionEnd
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateRadioButton} 0 5u 100% 10u "Repair"
Pop $hwnd
${NSD_AddStyle} $hwnd ${WS_GROUP}
${NSD_OnClick} $hwnd Repair
${NSD_CreateRadioButton} 0 25u 100% 56u "Remove"
Pop $hwnd
${NSD_OnClick} $hwnd Remove
nsDialogs::Show
FunctionEnd

我无法正确调用 nsdialog。 检查安装功能根本不起作用。我需要一个正确的解决方案。

您正在将带有引号的卸载命令写入注册表(正确(,但在读取值时没有删除引号,因此文件存在测试总是为假。

您应该从注册表中读取的命令中删除引号:

Function GetAppFromCommand
Exch $1
Push $2
Push $3
StrCpy $3 ""
StrCpy $2 $1 1
StrCmp $2 '"' qloop sloop
sloop:
StrCpy $2 $1 1 $3
IntOp $3 $3 + 1
StrCmp $2 "" +2
StrCmp $2 ' ' 0 sloop
IntOp $3 $3 - 1
Goto done
qloop:
StrCmp $3 "" 0 +2
StrCpy $1 $1 "" 1 ; Remove initial quote
IntOp $3 $3 + 1
StrCpy $2 $1 1 $3
StrCmp $2 "" +2
StrCmp $2 '"' 0 qloop
done:
StrCpy $1 $1 $3
Pop $3
Pop $2
Exch $1
FunctionEnd
!macro GetAppFromCommand cmd outvar
Push `${cmd}`
Call GetAppFromCommand
Pop ${outvar}
!macroend
Function checkinstall
ReadRegStr $R0 HKLM 
"SoftwareMicrosoftWindowsCurrentVersionUninstall${PRODUCT_NAME}" 
"UninstallString"
!insertmacro GetAppFromCommand $R0 $R0
IfFileExists $R0 +1 NotInstalled
Call nsDialogsPage
NotInstalled:
FunctionEnd

最新更新