所以我想知道是否可以允许用户仅输入 ASCII 作为安装路径? (警告他并再次输入路径)(问题是我们安装的应用程序是旧的,无法使用西里尔路径,因此我们需要在安装阶段限制用户)
最佳答案
限制 Basic Latin
的应用程序目录的用户输入字符集你可以使用下面的代码。该代码仅检查所选目录名称的任何字符是否不超过 Basic Latin
字符集范围。如果发生这种情况,则会显示一条错误消息,并且用户被迫留在目录选择页面上。剩余的文件夹名称验证(基于文件系统命名约定)保留在 Inno Setup 内部,因为它已经是:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
function IsCharValid(Value: Char): Boolean;
begin
Result := Ord(Value) <= $007F;
end;
function IsDirNameValid(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to Length(Value) do
if not IsCharValid(Value[I]) then
Exit;
Result := True;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if (CurPageID = wpSelectDir) and
not IsDirNameValid(WizardForm.DirEdit.Text) then
begin
Result := False;
MsgBox('There is an invalid char in the selected directory name. ' +
'Directory path may contain only chars that are valid for the ' +
'file system naming conventions and only in the range of the ' +
'Basic Latin character set.', mbError, MB_OK);
end;
end;
关于ascii - 是否可以在 InnoSetup 中过滤/要求安装路径为 ASCII?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21623515/