2017-09-26 27 views
1

内のすべてのアプリケーションフォルダとそこにファイルをインストールするには、これは私がInno Setupの内のユーザーのMATLABフォルダにファイルをインストールしたいFind the path of an application, and copy a file to that directory in Inno Setup検索Inno Setupの

に似質問です。しかし、MATLABのバージョンによっては、ディレクトリが変更される可能性があります。また、インストールされているバージョンの数によっては、複数の宛先が存在する可能性があります。 Windowsのコマンドラインで

、そうのようなMATLABの実行ファイルのパスを取得することが可能である:どの出力

C:\Program Files (x86)\MATLAB\R2015b\bin\matlab.exe 
C:\Program Files\MATLAB\R2017a\bin\matlab.exe 

二つの経路を示し、「どこ」の出力は以下となります

where matlab 

2つのバージョンのMATLABがインストールされているためです。次のフォルダにファイルをコピーしたいと考えています:

C:\Program Files (x86)\MATLAB\R2015b\bin 
C:\Program Files\MATLAB\R2017a\bin 

どうすればこのことができますか?

答えて

1

Innoセットアップでは、対象となるフォルダのランダムな番号にファイルをインストールすることはできません。あなたはパスカルスクリプトですべてをコーディングする必要が

[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;