V7.3
This commit is contained in:
@@ -5,7 +5,7 @@ interface
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, StdCtrls , ComCtrls ,WinInet, ExtCtrls , StrUtils, unitPrinc,
|
||||
ShellAPI ;
|
||||
ShellAPI;
|
||||
|
||||
type
|
||||
TFormVersion = class(TForm)
|
||||
@@ -23,14 +23,14 @@ var
|
||||
FormVersion: TFormVersion;
|
||||
Lance_verif : integer;
|
||||
verifVersion,notificationVersion : boolean;
|
||||
date_creation : string;
|
||||
|
||||
Const Version='7.2'; // sert à la comparaison de la version publiée
|
||||
Const Version='7.3'; // sert à la comparaison de la version publiée
|
||||
SousVersion=' '; // A B C ... en cas d'absence de sous version mettre un espace
|
||||
|
||||
function GetCurrentProcessEnvVar(const VariableName: string): string;
|
||||
function verifie_version : real;
|
||||
function DownloadURL_NOCache(aUrl: string;s : string;var taille : longint): Boolean;
|
||||
function url_github(var url: string) : boolean;
|
||||
|
||||
implementation
|
||||
|
||||
@@ -61,56 +61,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// récupère l'url de téléchargement du github avec curl
|
||||
// curl -s https://api.github.com/repos/f1iwq2/signaux_complexes_gl/releases/latest \
|
||||
function url_github(var url: string) : boolean;
|
||||
var s : string;
|
||||
retour,i : integer;
|
||||
trouve : boolean;
|
||||
fichier : text;
|
||||
begin
|
||||
result:=false;
|
||||
url:='';
|
||||
s:='-s -o url.txt https://api.github.com/repos/f1iwq2/signaux_complexes_gl/releases/latest'; // résultat dans url.txt
|
||||
//s:='';
|
||||
retour:=ShellExecute(Formprinc.Handle,'open',
|
||||
Pchar('curl.exe'),
|
||||
//Pchar('cmd.exe'),
|
||||
Pchar(s), // paramètre
|
||||
Pchar('') // répertoire
|
||||
,SW_HIDE); // pas d'affichage
|
||||
if retour>32 then
|
||||
begin
|
||||
result:=true;
|
||||
assign(fichier,'url.txt');
|
||||
reset(fichier);
|
||||
trouve:=false;
|
||||
while not(eof(fichier)) or not trouve do
|
||||
begin
|
||||
readln(fichier,s);
|
||||
if pos('browser_download_url',s)<>0 then
|
||||
begin
|
||||
trouve:=true;
|
||||
i:=pos('https',s);
|
||||
delete(s,1,i-1);
|
||||
i:=pos('"',s);
|
||||
s:=copy(s,1,i-1);
|
||||
url:=s;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
end;
|
||||
|
||||
|
||||
// téléchargement d'une page internet sans cache dans un fichier
|
||||
// aUrl = adresse URL du fichier - S : chemin et nom du fichier à écrire - taille : renvoie la taille lue en octets
|
||||
function DownloadURL_NOCache(aUrl: string;s : string;var taille : longint): Boolean;
|
||||
var
|
||||
hSession: HINTERNET;
|
||||
hService: HINTERNET;
|
||||
Fs:TFileStream;
|
||||
hSession,hService: hinternet;
|
||||
Fs : TFileStream;
|
||||
lpBuffer: array[0..1024 + 1] of byte;
|
||||
dwBytesRead: DWORD;
|
||||
dwBytesRead: dword;
|
||||
i : integer;
|
||||
t : longint;
|
||||
begin
|
||||
@@ -122,7 +80,6 @@ begin
|
||||
try
|
||||
if Assigned(hSession) then
|
||||
begin
|
||||
//Affiche('Session assignée',clLime);
|
||||
hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
|
||||
i:=getLastError;
|
||||
if i<>0 then
|
||||
@@ -136,13 +93,13 @@ begin
|
||||
//Affiche('Service assigné',clLime);
|
||||
while True do
|
||||
begin
|
||||
dwBytesRead := 1024;
|
||||
dwBytesRead:=1024;
|
||||
InternetReadFile(hService,@lpBuffer,1024,dwBytesRead);
|
||||
fs.WriteBuffer(lpBuffer,dwBytesRead);
|
||||
t:=t+dwBytesRead;
|
||||
if dwBytesRead=0 then break;
|
||||
end;
|
||||
Result := True;
|
||||
Result:=True;
|
||||
taille:=t;
|
||||
finally
|
||||
InternetCloseHandle(hService);
|
||||
@@ -156,22 +113,51 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// renvoie le numéro de version depuis le forum CDM
|
||||
// renvoie le numéro de version depuis le site github
|
||||
function verifie_version : real;
|
||||
var s,s2,s3,Version_p,Url,LocalFile,nomfichier : string;
|
||||
var description,s,s2,s3,Version_p,Url,LocalFile,nomfichier,nombre_tel,date_creation_ang
|
||||
: string;
|
||||
trouve_version,trouve_zip,zone_comm,LocZip : boolean;
|
||||
fichier : text;
|
||||
i,j,erreur,Ncomm,i2,i3,l : integer;
|
||||
i,j,erreur,Ncomm,i2,l : integer;
|
||||
V_utile,V_publie : real;
|
||||
SV_publie : char;
|
||||
taille : longint;
|
||||
comm : array[1..10] of string;
|
||||
|
||||
function extrait_champ(ss : string) : string;
|
||||
var i,j : integer;
|
||||
begin
|
||||
s:='"'+s+'"';
|
||||
result:='';
|
||||
i:=pos(ss,s);
|
||||
if i<>0 then
|
||||
begin
|
||||
i:=posEx('"',s,i+1);
|
||||
i:=posEx('"',s,i+1);
|
||||
j:=posex('"',s,i+1);
|
||||
result:=copy(s,i+1,j-i-1);
|
||||
end;
|
||||
end;
|
||||
|
||||
function extrait_champ_simple(ss : string) : string;
|
||||
var i,j : integer;
|
||||
begin
|
||||
s:='"'+s+'"';
|
||||
result:='';
|
||||
i:=pos(ss,s);
|
||||
if i<>0 then
|
||||
begin
|
||||
i:=posEx(':',s,i+1);
|
||||
j:=posEx(',',s,i+1);
|
||||
//j:=posex('"',s,i+1);
|
||||
result:=copy(s,i+1,j-i-1);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
//Affiche('vérifie version',clLime);
|
||||
// tester si on peut extraire l'url par curl
|
||||
//if url_github(UrlGIT) then affiche('curl ok',clyellow);
|
||||
|
||||
Url:='http://cdmrail.free.fr/ForumCDR/viewtopic.php?f=77&t=3906#p50499';
|
||||
Url:='https://api.github.com/repos/f1iwq2/signaux_complexes_gl/releases/latest';
|
||||
LocalFile:='page.txt';
|
||||
trouve_version:=false;
|
||||
trouve_zip:=false;
|
||||
@@ -181,82 +167,75 @@ begin
|
||||
begin
|
||||
AssignFile(fichier,LocalFile);
|
||||
reset(fichier);
|
||||
|
||||
while not(eof(fichier)) and (not(trouve_version) or not(trouve_zip)) do
|
||||
begin
|
||||
readln(fichier,s);
|
||||
//Affiche(s,clyellow);
|
||||
//s:=LowerCase(s);
|
||||
if not(trouve_version) then
|
||||
|
||||
// adresse de téléchargement
|
||||
s3:=extrait_champ('browser_download_url');
|
||||
if s3<>'' then trouve_zip:=true;
|
||||
|
||||
// nombre de téléchargements
|
||||
nombre_tel:=extrait_champ_simple('download_count');
|
||||
|
||||
// date de création
|
||||
date_creation_ang:=extrait_champ('created_at');
|
||||
if date_creation_ang<>'' then
|
||||
begin
|
||||
i:=pos('version ',LowerCase(s));
|
||||
trouve_version:=i<>0;
|
||||
if trouve_version then
|
||||
begin
|
||||
s2:=s;zone_comm:=true;
|
||||
//Affiche('trouvé version',clOrange);
|
||||
end;
|
||||
//Affiche(date_creation_ang,clyellow);
|
||||
i:=pos('-',date_creation_ang);
|
||||
j:=posex('-',date_creation_ang,i+1);
|
||||
i2:=pos('T',date_creation_ang);
|
||||
date_creation:=copy(date_creation_ang,j+1,i2-j-1);
|
||||
date_creation:=date_creation+'/'+copy(date_creation_ang,i+1,j-i-1);
|
||||
date_creation:=date_creation+'/'+copy(date_creation_ang,1,i-1);
|
||||
date_creation:=date_creation+' '+copy(date_creation_ang,i2+1,length(date_creation_ang)-i2-1);
|
||||
//Affiche(date_creation,clyellow);
|
||||
end;
|
||||
if not(trouve_zip) then
|
||||
|
||||
// version publiée
|
||||
version_p:=extrait_champ('tag_name');
|
||||
if version_p<>'' then
|
||||
begin
|
||||
i:=pos('.zip',LowerCase(s));
|
||||
trouve_zip:=i<>0;
|
||||
//if trouve_zip then Affiche(s,clyellow);
|
||||
if trouve_zip then
|
||||
begin
|
||||
s3:=s;
|
||||
//zone_comm:=false;
|
||||
end;
|
||||
trouve_version:=true;
|
||||
if not(version_p[1] in ['0'..'9']) then delete(version_p,1,1);
|
||||
end;
|
||||
// commentaire en gras
|
||||
if zone_comm then
|
||||
|
||||
description:=extrait_champ('body');
|
||||
if description<>'' then
|
||||
begin
|
||||
description:=utf8Decode(description);
|
||||
i:=1 ; j:=1;
|
||||
// couper en chaînes
|
||||
while j<>0 do
|
||||
begin
|
||||
i:=pos('bold">',LowerCase(s))+6;i2:=posEx('<br />',LowerCase(s),i+1); i3:=posEx('</span>',LowerCase(s),i+1) ;
|
||||
if i<>6 then
|
||||
j:=pos('\r',description);
|
||||
if j<>0 then
|
||||
begin
|
||||
//Affiche(s,clred);
|
||||
inc(ncomm);
|
||||
if i3<i2 then i2:=i3;
|
||||
comm[ncomm]:=UTF8Decode(copy(s,i,i2-i));
|
||||
Delete(s,1,i2-1);
|
||||
j:=0;
|
||||
repeat
|
||||
i:=pos('<br />',LowerCase(s))+6;i3:=posEx('</span>',LowerCase(s),i+1);i2:=posEx('<br />',LowerCase(s),i+1);
|
||||
inc(ncomm);
|
||||
if i2<i3 then
|
||||
begin
|
||||
comm[ncomm]:=UTF8Decode(copy(s,i,i2-i));Delete(s,1,i2-1);
|
||||
end
|
||||
else
|
||||
begin
|
||||
comm[ncomm]:=UTF8Decode(copy(s,i,i3-i));Delete(s,1,i3-1);
|
||||
end;
|
||||
inc(j);
|
||||
until (i3<i2) or (ncomm=10) or (j=20);
|
||||
zone_comm:=false;
|
||||
comm[i]:=copy(description,1,j-1);
|
||||
inc(i);
|
||||
delete(description,1,j+1);
|
||||
end;
|
||||
|
||||
j:=pos('\n',description);
|
||||
if j<>0 then
|
||||
begin
|
||||
delete(description,j,2);
|
||||
end;
|
||||
|
||||
end;
|
||||
comm[i]:=description;
|
||||
ncomm:=i;
|
||||
|
||||
end;
|
||||
|
||||
end;
|
||||
closefile(fichier);
|
||||
|
||||
if trouve_version and trouve_zip then
|
||||
begin
|
||||
// isoler le champ version
|
||||
i:=pos('version ',LowerCase(s2));
|
||||
delete(s2,1,i+7);
|
||||
j:=pos(' ',s2);
|
||||
Version_p:=copy(s2,1,j-1); // version dans version_p Exemple V4.73b
|
||||
// isoler l'url du zip
|
||||
i:=pos('.zip',LowerCase(s3));
|
||||
repeat
|
||||
dec(i);
|
||||
locZip:=s3[i]='=';
|
||||
until (i=1) or LocZip;
|
||||
if locZip then
|
||||
begin
|
||||
delete(s3,1,i+1);
|
||||
end;
|
||||
i:=pos('zip"',LowerCase(s3)); // s3 contient l'url du zip
|
||||
s3:=copy(s3,1,i+2);
|
||||
//----------------------------------------------------
|
||||
//isoler le nom du fichier
|
||||
i:=length(s3);
|
||||
@@ -266,6 +245,8 @@ begin
|
||||
until (i=1) or LocZip;
|
||||
nomfichier:=copy(s3,i+1,length(s3)-i);
|
||||
|
||||
//affiche(nombre_tel,cllime);
|
||||
|
||||
//Affiche(s3,clLime);
|
||||
//Affiche(nomfichier,clred);
|
||||
|
||||
@@ -284,19 +265,19 @@ begin
|
||||
if erreur<>0 then exit;
|
||||
val(s2,V_utile,erreur);
|
||||
if erreur<>0 then exit;
|
||||
|
||||
if (V_utile<V_publie) or
|
||||
((V_utile=V_publie) and (SousVersion<SV_publie)) then
|
||||
begin
|
||||
FormVersion.Top:=10;
|
||||
FormVersion.Top:=10;
|
||||
FormVersion.Left:=10;
|
||||
FormVersion.show;
|
||||
s:='Vous utilisez la version '+version+SousVersion+' mais il existe la version '+Version_p+SV_publie;
|
||||
if ncomm>0 then
|
||||
if length(description)>0 then
|
||||
begin
|
||||
Aff('Nouveautés de la V'+version_p+SV_publie+' de Signaux_Complexes_GL :');
|
||||
FormVersion.Memo1.lines.Clear;
|
||||
Aff('Nouveautés de la V'+version_p+SV_publie+' de Signaux_Complexes_GL du '+date_creation);
|
||||
aff(' ');
|
||||
for i:=1 to ncomm-1 do aff(comm[i]);
|
||||
for i:=1 to ncomm do aff(comm[i]);
|
||||
end;
|
||||
if MessageDlg(s+'. Voulez-vous la télécharger?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
|
||||
begin
|
||||
@@ -316,15 +297,18 @@ begin
|
||||
end
|
||||
else Aff('Echec 1 de téléchargement');
|
||||
end
|
||||
else formVersion.Free;
|
||||
else formVersion.close;
|
||||
end;
|
||||
result:=V_publie;
|
||||
end;
|
||||
end
|
||||
else
|
||||
affiche('Le dépôt github ne comprend aucune version diffusée.',clOrange);
|
||||
|
||||
end
|
||||
else
|
||||
begin
|
||||
result:=0;
|
||||
if notificationVersion then Affiche('Pas d''accès au site ou échec téléchargement',clorange);
|
||||
if notificationVersion then Affiche('Pas d''accès au site github.com ou échec téléchargement',clorange);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user