Dielo
Dielo

Reputation: 633

Inno Setup - How to Save a Xml Node without Prompt Message

I want the installer to edit a xml file in silence, without promp messages, that if the xml file exist in destination location, the installer edit it, and if do not exist in destination location, the installation continue and ignore that the xml file do not exist without prompt message. I saw the CodeAutomation.iss but that do not help me. Please help with a code sample.

[Files]
Source: GameConfiguration.xml; DestDir: "{pf}\Game\Sala"; Flags: uninsneveruninstall;

procedure SaveValueToXML(const AFileName, APath, AValue: string);
var
  XMLNode: Variant;
  XMLDocument: Variant;  
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(AFileName);
    if (XMLDocument.parseError.errorCode <> 0) then
      MsgBox('Install Garena. ' +
        XMLDocument.parseError.reason, mbError, MB_OK)
    else
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLNode := XMLDocument.selectSingleNode(APath);
      XMLNode.text := AValue;
      XMLDocument.save(AFileName);
    end;
  except
    MsgBox('Install Garena', mbError, MB_OK);
  end;
end;

  function NextButtonClick2(PageID: Integer): Boolean;
 begin
    Result := True;
    if (PageId = wpFinished) then begin
        SaveValueToXML(ExpandConstant('{pf}\Game\Sala\GameConfiguration.xml'), '//@param', PEdit.Text);
        SaveValueToXML(ExpandConstant('{pf}\Game\Sala\GameConfiguration.xml'), '//@path', ExpandConstant('{reg:HKCU\SOFTWARE\xxx,InstallPath}\xxx.exe'));
    end;
 end;

Upvotes: 1

Views: 629

Answers (1)

Ken White
Ken White

Reputation: 125728

Just test for the existence of the XML file first:

function NextButtonClick2(PageID: Integer): Boolean;
var
  XMLFile: string;
begin
  Result := True;
  if (PageId = wpFinished) then 
  begin
    XMLFile := ExpandConstant('{pf}\Game\Sala\GameConfiguration.xml');
    if FileExists(XMLFile) then 
    begin
      SaveValueToXML(XMLFile, '//@param', PEdit.Text);
      SaveValueToXML(XMLFile, '//@path', 
        ExpandConstant('{reg:HKCU\SOFTWARE\XXX,InstallPath}\xxx.exe'));
    end;
  end;
end;

end;

Upvotes: 4

Related Questions