2017-09-26 3 views
1

Ceci est une question similaire à Find the path of an application, and copy a file to that directory in Inno SetupRecherche tous les dossiers d'application Les et installer un fichier il dans Inno Setup

Je voudrais installer un fichier dans le dossier dans Matlab Inno Setup d'un utilisateur. Mais selon la version de MATLAB, le répertoire peut changer, et selon le nombre de versions installées, il peut y avoir plusieurs destinations.

Dans la ligne de commande Windows, il est possible d'obtenir le chemin de l'exécutable Matlab comme ceci:

where matlab 

qui sortira

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

La sortie de « où » montre deux chemins , en raison du fait que deux versions de MATLAB sont installées. Je voudrais copier un fichier dans les dossiers suivants:

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

Comment cela peut-il être fait?

Répondre

1

Inno Setup ne peut pas installer seul un fichier sur un nombre aléatoire de dossiers cibles.

Vous avez coder tout 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;