Inno Setup Compiler: How to modify file content

Ionut Flavius Pogacian

I am trying to read line by line the content of a text file;

I am looking for something, for a specific line.

I need to modify that line;

I need to save, the new content in another file, and then delete the original file and rename the new file with the original file name;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ExecInfo: TShellExecuteInfo;
  ExecInfoBrowser: TShellExecuteInfo;
  textFileFrom, textFileTo : text;
  line: string;
begin
  Result := True;

  if CurPageID = wpFinished then
  begin
    ExecInfo.cbSize := SizeOf(ExecInfo);
    ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
    ExecInfo.Wnd := 0;
    ExecInfo.lpFile := ExpandConstant('{app}') + '\{#Exewampmanager}';
    ExecInfo.nShow := SW_HIDE;
    if ShellExecuteEx(ExecInfo) then
      begin
        if WaitForSingleObject(ExecInfo.hProcess, 5000) = WAIT_TIMEOUT then
          begin
            Assign(textFileFrom,'wampmanager.conf');
            Reset(textFileFrom);
            Assign(textFileto,'wampmanager2.conf');
            Rewrite(textFileTo);
            repeat
              readln(textFileFrom,line);
              writeln(textFileto,line);
            until eof(textFileFrom);
            Close(textFileFrom);
            Close(textFileTo);
               ExecInfoBrowser.cbSize := SizeOf(ExecInfo);
               ExecInfoBrowser.fMask := SEE_MASK_NOCLOSEPROCESS;
               ExecInfoBrowser.Wnd := 0;
               ExecInfoBrowser.lpFile := 'http://localhost/cow';
               ExecInfoBrowser.nShow := SW_HIDE;
               ShellExecuteEx(ExecInfoBrowser);
          end;
      end;
  end;
end;

in the file i need to nodify this line: installDir = "c:/wamp"

because the new installation might not be in the same location

this is the conf file:

[main]
language = english
status = "offline"
wampserverVersion = 2.2
wampserverLastKnown = 2.2
installDir = "c:/wamp"
navigator = "C:\Windows\explorer.exe"
defaultLanguage = english


[php]
phpVersion = "5.4.3"
phpLastKnown = 5.4.3
phpIniDir = .
phpConfFile = php.ini
phpExeDir = .


[phpCli]
phpCliVersion = 5.4.3
phpExeFile = php.exe
phpCliFile = php-win.exe


[apache]
apacheVersion = "2.2.22"
apacheLastKnown = 2.2.22
apacheExeDir = bin
apacheConfDir = conf
apacheExeFile = httpd.exe
apacheConfFile = httpd.conf
apacheServiceInstallParams = -n wampapache -k install
apacheServiceRemoveParams = -n wampapache -k uninstall


[mysql]
mysqlVersion = "5.5.24"
mysqlLastKnown = 5.5.24
mysqlConfDir = .
mysqlConfFile = my.ini
mysqlExeDir = bin
mysqlExeFile = mysqld.exe
mysqlServiceInstallParams = --install-manual wampmysqld
mysqlServiceRemoveParams = --remove wampmysqld


[apps]
phpmyadminVersion = 3.5.1
sqlbuddyVersion = 1.3.3
webgrindVersion = 1.0
TLama

If that config file is in an INI file format, what seems to be, you can either use the [INI] section to modify a single value e.g. this way (note, that you must double double quotes to compile the script and have the value enclosed in double quotes). Of course the values I've showed here you can replace with constants as usually:

[INI]
Filename: "{app}\wampmanager.conf"; Section: "main"; Key: "installDir"; String: """{app}"""

Or you can complicate things a bit by using code from the [Code] section:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
function ChangeInstallDir(const FileName, InstallDir: string): Boolean;
begin
  Result := SetIniString('main', 'installDir', '"' + InstallDir + '"', FileName);
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
    if not ChangeInstallDir(ExpandConstant('{app}\wampmanager.conf'), 
        ExpandConstant('{app}')) then
      MsgBox('Saving to config file failed!', mbError, MB_OK);
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

How to load an RTF file content into Inno Setup TNewMemo?

From Dev

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

From Dev

How to modify file content?

From Dev

Inno setup compiler How to set launching image during app loading

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

How to call the GetNativeSystemInfo at Inno Setup iss file?

From Dev

Inno Setup Compiler: How to use a constant from Setup region within a event method

From Dev

Passing in version number to Inno Setup compiler

From Dev

Best Disk Spanning settings in Inno Setup Compiler

From Dev

Inno Setup : How to change language file depending on code

From Java

How to catch the error message of bat file for deleting files in Inno Setup?

From Dev

How to test using wildcards whether a file exists in Inno Setup

From Dev

How can I reference a custom icon for a file association in Inno Setup?

From Dev

How can I reference a custom icon for a file association in Inno Setup?

From Dev

How to provide an input to a batch file ran using Inno Setup installer?

From Dev

Replace a text in a file with Inno Setup

From Dev

Writing binary file in Inno Setup

From Dev

Writing binary file in Inno Setup

From Dev

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

From Dev

How to override functions in Inno Setup?

From Dev

How to split a string in Inno Setup

From Dev

how to refresh a page in inno setup

From Dev

How to extract a Inno Setup Installer

From Dev

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

From Dev

awk to modify content of file

From Dev

Assembly Modify file content

From Dev

Inno Setup Compiler "Cannot find the path specified" error with long paths

From Dev

Inno Setup Compiler - JavaFX app doesn't write files

Related Related

  1. 1

    How to load an RTF file content into Inno Setup TNewMemo?

  2. 2

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

  3. 3

    How to modify file content?

  4. 4

    Inno setup compiler How to set launching image during app loading

  5. 5

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

  6. 6

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

  7. 7

    How to call the GetNativeSystemInfo at Inno Setup iss file?

  8. 8

    Inno Setup Compiler: How to use a constant from Setup region within a event method

  9. 9

    Passing in version number to Inno Setup compiler

  10. 10

    Best Disk Spanning settings in Inno Setup Compiler

  11. 11

    Inno Setup : How to change language file depending on code

  12. 12

    How to catch the error message of bat file for deleting files in Inno Setup?

  13. 13

    How to test using wildcards whether a file exists in Inno Setup

  14. 14

    How can I reference a custom icon for a file association in Inno Setup?

  15. 15

    How can I reference a custom icon for a file association in Inno Setup?

  16. 16

    How to provide an input to a batch file ran using Inno Setup installer?

  17. 17

    Replace a text in a file with Inno Setup

  18. 18

    Writing binary file in Inno Setup

  19. 19

    Writing binary file in Inno Setup

  20. 20

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

  21. 21

    How to override functions in Inno Setup?

  22. 22

    How to split a string in Inno Setup

  23. 23

    how to refresh a page in inno setup

  24. 24

    How to extract a Inno Setup Installer

  25. 25

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

  26. 26

    awk to modify content of file

  27. 27

    Assembly Modify file content

  28. 28

    Inno Setup Compiler "Cannot find the path specified" error with long paths

  29. 29

    Inno Setup Compiler - JavaFX app doesn't write files

HotTag

Archive