2013-01-19 8 views
1

我希望安裝程序在沒有提示消息的情況下靜默編輯xml文件,如果目標位置存在xml文件,安裝程序將編輯它,如果不存在於目標位置,安裝將繼續並忽略xml文件不存在而沒有提示消息。我看到了CodeAutomation.iss,但這對我沒有幫助。請幫助一個代碼示例。Inno安裝程序 - 如何保存無提示信息的Xml節點

[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; 

回答

4

只是用於測試的XML文件是否存在第一:

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; 

末;

+2

+1,@Dielo,你應該已經['瞭解FileExists'](http://stackoverflow.com/q/12951327/960757)函數。 – TLama

+0

我原諒了:S謝謝... – Dielo

+0

對不起,你是儀式:)你的答案完美無缺,謝謝隊友 – Dielo

相關問題