| 发表于:2007-11-26 09:01:078楼 得分:17 |
unit untupdtstat; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, idbasecomponent, idcomponent, idtcpconnection,inifiles, idtcpclient, idftp,shellapi,extctrls, idftplist,strutils; type tupdtstatform = class(tform) updtmessage: tmemo; updtftp: tidftp; edit1: tedit; button1: tbutton; timer1: ttimer; label1: tlabel; procedure button1click(sender: tobject); procedure timer1timer(sender: tobject); procedure formcreate(sender: tobject); private { private declarations } public { public declarations } end; var updtstatform: tupdtstatform; implementation {$r *.dfm} function getfilenamestr(srcstr:string):string; var i:integer; begin i:=0; while (srcstr[length(srcstr)-i] <> ' ')and (i <length(srcstr)) do inc(i); result:=rightstr(srcstr,i); end; procedure tupdtstatform.button1click(sender: tobject); begin edit1.readonly := true; timer1.enabled := true; end; procedure tupdtstatform.timer1timer(sender: tobject); var tpfilenamestr:string; dirstrings:tstrings; i:smallint; att:tiddiritemtype; iniparam : tinifile; verlocal,verserver:string; begin try begin updtftp.host := edit1.text; updtftp.connect(true); updtmessage.lines.add('ftp主机已连接,正在检测程序版本......'); //updtmessage.lines.add('current directory is:"'+updtftp.retrievecurrentdir+'"'); updtftp.changedir('/lqf'); //updtmessage.lines.add('current directory is:"'+updtftp.retrievecurrentdir+'"'); iniparam := tinifile.create(getcurrentdir+'\test.ini'); verlocal := iniparam.readstring('versioninfo','versionno','') ; iniparam.free; updtmessage.lines.add('目前本机程序版本:'+verlocal); updtftp.get('test.ini','test1.ini',true,false); iniparam := tinifile.create(getcurrentdir+'\test1.ini'); verserver := iniparam.readstring('versioninfo','versionno','') ; iniparam.free; deletefile('test1.ini'); dirstrings := tstringlist.create; if not (trim(verlocal)=trim(verserver)) then begin updtmessage.lines.add('服务器有最新版本程序,开始更新......'); updtftp.list(dirstrings,'',true); //updtmessage.lines.add(inttostr(dirstrings.count)); for i:=0 to dirstrings.count-1 do begin att:=updtftp.directorylisting.items[i].itemtype; if att <> ditfile then continue; tpfilenamestr := getfilenamestr(dirstrings.strings[i]); updtmessage.lines.add('下载:'+tpfilenamestr+'......'); updtftp.get(tpfilenamestr,tpfilenamestr,true,false); updtmessage.text := updtmessage.text+' 完成!'; //updtftp.get(tpfilenamestr,'d:\ftptest\downfiles\'+tpfilenamestr,true,false); end; updtmessage.lines.add('程序自动更新完成,初始化数据库连接中......'); end else updtmessage.lines.add('服务器上的程序没有更新的版本,初始化数据库连接中......'); //updtftp.get('testomisxndate.exe','testomisxndate.exe',true,false); //updtftp.get('1.txt','1.txt',true,false); dirstrings.free; winEXEC('testomisxndate.exe',sw_show); //winEXEC('d:\ftptest\downfiles\testomisxndate.exe',sw_show); application.terminate; end; except on e:exception do begin timer1.enabled := false; //messagedlg('ftp下载更新程序时出错,错误信息:'+e.message, mterror, [mbok], 0); if pos('connection timed out',e.message) <> 0 then begin if messagedlg('指定ftp主机连接不上,“确定”重新输入地址,“否”退出程序', mtconfirmation,[mbyes,mbno],0)=mrno then application.terminate; edit1.readonly := false; end else if pos('no route',e.message) <> 0 then begin messagedlg('本机没有连接网络,请排除故障后重新启动!', mterror, [mbok], 0); application.terminate; end else begin messagedlg('ftp下载更新程序时出错,错误信息:'+e.message, mterror, [mbok], 0); application.terminate; end; end; end; end; procedure tupdtstatform.formcreate(sender: tobject); begin edit1.readonly := false; edit1.text := '172.18.1.31'; updtmessage.clear; updtmessage.lines.add('程序初始化中......'); end; end. | | |
|