procedure Tflogin.Timer1Timer(Sender: TObject); var DownLoadFile:TFileStream; myini: Tinifile; myver, oldver, filename: string; aURL: string; IdHttp: TIdHttp; begin Timer1.Enabled:=false;
myini := TIniFile.Create(pchar(ExtractFilePath(Application.ExeName))+'user.ini'); oldver := myini.ReadString('server','ver','100'); myini.Free;
aURL:='http://x.x.x.x/pub/downFile.do?fileid=2602'; //指向新的升级版本文件:up_2608.ini,其中2608为新的运行文件fileid IdHttp := TIdHttp.Create(self); // 处理重定向 IdHttp.HandleRedirects := True; //IdHttp.Request.GetNamePath; IdHttp.Head(aURL); // 获取重定向后的URL //aURL := IdHttp.URL.URI;
//取真实文件名 Filename:= IdHttp.Response.RawHeaders.Values['Content-Disposition']; Filename := copy(Filename,pos('=',Filename)+1,length(Filename));
//获取Filename中的更新ID Filename:=copy(Filename,pos('_',Filename)+1,length(Filename)); myver:=copy(Filename,1,pos('.',Filename)-1);
if myver<>oldver then begin lbl_info.Caption := '发现新程序版本,更新...'; //Button1.Enabled:=false; //检查jfglUpdate.exe存在 filename:=pchar(ExtractFilePath(Application.ExeName))+'Update.exe'; if not fileExists(filename) then //没有, 下载 begin lbl_info.Caption:= '正在下载更新程序,请稍候...'; DownLoadFile:=TFileStream.Create(pchar(ExtractFilePath(Application.ExeName))+'Update.exe',fmCreate); IdHTTP.Get('http://x.x.x.x/pub/downFile.do?fileid=2607',DownLoadFile);//2607指向Update.exe DownLoadFile.Free; Delay(2000); end; ShellExecute(0, nil, 'Update.exe', PChar(myver), nil, SW_SHOWNORMAL); application.Terminate; end; end;
|