查找所有应用程序文件夹并在Inno Setup中安装文件 [英] Lookup all application folders and install a file there in Inno Setup
问题描述
这与找到应用程序的路径,然后将文件复制到Inno Setup中的目录类似. >
我想在Inno Setup中将文件安装到用户的MATLAB文件夹中.但是根据MATLAB的版本,目录可以更改,根据安装的版本数,可以有多个目标.
在Windows命令行中,可以像这样获取MATLAB可执行文件的路径:
where matlab
将输出
C:\Program Files (x86)\MATLAB\R2015b\bin\matlab.exe
C:\Program Files\MATLAB\R2017a\bin\matlab.exe
由于安装了两个版本的MATLAB,"where"的输出显示两个路径.我想复制以下文件夹中的文件:
C:\Program Files (x86)\MATLAB\R2015b\bin
C:\Program Files\MATLAB\R2017a\bin
这怎么办?
Inno Setup无法自行将文件安装到随机数量的目标文件夹中.
您必须使用Pascal脚本编写所有代码:
[Files]
Source: "MyFile.dat"; Flags: dontcopy
[Code]
procedure ExtractFileToPathsWhereAnotherFileIs(ExtractFile: string; SearchFile: string);
var
P: Integer;
Paths: string;
Path: string;
TempPath: string;
begin
{ Extract the file to temporary location (there's no other way) }
ExtractTemporaryFile(ExtractFile);
TempPath := ExpandConstant('{tmp}\' + ExtractFile);
Paths := GetEnv('PATH');
{ Iterate paths in PATH environment variable... }
while Paths <> '' do
begin
P := Pos(';', Paths);
if P > 0 then
begin
Path := Trim(Copy(Paths, 1, P - 1));
Paths := Trim(Copy(Paths, P + 1, Length(Paths) - P));
end
else
begin
Path := Trim(Paths);
Paths := '';
end;
{ Is it the path we are interested in? }
if FileExists(AddBackslash(Path) + SearchFile) then
begin
Log(Format('Found "%s" in "%s"', [SearchFile, Path]));
{ Install the file there }
if FileCopy(TempPath, AddBackslash(Path) + ExtractFile, False) then
begin
Log(Format('Installed "%s" to "%s"', [ExtractFile, Path]));
end
else
begin
MsgBox(Format('Failed to install "%s" to "%s"', [ExtractFile, Path]),
mbError, MB_OK);
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ExtractFileToPathsWhereAnotherFileIs('MyFile.dat', 'matlab.exe');
end;
end;
This is a similar question to Find the path of an application, and copy a file to that directory in Inno Setup
I'd like to install a file into a user's MATLAB folder in Inno Setup. But depending on the version of MATLAB, the directory can change, and depending on the number of versions installed, there can be multiple destinations.
In the Windows command line, it is possible to get the path of the MATLAB executable like so:
where matlab
Which will output
C:\Program Files (x86)\MATLAB\R2015b\bin\matlab.exe
C:\Program Files\MATLAB\R2017a\bin\matlab.exe
The output of "where" shows two paths, due to the fact that two versions of MATLAB are installed. I'd like to copy a file in the following folders:
C:\Program Files (x86)\MATLAB\R2015b\bin
C:\Program Files\MATLAB\R2017a\bin
How can this be done?
Inno Setup cannot install a file to random number of target folders on its own.
You have to code everything in Pascal Script:
[Files]
Source: "MyFile.dat"; Flags: dontcopy
[Code]
procedure ExtractFileToPathsWhereAnotherFileIs(ExtractFile: string; SearchFile: string);
var
P: Integer;
Paths: string;
Path: string;
TempPath: string;
begin
{ Extract the file to temporary location (there's no other way) }
ExtractTemporaryFile(ExtractFile);
TempPath := ExpandConstant('{tmp}\' + ExtractFile);
Paths := GetEnv('PATH');
{ Iterate paths in PATH environment variable... }
while Paths <> '' do
begin
P := Pos(';', Paths);
if P > 0 then
begin
Path := Trim(Copy(Paths, 1, P - 1));
Paths := Trim(Copy(Paths, P + 1, Length(Paths) - P));
end
else
begin
Path := Trim(Paths);
Paths := '';
end;
{ Is it the path we are interested in? }
if FileExists(AddBackslash(Path) + SearchFile) then
begin
Log(Format('Found "%s" in "%s"', [SearchFile, Path]));
{ Install the file there }
if FileCopy(TempPath, AddBackslash(Path) + ExtractFile, False) then
begin
Log(Format('Installed "%s" to "%s"', [ExtractFile, Path]));
end
else
begin
MsgBox(Format('Failed to install "%s" to "%s"', [ExtractFile, Path]),
mbError, MB_OK);
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
ExtractFileToPathsWhereAnotherFileIs('MyFile.dat', 'matlab.exe');
end;
end;
这篇关于查找所有应用程序文件夹并在Inno Setup中安装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!