0

I created a ISS file for Inno Setup to install a software and I have a YAML configuration file where I need to change a value in it during the installation.

I am new of Inno Setup and I don't have experience in Pascal, so I looked around and found how to open and change a text file or a JSON but not YAML, I don't know if it's the same.

My ISS file is:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "MyApp"
#define MyAppVersion "1.0"
#define MyAppPublisher "Myself"
#define MyAppExeName "MyApp.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5FA0A2CF-7FD4-4464-AF88-4B73D0857D03}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName=C:\ProgramData\MyApp\{#MyAppName}
DisableDirPage=no
DefaultGroupName=MyApp
;DisableProgramGroupPage=yes
OutputDir=D:\MyApp
OutputBaseFilename=MyApp
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\MyApp\MyApp.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\MyApp\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Code]
procedure Update;
var
C: AnsiString;
CU: String;
begin
  LoadStringFromFile(ExpandConstant('conf.yml'), C);
  CU := C;
  StringChangeEx(CU, 'logoImage:', '{app}\ImageLogos.svg', True);
  C := CU;
  SaveStringToFile(ExpandConstant('conf.yml'), C, False);          
end;

function InitializeSetup: Boolean;
begin
  Update;
  result := True;
end;

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}""

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent"

A subset of my configuration file (conf.yml) is like this:

graphs:

    Temperature:
        plots:
            Temperature pcolor:
              cmap: nipy_spectral
              type: contourf
              var: thetao
              min: 10.0
              max: 35.0
              units: Celsius

    Salinity:
        plots:
            Salinity pcolor:
              type: contourf
              var: so
              min: 25.0
              max: 50.0
              units: Practical Salinity Unit

logoImage: 'D:\MyApp\ImageLogos.svg'
appTitle: 'MyApp'

What I want is to change the path of logoImage with the path of the installed app.

If I use my script, I can compile and install my software but it doesn't change the configuration file.

All the examples I found are with JSON and they use third-party libraries.

Do you have any suggestions?

Anthon
  • 69,918
  • 32
  • 186
  • 246
cicciodevoto
  • 305
  • 4
  • 19

1 Answers1

1

YAML (1.2) is a superset of JSON, but not the other way around.

So you would have to ship a YAML parser along with your installer (as third party library) and AFAIK (http://yaml.org/) there isn't one for InnoSetup nor for Pascal.

You might be able to run a program from your installer using the language that is finally going to read the YAML file, assuming there is such a program and that it has a proper parser.

What definately will work is that you read, update and write the file yourself. A string replacement usually works for such cases. That is not generally the best way to update YAML, but if you ship the file in the first place, you know exactly what it looks like and you don't really need a parser. You would need a parser in case the syntax could change for a semantically equivalent YAML, e.g. your block-style transformed to flow-style:

{graphs: {Temperature: {plots: {Temperature pcolor: {cmap: nipy_spectral, type: contourf, var: thetao, min: 10.0, max: 35.0, units: Celsius}}}, 
  Salinity: {plots: {Salinity pcolor: {type: contourf, var: so, min: 25.0, max: 50.0, units: Practical Salinity Unit}}}},
  logoImage: "D:\\MyApp\\ImageLogos.svg", appTitle: MyApp}
Anthon
  • 69,918
  • 32
  • 186
  • 246
  • For a *"string replacement"*, see [Replace placeholder in an installed text file with input entered by user](https://stackoverflow.com/q/45289100/850848). – Martin Prikryl Oct 31 '18 at 08:18