V5.75+
This commit is contained in:
@@ -23,11 +23,12 @@ var
|
||||
Lance_verif : integer;
|
||||
verifVersion,notificationVersion : boolean;
|
||||
|
||||
Const Version='5.74'; // sert à la comparaison de la version publiée
|
||||
Const Version='5.75'; // 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;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
@@ -57,40 +58,47 @@ end;
|
||||
|
||||
|
||||
// téléchargement d'une page internet sans cache dans un fichier
|
||||
function DownloadURL_NOCache(aUrl: string;s : string): Boolean;
|
||||
// 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;
|
||||
lpBuffer: array[0..1024 + 1] of byte;
|
||||
dwBytesRead: DWORD;
|
||||
dwTimeout : integer;
|
||||
i : integer;
|
||||
t : longint;
|
||||
begin
|
||||
Result:=False;
|
||||
DeleteFile(s);
|
||||
//Affiche('VV1',clLime);
|
||||
Application.ProcessMessages;
|
||||
Try Fs:=TFileStream.Create(s,fmCreate,fmShareDenyNone);
|
||||
hSession:=InternetOpen('MyApp',INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
|
||||
Result := False;
|
||||
t:=0;
|
||||
Try Fs := TFileStream.Create(s,fmCreate);
|
||||
//hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
|
||||
hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, nil, nil, 0);
|
||||
try
|
||||
if Assigned(hSession) then
|
||||
begin
|
||||
// fonction longue
|
||||
dwTimeout:=2000; //2s
|
||||
//Affiche('VV2',clLime);
|
||||
Application.ProcessMessages;
|
||||
InternetSetOption(hSession,INTERNET_OPTION_CONNECT_TIMEOUT,@dwTimeOut, SizeOf(dwTimeOut));
|
||||
hService:=InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
|
||||
//Affiche('Session assignée',clLime);
|
||||
hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
|
||||
i:=getLastError;
|
||||
if i<>0 then
|
||||
case i of
|
||||
12037 : Affiche('Erreur validité de certificat',clred);
|
||||
12157 : Affiche('Erreur canal sécurisé SSL 2.0',clred);
|
||||
else affiche('Erreur '+intToSTR(i),clred);
|
||||
end;
|
||||
if Assigned(hService) then
|
||||
try
|
||||
//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);
|
||||
end;
|
||||
@@ -103,25 +111,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure verifie_version;
|
||||
var s,s2,s3,Version_p,Url,LocalFile : string;
|
||||
trouve_version,trouve_zip,zone_comm : boolean;
|
||||
|
||||
function verifie_version : real;
|
||||
var s,s2,s3,Version_p,Url,LocalFile,nomfichier : string;
|
||||
trouve_version,trouve_zip,zone_comm,LocZip : boolean;
|
||||
fichier : text;
|
||||
i,j,erreur,Ncomm,i2,i3,l : integer;
|
||||
V_publie,V_utile : real;
|
||||
V_utile,V_publie : real;
|
||||
SV_publie : char;
|
||||
taille : longint;
|
||||
comm : array[1..10] of string;
|
||||
begin
|
||||
//Affiche('vérifie version',clLime);
|
||||
if not(AvecInit) then exit ;
|
||||
if not(verifVersion) then exit;
|
||||
Url:='http://cdmrail.free.fr/ForumCDR/viewtopic.php?f=77&t=3906#p50499';
|
||||
LocalFile:='page.txt';
|
||||
trouve_version:=false;
|
||||
trouve_zip:=false;
|
||||
zone_comm:=false;
|
||||
Ncomm:=0;
|
||||
if DownloadURL_NOCache(Url,localFile) then
|
||||
if DownloadURL_NOCache(Url,localFile,taille) then
|
||||
begin
|
||||
AssignFile(fichier,LocalFile);
|
||||
reset(fichier);
|
||||
@@ -129,10 +137,10 @@ begin
|
||||
begin
|
||||
readln(fichier,s);
|
||||
//Affiche(s,clyellow);
|
||||
s:=LowerCase(s);
|
||||
//s:=LowerCase(s);
|
||||
if not(trouve_version) then
|
||||
begin
|
||||
i:=pos('version ',s);
|
||||
i:=pos('version ',LowerCase(s));
|
||||
trouve_version:=i<>0;
|
||||
if trouve_version then
|
||||
begin
|
||||
@@ -142,7 +150,7 @@ begin
|
||||
end;
|
||||
if not(trouve_zip) then
|
||||
begin
|
||||
i:=pos('.zip',s);
|
||||
i:=pos('.zip',LowerCase(s));
|
||||
trouve_zip:=i<>0;
|
||||
//if trouve_zip then Affiche(s,clyellow);
|
||||
if trouve_zip then
|
||||
@@ -154,7 +162,7 @@ begin
|
||||
// commentaire en gras
|
||||
if zone_comm then
|
||||
begin
|
||||
i:=pos('bold">',s)+6;i2:=posEx('<br />',s,i+1); i3:=posEx('</span>',s,i+1) ;
|
||||
i:=pos('bold">',LowerCase(s))+6;i2:=posEx('<br />',LowerCase(s),i+1); i3:=posEx('</span>',LowerCase(s),i+1) ;
|
||||
if i<>6 then
|
||||
begin
|
||||
//Affiche(s,clred);
|
||||
@@ -164,7 +172,7 @@ begin
|
||||
Delete(s,1,i2-1);
|
||||
j:=0;
|
||||
repeat
|
||||
i:=pos('<br />',s)+6;i3:=posEx('</span>',s,i+1);i2:=posEx('<br />',s,i+1);
|
||||
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
|
||||
@@ -177,7 +185,7 @@ begin
|
||||
inc(j);
|
||||
until (i3<i2) or (ncomm=10) or (j=20);
|
||||
zone_comm:=false;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
closefile(fichier);
|
||||
@@ -185,24 +193,39 @@ begin
|
||||
if trouve_version and trouve_zip then
|
||||
begin
|
||||
// isoler le champ version
|
||||
i:=pos('version ',s2);
|
||||
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('href="',s3);
|
||||
delete(s3,1,i+5);
|
||||
j:=pos('"',s3);
|
||||
s3:=copy(s3,1,j-1);
|
||||
i:=pos('.',s3);
|
||||
if i<>0 then delete(s3,i,1); // supprimer le .
|
||||
s3:='http://cdmrail.free.fr/ForumCDR'+s3 ;
|
||||
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);
|
||||
repeat
|
||||
dec(i);
|
||||
locZip:=s3[i]='/';
|
||||
until (i=1) or LocZip;
|
||||
nomfichier:=copy(s3,i+1,length(s3)-i);
|
||||
|
||||
//Affiche(s3,clLime);
|
||||
//Affiche(nomfichier,clred);
|
||||
|
||||
// changer le . en ,
|
||||
s:=Version_p;
|
||||
// i:=pos('.',s);if i<>0 then s[i]:=',';
|
||||
s2:=version;
|
||||
// i:=pos('.',s2);if i<>0 then s2[i]:=',';
|
||||
// i:=pos('.',s2);if i<>0 then s2[i]:=',';
|
||||
|
||||
s:=AnsiUppercase(s);
|
||||
l:=length(s);
|
||||
@@ -220,7 +243,6 @@ begin
|
||||
FormVersion.Top:=10;
|
||||
FormVersion.Left:=10;
|
||||
FormVersion.show;
|
||||
//aff(s3); // url dans s3
|
||||
s:='Vous utilisez la version '+version+SousVersion+' mais il existe la version '+Version_p+SV_publie;
|
||||
if ncomm>0 then
|
||||
begin
|
||||
@@ -231,31 +253,31 @@ begin
|
||||
if MessageDlg(s+'. Voulez-vous la télécharger?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
|
||||
begin
|
||||
// récupérer depuis la variable d'environnement windows USERPROFILE le repertoire de la session ouverte
|
||||
s:=GetCurrentProcessEnvVar('USERPROFILE')+'\Downloads\Signaux_Complexes_GL.Zip';
|
||||
s:=GetCurrentProcessEnvVar('USERPROFILE')+'\Downloads\'+Nomfichier;
|
||||
Aff('Téléchargement de '+s3+' dans ');
|
||||
Aff(s);
|
||||
|
||||
if DownloadURL_NOCache(s3,s) then
|
||||
//if true then
|
||||
if DownloadURL_NOCache(s3,s,taille) then
|
||||
begin
|
||||
Aff('Téléchargement réussi');
|
||||
Aff('Vous pouvez ouvrir le dossier de téléchargement, décomprimer le zip et l''installer');
|
||||
if taille>700000 then
|
||||
begin
|
||||
Aff('Téléchargement réussi');
|
||||
Aff('Vous pouvez ouvrir le dossier de téléchargement, décomprimer le zip et l''installer');
|
||||
end
|
||||
else Aff('Echec 2 de téléchargement');
|
||||
end
|
||||
else Aff('Echec de téléchargement');
|
||||
else Aff('Echec 1 de téléchargement');
|
||||
end
|
||||
else formVersion.Free;
|
||||
end;
|
||||
result:=V_publie;
|
||||
|
||||
if notificationVersion then
|
||||
begin
|
||||
if V_utile=V_publie then Affiche('Votre version '+Version_p+SousVersion+' est à jour',clLime);
|
||||
if V_utile>V_publie then Affiche('Votre version '+version+SousVersion+' est plus récente que la version publiée '+Version_p+SV_publie,clLime);
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if notificationVersion then Affiche('Pas d''accès au site CDM rail ou échec téléchargement',clorange);
|
||||
result:=0;
|
||||
if notificationVersion then Affiche('Pas d''accès au site ou échec téléchargement',clorange);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -263,13 +285,29 @@ end;
|
||||
procedure TFormVersion.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Timerverif.Interval:=1000; // timer à 1 seconde
|
||||
Lance_verif:=3; // lancer la vérification de version dans 1s
|
||||
Lance_verif:=2; // lancer la vérification de version dans 3s
|
||||
end;
|
||||
|
||||
procedure TFormVersion.TimerVerifTimer(Sender: TObject);
|
||||
var V_utile,V_publie : real;
|
||||
erreur: integer;
|
||||
s : string;
|
||||
begin
|
||||
if lance_verif>0 then dec(lance_verif);
|
||||
if lance_verif=1 then begin lance_verif:=0;verifie_version;end;
|
||||
if lance_verif=0 then
|
||||
begin
|
||||
timerVerif.Enabled:=false;
|
||||
if not(AvecInit) then exit;
|
||||
if not(verifVersion) then exit;
|
||||
V_publie:=verifie_version;
|
||||
if notificationVersion and (v_publie>0) then
|
||||
begin
|
||||
val(version,V_utile,erreur);
|
||||
str(v_publie:2:2,s);
|
||||
if V_utile=V_publie then Affiche('Votre version '+Version+SousVersion+' est à jour',clLime);
|
||||
if V_utile>V_publie then Affiche('Votre version '+version+SousVersion+' est plus récente que la version publiée '+s,clLime);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
|
||||
Reference in New Issue
Block a user