1

My update has to figure out if two known files exist in the directory the user has specified. If not I want to let him know, that there are no files at this path. Up to now, this was a CustomMessage in all of my .isl Files. Now I want to show him the complete path he entered with the files.

Up to now the message looks like this:

File1, File2 or both could not be found at the selected location....

What I now want is this:

%1, %2 or both could not be found...

For %1 and %2 I want to pass in the complete specified paths, but I cannot see how to do this. ExpandConstant does not have any arguments, and up to now I've found nothing about how to pass parameters to a custom message.

To clarify things, here's the code:

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
  ServerData : String;
  UseDatabase : String;
  Language : String;
  ResultCode : Integer;
  ExePath : String;
  ConfigFilePath : String;
begin
  Result := True;
  if CurPageID = wpSelectDir then begin
    if DirExists(ExpandConstant('{app}')) then begin
        MsgBox(ExpandConstant('{app}'),mbInformation,MB_OK);    
        UpdatePath := ExpandConstant('{app}');
        ExePath := UpdatePath+'\File1.exe';
        ConfigFilePath := UpdatePath+'\File2.exe.config'; 
        if FileExists(UpdatePath+'\File1.exe') and FileExists(UpdatePath+'\File2.exe.config') then begin
            RegPath := UpdatePath;
            UpdatePath := RegPath + '\Update-' + ExpandConstant('{#MyAppVersion}');
            ConfigPath := RegPath + '\File2.exe.config';
            DBPage.Values[0] := ExtractServerAddr(GetServerData(ConfigPath));
            DBPage.Values[1] := ExtractServerPort(GetServerData(ConfigPath));           
        end else begin
            MsgBox(ExpandConstant('{cm:DirPageFileNotFound,ExePath,ConfigFilePath}'),mbInformation,MB_OK);
            Result := False;
        end;
    end else begin
            MsgBox(ExpandConstant('{cm:DirPageDirectoryNotFound}'),mbInformation,MB_OK);
            Result := False;
    end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
EaranMaleasi
  • 895
  • 1
  • 13
  • 32

2 Answers2

1

In Pascal Script you should use CustomMessage together with FmtMessage:

FmtMessage(CustomMessage('DirPageFileNotFound'), [ExePath, ConfigFilePath])

It's cleaner and less error prone than assembling the {cm:MessageName,Arguments} "constant". Your syntax will for example break, if there's any comma or curly bracket in any of the paths.

The {cm:...} constant is intended for use in non-Code sections, like:

[Run]
Filename: "myapp.exe"; Description: "{cm:RunningApp,myapp.exe}"; 

Similar question: Pass parameters to custom messages defined in .isl files

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

Well, the solution is as easy as it could possibly be:

ToExpand := '{cm:DirPageFileNotFound,' + ExePath +',' + ConfigFilePath + '}'
MsgBox(ExpandConstant(ToExpand),mbInformation,MB_OK);

This two lines did the trick.

PS: I'm thankful for StackOverflow being my rubber duck.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
EaranMaleasi
  • 895
  • 1
  • 13
  • 32