[英]when installing the software, if the specific condition is false How to roll back the software installation process using NSIS?
My requirement is when installing the software using NSIS installer, it should call the function and check if the UPS is connected to the computer or not. 我的要求是使用NSIS安装程序安装软件时,应调用该函数并检查UPS是否已连接到计算机。
If the UPS is connect it would complete the installation process. 如果UPS已连接,它将完成安装过程。
If the UPS battery is not connected it would show a message box asking "Please connect the UPS and try again with "Cancel" and "Retry" buttons". 如果未连接UPS电池,则会显示一个消息框,询问“请连接UPS,然后使用“取消”和“重试”按钮重试”。 If "cancel" is clicked, it would Roll back the installation process.
如果单击“取消”,它将回滚安装过程。
I am able to get if the UPS is connected or not using the below line of code: 我可以使用以下代码行获取是否已连接UPS:
System::Call "$INSTDIR\drvutil.dll::IsUPSPresent() i.r0 ?e"
Then I am using the "If" condition and checking if the UPS is connected or not 然后,我使用“如果”条件并检查UPS是否已连接
${If} $0 = 0
If the condition is false, I need to show the Messagebox like "Please connect the UPS and try again with "Cancel" and "Retry" buttons". 如果条件为假,则需要显示消息框,例如“请连接UPS,然后使用“取消”和“重试”按钮重试”。 If I click on "Cancle", It should Roll back the installation process.
如果我单击“ Cancle”,它将回滚安装过程。 And If i connect the UPS (or the condition is True) then installation should complete.
并且,如果我连接UPS(或条件为True),则安装应完成。
Please help me how to implement this logic. 请帮助我如何实现此逻辑。
Below is my code snippet: 以下是我的代码段:
; The stuff to install
Section "UPSTest (required)"
SectionIn RO
DetailPrint "Testing UPS"
SetOutPath $INSTDIR
; Give the dll path
File E:\TestNullSoft\ValidateUPS.exe
File E:\TestNullSoft\drvutil.dll
File E:\TestNullSoft\UpsControl.dll
File E:\TestNullSoft\UpsDevice.dll
File E:\TestNullSoft\pdcdll.dll
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")' ; Tell Windows we trust all .DLLs in this directory
System::Call "$INSTDIR\drvutil.dll::IsUPSPresent() i.r0 ?e"
Pop $1
MessageBox MB_OK "Return value = $0, lasterr = $1"
; In the below line If the return value is 0("false"), That means UPS is not connected to the computer
${If} $0 = 0
; Here I need to show the Messagebox like "Please connect the UPS and try again with "Cancel" and "Retry" buttons"
; If I click on "Cancle", It should Roll back the installation process.
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_UPSTest "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "DisplayName" "NSIS UPSTest"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\UPSTest" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Please provide your inputs on this. 请提供您对此的意见。
Instead of trying to roll back a partial install you can just put the .DLL in a temporary directory and do the check there just before you start installing files: 无需尝试回退部分安装,您只需将.DLL放在一个临时目录中,然后在开始安装文件之前在其中进行检查:
!include LogicLib.nsh
Section
InitPluginsDir
SetOutPath $PluginsDir
File "something\mydll.dll"
SetOutPath $Temp ; Don't hold the lock on $PluginsDir
System::Call 'KERNEL32::AddDllDirectory(w "$PluginsDir")'
retry:
System::Call '$PluginsDir\mydll.dll::IsUPSPresentDummyFunction(i 0 r0)i.r0?e' ; Fake a return FALSE system call for this example
Pop $1 ; LastError
${If} $0 = 0
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Blah blah UPS blah blah error $1" IDRETRY retry
Abort "UPS required!" ; You can replace this with Quit if you want
${EndIf}
SetOutPath $InstDir
WriteUninstaller "$InstDir\uninstall.exe"
File "something\myapp.exe"
...
SectionEnd
$PluginsDir is deleted automatically when the installer exits. 安装程序退出时,$ PluginsDir将被自动删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.