Inno Setup - How to edit a specific line from a text file during setup?

Dielo

I need to edit a specific line from a text file using Inno Setup. I need my installer to find this line ("appinstalldir" "C:MYXFOLDER\\apps\\common\\App70") and use the directory path from the installer.

This is the code I am trying to use:

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssDone then
  begin
    SaveStringToFile(
      ExpandConstant('{app}\app70.txt'),
      'directory's path' + '\\apps\\common\\App70', True);
  end;
end;

This is my text file:

"App"
{
    "appID"     "70"

    {
        "appinstalldir"     "C:MYXFOLDER\\apps\\common\\App70"
    }
}
TLama

This code can do it. But note, that this code doesn't check, if the value for the tag is enclosed by quote chars, once it finds a tag specified by TagName parameter, it cuts off the rest of the line and appends the value given by TagValue parameter:

function ReplaceValue(const FileName, TagName, TagValue: string): Boolean;
var
  I: Integer;
  Tag: string;
  Line: string;
  TagPos: Integer;
  FileLines: TStringList;
begin
  Result := False;
  FileLines := TStringList.Create;
  try
    Tag := '"' + TagName + '"';
    FileLines.LoadFromFile(FileName);
    for I := 0 to FileLines.Count - 1 do
    begin
      Line := FileLines[I];
      TagPos := Pos(Tag, Line);
      if TagPos > 0 then
      begin
        Result := True;
        Delete(Line, TagPos + Length(Tag), MaxInt);
        Line := Line + ' "' + TagValue + '"';
        FileLines[I] := Line;
        FileLines.SaveToFile(FileName);
        Break;
      end;
    end;
  finally
    FileLines.Free;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  NewPath: string;
begin
  if CurStep = ssDone then
  begin
    NewPath := ExpandConstant('{app}') + '\apps\common\App70';
    StringChangeEx(NewPath, '\', '\\', True);

    if ReplaceValue(ExpandConstant('{app}\app70.txt'), 'appinstalldir', 
      NewPath) 
    then
      MsgBox('Tag value has been replaced!', mbInformation, MB_OK)
    else  
      MsgBox('Tag value has not been replaced!.', mbError, MB_OK);
  end;
end;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inno Setup: Reading a file from installer during uninstallation

From Dev

Replace a text in a file with Inno Setup

From Dev

How to completely disable specific component in Inno Setup from code section?

From Dev

Save entered text to TXT file in Inno Setup

From Dev

Save entered text to TXT file in Inno Setup

From Dev

Multi-line edit in Inno Setup on page created by CreateInputQueryPage

From Dev

Inno Setup unzip file from input user

From Dev

Show text during installation process with inno-setup

From Dev

Inno Setup Compiler: How to edit INI file and replace a value with {app} constant

From Java

Inno Setup: Load file edited during installation for wpInfoAfter

From Dev

Inno Setup Executing a large sql script file during installation

From Dev

Inno setup: how to replace a string in XML file?

From Dev

Inno Setup (How to get dynamically path to file)?

From Dev

Inno Setup Compiler: How to modify file content

From Dev

How to call the GetNativeSystemInfo at Inno Setup iss file?

From Dev

How to read and compare a number from a txt file during setup

From Dev

How to call "npm install" from Inno Setup?

From Dev

Command line parameters missing special characters like ! when ran via batch file from Inno Setup

From Dev

Inno setup compiler How to set launching image during app loading

From Dev

INNO setup writing a multi line text constant to the registry

From Dev

How do you execute command line tools without using batch file in Inno Setup

From Dev

Edit specific record from a line in text file and PHP

From Dev

Getting output from running command line app in Inno Setup

From Dev

Writing binary file in Inno Setup

From Dev

Writing binary file in Inno Setup

From Dev

Inno Setup How to add CRLF/line break in custom message

From Dev

Inno Setup How to add CRLF/line break in custom message

From Dev

Inno setup - how to change version in the setup hover?

From Dev

Inno setup executes [UninstallRun] during installation followup

Related Related

  1. 1

    Inno Setup: Reading a file from installer during uninstallation

  2. 2

    Replace a text in a file with Inno Setup

  3. 3

    How to completely disable specific component in Inno Setup from code section?

  4. 4

    Save entered text to TXT file in Inno Setup

  5. 5

    Save entered text to TXT file in Inno Setup

  6. 6

    Multi-line edit in Inno Setup on page created by CreateInputQueryPage

  7. 7

    Inno Setup unzip file from input user

  8. 8

    Show text during installation process with inno-setup

  9. 9

    Inno Setup Compiler: How to edit INI file and replace a value with {app} constant

  10. 10

    Inno Setup: Load file edited during installation for wpInfoAfter

  11. 11

    Inno Setup Executing a large sql script file during installation

  12. 12

    Inno setup: how to replace a string in XML file?

  13. 13

    Inno Setup (How to get dynamically path to file)?

  14. 14

    Inno Setup Compiler: How to modify file content

  15. 15

    How to call the GetNativeSystemInfo at Inno Setup iss file?

  16. 16

    How to read and compare a number from a txt file during setup

  17. 17

    How to call "npm install" from Inno Setup?

  18. 18

    Command line parameters missing special characters like ! when ran via batch file from Inno Setup

  19. 19

    Inno setup compiler How to set launching image during app loading

  20. 20

    INNO setup writing a multi line text constant to the registry

  21. 21

    How do you execute command line tools without using batch file in Inno Setup

  22. 22

    Edit specific record from a line in text file and PHP

  23. 23

    Getting output from running command line app in Inno Setup

  24. 24

    Writing binary file in Inno Setup

  25. 25

    Writing binary file in Inno Setup

  26. 26

    Inno Setup How to add CRLF/line break in custom message

  27. 27

    Inno Setup How to add CRLF/line break in custom message

  28. 28

    Inno setup - how to change version in the setup hover?

  29. 29

    Inno setup executes [UninstallRun] during installation followup

HotTag

Archive