简体   繁体   English

NSIS - 强制用户选择其他目录

[英]NSIS - force user to select a different directory

So far I've figured out how to detect a previous installation of my software by reading registry keys, and testing for whether the directory exists. 到目前为止,我已经找到了如何通过读取注册表项来检测以前的软件安装,并测试该目录是否存在。 (Both are well documented in the NSIS help file). (两者都在NSIS帮助文件中有详细记录)。 Now I want to force the user to specify a different directory, if the application is previously installed. 现在我想强制用户指定一个不同的目录,如果以前安装了该应用程序。 (Don't want to force uninstall by myself, because previous versions simply remove everything including saved data). (不想自己强制卸载,因为以前的版本只删除包括已保存数据在内的所有内容)。

As far as I can see, there are predefined templates in MUI2.nsh for the license, install folder, progress indicator etc. How do I add a validation at this stage in the installer flow? 据我所知,MUI2.nsh中有预定义的模板,用于许可证,安装文件夹,进度指示器等。如何在安装程序流程的此阶段添加验证?

Update - Tried Paul's solution, but it doesn't work. 更新 - 尝试了保罗的解决方案,但它不起作用。 At the top of the script, I've declared 在脚本的顶部,我已经声明了

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE validateDirectory
!insertmacro MUI_PAGE_DIRECTORY

to refer to this function: 引用此功能:

Function validateDirectory
ReadRegStr $R0 HKLM "SOFTWARE\Aadhaar Enrolment Client" "Installdir"
Pop $R0
StrCmp $R0 $OUTDIR +1 +3
MessageBox MB_ICONSTOP|MB_OK 'The directory $OUTDIR already exists.Please choose a different directory.'
Abort
FunctionEnd

This function displays the message, but doesn't abort. 此功能显示消息,但不会中止。 Moreover, if I click on 'back' in the directory selection page and again click forward, then it simply proceeds with the installation. 此外,如果我在目录选择页面中单击“返回”并再次单击向前,则只需继续安装。

You need to specify a "Leave" function for the directory page like this 您需要像这样为目录页面指定“离开”功能

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveDirectory
!insertmacro MUI_PAGE_DIRECTORY

and this will call the function specified when the Next button is clicked. 这将调用单击“下一步”按钮时指定的函数。

Then create the LeaveDirectory function with the logic required to validate the directory selected and if the directory is determined to be invalid, simply call Abort in the function and the installer won't move on to the next step. 然后使用验证所选目录所需的逻辑创建LeaveDirectory函数,如果确定目录无效,只需在函数中调用Abort,安装程序将不会继续执行下一步。

The documentation is on this page under the "Custom Functions" section but because you have to expand the "Page Custom Functions" heading is not obvious unfortunately. 该文档位于页面的“自定义函数”部分下,但由于您必须展开“页面自定义函数”标题,遗憾的是并不明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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