4

I have a INI file which contains c:/wamp many times.

How can I replace this text with the {app} extended/chosen constant value?

I know now how to replace a single value:

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

I am reading from here

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100
  • You can use `LoadStringFromFile` and then `StringChange` where you will replace `c:/wamp` (any string) with `{app}`. Just keep in mind that if INI is ANSI and you use Unicode IS, then you have to point it in the script. – RobeN Oct 11 '13 at 08:25
  • @RobeN, I strongly suggest to not do this! That file is obviously generated by a certain external installer and by this blind replace you can modify keys that you don't want to change. I urge you to make a list of all those keys. – TLama Oct 11 '13 at 08:27
  • 1
    the file is big, so a list is out of the question; i need a find and replace method – Ionut Flavius Pogacian Oct 11 '13 at 08:30
  • No, you don't need it. You want it. – TLama Oct 11 '13 at 08:31
  • so, how do i replace all the values without that list? – Ionut Flavius Pogacian Oct 11 '13 at 08:32

1 Answers1

8

This is risky solution as TLama says.

You have to call this procedure at some point, e.g. on ssDone or as an AfterInstall

[Code]
procedure Update;
var
A: AnsiString;
U: String;
begin
    LoadStringFromFile(ExpandConstant('{app}\wampmanager.conf'), A);
    U := A;
    StringChange(U, 'c:/wamp', ExpandConstant('{app}'));
    A := U;
    SaveStringToFile(ExpandConstant('{app}\wampmanager.conf'), A, False);
end;
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • 1
    This is very risky. Better list all strings you have to replace. E.g. in Excel you may filter that out and then create script for INI section. – RobeN Oct 11 '13 at 08:35
  • ok, so, now, i must somehow wait until my app finishes to edit this file also;\ – Ionut Flavius Pogacian Oct 11 '13 at 08:36
  • is this waiting code ok? if(WaitForSingleObject(ExecInfo.hProcess, Timeout) = WAIT_OBJECT_0) then Result := Boolean(ShellExecuteEx(ExecInfo)); – Ionut Flavius Pogacian Oct 11 '13 at 08:38
  • 1
    You need to know what you are waiting for. Now you're going to wait for the process specified by the `ExecInfo.hProcess` to terminate. But it looks a bit suspicious. Are you sure that member constains a valid process handle (since that subsequent call of `ShellExecuteEx` looks strange) ? Anyway, please use `@` char before the user's name for comment notifications and please try to work on a single problem per question. Thanks! – TLama Oct 11 '13 at 08:45