如何只允许安装到特定文件夹? [英] How to allow installation only to a specific folder?
问题描述
我只想将安装内容安装到一个特定目录,因此我希望禁用目录选择页面上的Next
按钮,除非用户选择要安装的正确文件夹.
I would like to install my setup content only to one specific directory, so I want to have the Next
button on directory selection page disabled, unless the user chooses the right folder to install to.
如何在目录选择页面上禁用Next
按钮并在用户选择特定目录后立即启用它?
How can I disable the Next
button on directory selection page and enable it right after user chooses a specific directory ?
推荐答案
下面的示例演示如何在到达SelectDir
页面时禁用Next
按钮,并仅在您输入(或从浏览器中选择)时启用它目录对话框)C:\MySecretDir
文件夹(MySecretDir
常量).比较是不区分大小写的,因为用户可以输入他(或她)想要的任何内容.
The following sample shows how to disable the Next
button when you reach the SelectDir
page and enable it only when you enter (or choose from the browse directory dialog) the C:\MySecretDir
folder (the MySecretDir
constant). The comparing is case insensitive since user can enter whatever he (or she) wants.
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
const
MySecretDir = 'C:\MySecretDir';
procedure OnDirEditChange(Sender: TObject);
begin
WizardForm.NextButton.Enabled := CompareText(WizardDirValue, MySecretDir) = 0;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectDir then
OnDirEditChange(nil);
end;
procedure InitializeWizard;
begin
WizardForm.DirEdit.OnChange := @OnDirEditChange;
end;
或者如果仅当所选目录中有特定文件MyUniqueFile.exe
时才想启用Next
按钮,请以这种方式修改OnDirEditChange
事件处理程序中的代码:
Or if you want to enable the Next
button only if there's a specific file MyUniqueFile.exe
in the chosen directory, modify the code in OnDirEditChange
event handler this way:
procedure OnDirEditChange(Sender: TObject);
begin
WizardForm.NextButton.Enabled := FileExists(AddBackslash(WizardDirValue) +
'MyUniqueFile.exe');
end;
这篇关于如何只允许安装到特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!