procedure TfMenu.chk_nuevas_versionesClick(Sender: TObject);
var
vInst:string; dir_exe:String; dir_tmp:String; fic_web_txt:String; fic_pc_txt:String; fic_web_zip:String; fic_pc_zip:String; params:string; nom_apli:String; msg:string; b:Boolean;
TS:TStrings; Str:String; fec:String; titulo:String;
function DownloadFile(Source, Dest: string): Boolean; begin
try
Source := AnsiReplaceStr(Source, '/', '\');
Result := UrlDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
function GetAppVersion:string; var
Size, Size2: DWord;
Pt, Pt2: Pointer;
begin
Size := GetFileVersionInfoSize(PChar (ParamStr (0)), Size2);
if Size > 0 then
begin
GetMem (Pt, Size);
try
GetFileVersionInfo (PChar (ParamStr (0)), 0, Size, Pt);
VerQueryValue (Pt, '\', Pt2, Size2);
with TVSFixedFileInfo (Pt2^) do
begin
Result:= IntToStr (HiWord (dwFileVersionMS)) + '.' +
IntToStr (LoWord (dwFileVersionMS)) + '.' +
IntToStr (HiWord (dwFileVersionLS)) + '.' +
IntToStr (LoWord (dwFileVersionLS));
end;
finally
FreeMem (Pt);
end;
end;
end;
begin
nom_apli := 'VISOR';
dir_tmp := 'c:\temp';
fic_web_txt:= 'http://www.paginaweb.es/ficheros/version_visor.txt';
fic_pc_txt := 'c:\temp\version_visor.txt';
fic_web_zip:= 'http://www.paginaweb.es/ficheros/visor_act.zip';
fic_pc_zip := 'c:\temp\visor_act.zip';
params := '-e -o '+fic_pc_zip;
vInst:= GetAppVersion; dir_exe:=ExtractFilePath(paramstr(0));
If not DirectoryExists(dir_tmp) then
if not createdir(dir_tmp) then
begin
raise exception.create('Proceso cancelado al no poder creárse la carpeta '+dir_tmp);
exit;
end;
b := DownloadFile(fic_web_txt,fic_pc_txt);
if (b) then begin
TS := TStringList.Create();
TS.LoadFromFile(fic_pc_txt);
Str := TS[0]; fec := TS[1]; TS.Free;
DeleteFile(fic_pc_txt);
msg:= 'Versión en este ordenador: '+ vInst+#13+
'Versión en el Servidor____: ' + Str+' de '+fec;
if vInst<>Str then begin
msg:=msg+#13+#13+'Quieres descargar la nueva versión';
titulo:='Descargar actualización '+nom_apli;
if application.MessageBox (pchar(msg),
PCHAR(titulo),
(MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)) <> IDYES then exit;
DownloadFile(fic_web_zip,fic_pc_zip);
msg:= 'Ha descargado la nueva actualización, '+#13+
'al directorio '+dir_tmp+', para instalarla'+#13+
'en su ordenador no debe haber ningún'+#13+
'usuario conectado a la aplicación.'+#13+#13+
'Quiere instalar la nueva versión';
titulo:='Actualizar '+nom_apli;
if application.MessageBox (pchar(msg),
PCHAR(titulo),
(MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)) <> IDYES then exit;
begin
ShellExecute(Handle, 'Open', 'WinZip32.exe', PCHAR(params), PCHAR(dir_exe), SW_NORMAL);
Application.Terminate;
end;
end
else
Application.MessageBox((pChar(msg+#13+#13+'NO HAY NUEVAS ACTUALIZACIONES')) , 'Comprobación versiones', MB_ICONEXCLAMATION) ;
end
else
ShowMessage('Esta comprobación solo se puede hacer'+#13+
'en ordenadores conectados a Internet.'+#13+
'Su equipo no tiene esta conexión'+#13+
'- Proceso Cancelado -');
end;