7

The following (in quote) is the content of a XML file which is part of my package. I'd like to replace the value of c:\path\myapp.exe during the installation (with the real path where the user chose to install the application. Is that possible? How to?

<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
   <listAttribute key="org.eclipse.debug.ui.favoriteGroups">
      <listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
   </listAttribute>
   <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
   <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="c:\path\myapp.exe"/>
   <stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="${resource_loc}"/>
</launchConfiguration>
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 1
    Actually I can treat this file as a regular text file. –  Feb 17 '14 at 16:12
  • 2
    You can call the procedure I wrote there like `SaveAttributeValueToXML('C:\File.xml', '//launchConfiguration/stringAttribute[@key=''org.eclipse.ui.externaltools.ATTR_LOCATION'']', 'value', 'C:\NewPath\File.exe');`. – TLama Feb 17 '14 at 16:26

1 Answers1

10

Your best option is to use the XML DOM to select and edit the required node as TLama suggested.

Alternatively, you can install a template file with a known string in the location you want to replace. The file can then be read as a string, modified and written back out again using something like:

[Code]
procedure WriteAppPath;
var
    FileData: String;
begin
    LoadStringFromFile(ExpandConstant('{app}\app.xml'), FileData);
    StringChange(FileData, 'XXXXXMARKERXXXXX', ExpandConstant('{app}'));
    SaveStringToFile(ExpandConstant('{app}\app.xml'), FileData, False);
end;

See also this question about doing the same thing en masse to an INI file.

Community
  • 1
  • 1
Deanna
  • 23,876
  • 7
  • 71
  • 156