1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
uses omniXML, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdAntiFreezeBase, IdAntiFreeze, IdException;
type TAboutBox = class(TForm)
IdHTTP1: TIdHTTP;
IdAntiFreeze1: TIdAntiFreeze;
...
function ApplicationVersion: String;
procedure getUpdate;
procedure download(upd : String);
...
end;
implementation
const path : String = 'http://xxxxxx.be/'; //url du serveur. Le fichier xml sera stocké à la racine du site.
{procédure de téléchargement de nouvelle version }
procedure TAboutBox.download(upd : String);
var
Fs : TFileStream;
begin
ProgressBar1.Visible :=true;
Button1.Visible :=false;
Fs := TFileStream.Create(Main.AppliPath+'patch.exe',fmCreate); //Nom du fichier local
with IdHTTP1 do
try
try
//URL du fichier à télécharger
Get(upd ,Fs);
except
On E : EIdException do
ShowMessage(Format(LangManager.ConstantValue['RsDownloadError'],[E.Message]));
On E : Exception do
ShowMessage(Format(LangManager.ConstantValue['RsUnknownError'],[E.Message]));
end;
finally
Fs.Free; //Liberer le flux
end;
ShowMessage(LangManager.ConstantValue['RsRestartRequired']);
end;
{procédure de recherche de nouvelle version}
procedure TAboutBox.getUpdate ;
var
version, upd : integer;
xml: IXMLDocument;
url: String;
begin
version := StrToInt(AnsiReplaceStr(ApplicationVersion, '.', '')) ;
xml := CreateXMLDoc;
xml.LoadXML(IdHTTP1.Get(path+'version.xml')); //on récupère le fichier xml
upd := StrToInt(xml.SelectSingleNode('//Version').Text);
url := xml.selectSingleNode('//Path').Text;
if version < upd then begin
if MessageDlg(LangManager.ConstantValue['RsUpdateNeeded'],mtInformation, [mbYes, mbNo],0) = mrYes then
download(url);
end
else ShowMessage(LangManager.ConstantValue['RsNoUpdateNeeded']);
end;
function TAboutBox.ApplicationVersion: String;
var
VerInfoSize, VerValueSize, Dummy: DWord;
VerInfo: Pointer;
VerValue: PVSFixedFileInfo;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
{Deux solutions : }
if VerInfoSize <> 0 then
{- Les info de version sont inclues }
begin
{On alloue de la mémoire pour un pointeur sur les info de version : }
GetMem(VerInfo, VerInfoSize);
{On récupère ces informations : }
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
{On traite les informations ainsi récupérées : }
with VerValue^ do
begin
Result := IntTostr(dwFileVersionMS shr 16);
Result := Result + '.' + IntTostr(dwFileVersionMS and $FFFF);
Result := Result + '.' + IntTostr(dwFileVersionLS shr 16);
Result := Result + '.' + IntTostr(dwFileVersionLS and $FFFF);
end;
{On libère la place précédemment allouée : }
FreeMem(VerInfo, VerInfoSize);
end
else
{- Les infos de version ne sont pas inclues }
{On déclenche une exception dans le programme : }
raise EAccessViolation.Create(LangManager.ConstantValue['RsNoInfoVersion']);
end; |
Partager