function ExistNewfile&:boolean; var i,iFileHandle:integer; FileDateTime:TDateTime; AppIni:TiniFile; g_path:string; url:string; files:TStrings; begin result:=false; url:='http://yousoft.hi.com.cn/update.htm/'; //要升级的服务器 g_path:=ExtractFilePath(application.ExeName); //升级程序的路径 if copy(g_path,length(g_path),1)<>'\' then g_path:=g_path+'\'; if copy(url,length(url),1)<>'/' then url:=url+'/';
//下载升级信息文件 try HTTPFiles.InputFileMode := true; HTTPFiles.OutputFileMode := FALSE; HTTPFiles.ReportLevel := Status_Basic; HTTPFiles.Body:=g_path+'update/update.ini'; //下载后保存到程序的update目录下 HTTPFiles.Get(url); except result:=false; //'取得升级信息出错!,不用再继续 exit; end; try files:=TStringlist.Create; //有哪些文件? AppIni := TIniFile.Create(g_path+'\update\update.ini'); AppIni.ReadSections(files); for i:=0 to files.Count-1 do try iFileHandle :=FileOpen(g_path+files[i],fmShareDenyNone); FileDateTime:=FileDateToDateTime(FileGetDate(iFileHandle)); //取得文件时间 FileClose(iFileHandle); //是否要下载文件 if FileDateTime<strtodatetime(Appini.ReadString(files[i],'datetime','1900-1-1')) then begin result:=true; break; end; except end; finally AppIni.free; files.Free; end; end; 取得files后文件下载!httpfiles为TNMHTTP
for i:=0 to files.Count-1 do //备份文件 begin //备份一份文件出来 copyfile(pchar(g_path+files[i]),pchar(g_path+files[i]+'.bak'),false); end; for i:=0 to files.Count-1 do //从update复制新文件 begin copyfile(pchar(g_path+'update\'+files[i]),pchar(g_path+files[i]),false); end; 因为采用了TNMHTTP,文件下载的进度并不是很好控制,可以在TNMHTTP的PacketRecvd事件,确定进度 在线升级的方法就这样简单介绍了,在DELPHI6+WIN2000环境调试通过,这里我没有写出完整的代码,有兴趣可以自己写写。在我的主页我做了演示程序,大家可以看看,网址是:http://yousoft.hi..com.cn