Inno安装选择一个目录来从预定义的集合安装文件 [英] Inno Setup Choose a directory to install files from a pre-defined set
问题描述
在这种情况下,我需要安装一个文件到特定的目录,但在不同的计算机中可能会在不同的文件夹中,所以我需要检查哪个是正确的。
In this situation, I need to install a file to specific directory, but in different computer it might be in different folder so I need to check which on is correct.
例如,我有一个文件,它需要安装在 A
文件夹或 B
文件夹或 C
文件夹,取决于电脑是否有 A
或 B
或<$ ç$ C> C 。所以我需要先检查一下,如果电脑有 B
,然后将文件安装在 B
文件夹等
For example, I have a file and it needs to install in A
folder or B
folder or C
folder, depends on the computer has A
or B
or C
. So I need to check them first, if the computer has B
, then install the file in the B
folder, etc.
我知道我可以使用检查文件的 DestDir
,如果目录不存在,那么它赢得' t安装任何东西,但我需要的是将该文件安装到其他目录。
I know I can use check after file's DestDir
, if the directory doesn't exist then it won't install anything, but what I need is install that file to other directory.
提前感谢。
推荐答案
在 InitializeSetup
事件功能,检查是否存在预定义的目录集,并记住一个目录找。然后使用脚本常数将默认安装路径设置为找到的路径在 DefaultDirName
指令。
In the InitializeSetup
event function, check for existence of your pre-defined set of directories and remember the one you find. Then set the default installation path to the found one using a scripted constant in the DefaultDirName
directive.
您可能还想设置 DisableDirPage = yes
和 UsePreviousAppDir = no
。
You will possible also want to set the DisableDirPage=yes
and the UsePreviousAppDir=no
.
[Setup]
DefaultDirName={code:GetDirName}
DisableDirPage=yes
UsePreviousAppDir=no
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
[Code]
var
DirName: string;
function TryPath(Path: string): Boolean;
begin
Result := DirExists(Path);
if Result then
begin
Log(Format('Path %s exists', [Path]))
DirName := Path;
end
else
begin
Log(Format('Path %s does not', [Path]))
end;
end;
function GetDirName(Param: string): string;
begin
Result := DirName;
end;
function InitializeSetup(): Boolean;
begin
Result :=
TryPath('C:\path1') or
TryPath('C:\path2') or
TryPath('C:\path3');
if Result then
begin
Log(Format('Destination %s selected', [DirName]))
end
else
begin
MsgBox('No destination found, aborting installation', mbError, MB_OK);
end;
end;
而不是使用 DefaultDirName = {code:GetDirName}
,您还可以在 [Files]
DestDir:{code:GetDirName} >部分,如果适用。
Instead of using DefaultDirName={code:GetDirName}
, you can also use DestDir: "{code:GetDirName}"
in the respective entries of the [Files]
section, if appropriate.
这篇关于Inno安装选择一个目录来从预定义的集合安装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!