为了实现这一点,我创建一个简单的程序,它接受XML文件名作为输入。该过程应解析每行并将内容写入临时文件。代码检查每一行寻找字符串“键=‘名称’”:
if (Pos('key="Name"', strTest) <> 0)
如果找到匹配,那么我通过我的期望的变量,它的value
是从我的自定义页面变得替换特定的行。
strTest := ' <add key="Name" value="' + strName + '"/> ';
这会写入临时文件。然后删除原始的exe.config文件并将temp配置文件重命名为exe.config文件(从而反映出我需要的更改)。下面是该过程的整个代码段,也不要忘记从[文件]调用过程,即
[Files]
Source: "HUS.exe.config"; DestDir: "{app}"; AfterInstall: ConvertConfig('HUS.exe.config')
代码段
procedure ConvertConfig(xmlFileName: String);
var
xmlFile: String;
xmlInhalt: TArrayOfString;
strName: String;
strTest: String;
tmpConfigFile: String;
k: Integer;
begin
xmlFile := ExpandConstant('{app}') + '\' + xmlFileName;
tmpConfigFile:= ExpandConstant('{app}') + '\config.tmp';
strName := UserPage.Values[0] +' '+ UserPage.Values[1];
if (FileExists(xmlFile)) then begin
// Load the file to a String array
LoadStringsFromFile(xmlFile, xmlInhalt);
for k:=0 to GetArrayLength(xmlInhalt)-1 do begin
strTest := xmlInhalt[k];
if (Pos('key="Name"', strTest) <> 0) then begin
strTest := ' <add key="Name" value="' + strName + '"/> ';
end;
SaveStringToFile(tmpConfigFile, strTest + #13#10, True);
end;
DeleteFile(xmlFile); //delete the old exe.config
RenameFile(tmpConfigFile,xmlFile);
end;
end;
[Inno Setup修改基于自定义输入的XML文件的可能的重复] (http://stackoverflow.com/questions/8141886/inno-setup-modify-xml-file-based-on-custom-input) – Deanna 2012-03-07 13:49:29