Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

replacing text in a config file


3 replies to this topic

Mariscal

Mariscal
  • Full Members
  • 50 posts

Posted 03 August 2005 - 17:05

Hi all,

I have a situation where I need to replace the name of an application that appears about three times within an .ini file with the app's new name. As it is, if a user were to perform an upgrade, their ini file would retain the "old" name of the application, which will keep the app from working. What I would like to do is set a variable called szSearchString to the old name, do a FileGrep with the CONTINUE flag, and then where the name is found, overwrite it with the new name. My problem is finding the right mechanism for doing the overwrite.

Any suggestions would be greatly appreciated...

Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 03 August 2005 - 19:39

If it's an INI file why don't you use GetProfString and WriteProfString?

Mariscal

Mariscal
  • Full Members
  • 50 posts

Posted 04 August 2005 - 19:59

The problem I'm finding is that the name of the application is also the name of a section. So I need to change the name of the section to the "new" name of the app. I can't simply delete the whole section and re-add, because I need to preserve the user's settings. It doesn't appear that WriteProfString allows me this ability. So I currently have something like this:

[OldApp]
ApplicationPath=""C:\Program Files\ENS\OldApp.exe""
StartInDirectory=C:\Program Files\ENS\
CommandLineArguments=
InitialTimeOutInSeconds=60
ApplicationTimeOutInSeconds=300
DependsOnApplication=
RestartApplicationLimit=3
SecondsBetweenRestartAttempts=10
ApplicationHungScript=
RestartFailedScript=
AutoRestartInMinutes=0
SecondsBetweenAutoRestartAttempts=0
CriticalApplication=FALSE

and it needs to become...

[NewApp]
ApplicationPath=""C:\Program Files\ENS\NewApp.exe""
StartInDirectory=C:\Program Files\ENS\
CommandLineArguments=
InitialTimeOutInSeconds=60
ApplicationTimeOutInSeconds=300
DependsOnApplication=
RestartApplicationLimit=3
SecondsBetweenRestartAttempts=10
ApplicationHungScript=
RestartFailedScript=
AutoRestartInMinutes=0
SecondsBetweenAutoRestartAttempts=0
CriticalApplication=FALSE

Changing the app name in the ApplicationPath key is straightforward; it's just the section name I'm now trying to change. Thanks very much...

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 05 August 2005 - 01:06

In that case, it sounds like you'll need to read each line into a buffer, write our that new section name to the file, and then write out the buffer content--skipping over the old section name.

Check the help for the general file read/write calls to get started.

Edited by Taco Bell, 05 August 2005 - 01:10.

user posted image