unit update_unit;
interface
uses Windows, SysUtils, Classes, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP,Dialogs,MSXML2_TLB,ShellApi,IniFiles;
procedure load ;
procedure readxml;
procedure ini;
var
xmlDoc: IXMLDOMDocument2;
close_upd :boolean;
URL,version:
string;
implementation
uses unit1;
{$R *.dfm}
procedure readxml;
Var ivers,url_xml,force_update:IXMLDOMnode; internet_addr:
string;
Begin
xmlDoc:=CoDomDocument40.Create;
xmlDoc.setProperty('
NewParser',true);
//Laden der XML
xmlDoc.load('
http://de.geocities.com/boincobserver/update.xml') ;
if xmlDoc.parseError.errorCode = 0
then
Begin
ivers:= xmldoc.selectSingleNode('
BOINC-Observer/files/actual_version/version') ;
version:= ivers.text;
if Form1.versnum.Caption=ivers.text
then Begin Form1.check_upd.Caption:='
no update alivable';close_upd:=true;
End
else
Begin
force_update:= xmldoc.selectSingleNode('
BOINC-Observer/files/actual_version/force_update') ;
URL_xml:=xmldoc.selectSingleNode('
BOINC-Observer/files/actual_version/force_update_url') ;
if force_update.text='
yes'
then URL:=url_xml.text
else
Begin
url_xml:= xmldoc.selectSingleNode('
BOINC-Observer/files/actual_version/progam_url') ;
URL:=url_xml.text;
End;
close_upd:=false;
End;
End
else close_upd:=true;
End;
procedure ini;
var Ini: TIniFile;
Begin
try
Ini:=TIniFile.Create(ExtractFileDir(Application.ExeName)+'
\BOINC-OBSERVER.ini');
Begin
Ini.WriteString('
update','
to version',version);
Ini.WriteBool('
update','
to do',true);
End;
except
Ini.Free
End;
End;
procedure load ;
Var stream:Tstream; file_size:
string; IdHttp:TIdHttp;
Begin
IdHttp := IdHttp.Create(
nil);
Form1.check_upd.Caption:='
try to connect' ;
readxml;
if close_upd=false
then
Begin
Form1.check_upd.Caption:='
got data' ;
IdHTTP.Head(
URL);
if MessageDlg('
Download the files now? ['+IntToStr(round(IdHTTP.Response.ContentLength /1048576))+'
MB]', mtInformation, [mbYes, mbNo], 0)=mrYes
then
Begin
stream := TFileStream.Create((ExtractFileDir(Application.ExeName)+'
\update.zip'), fmCreate);
Form1.check_upd.Caption:='
downloading' ;
try
IdHTTP.Get(
URL, stream);
except
on e:
exception do
ShowMessage('
Error: ' + e.
Message);
end;
stream.Free;
Form1.check_upd.Caption:='
updated';
ini;
if MessageDlg('
Install the new version know or during the next start? (NOTE:BOINC-Observer will be short close!)', mtInformation, [mbYes, mbNo], 0)=mrYes
then
Begin
Form1.Close;
End
End
else Form1.check_upd.Caption:='
aborted' ;
end
else Form1.check_upd.Caption:='
error' ;
end;
end.