$PBExportHeader$uo_atudexe.sru forward global type uo_atudexe from nonvisualobject end type type sys_autoudexe_info from structure within uo_atudexe end type type filetime from structure within uo_atudexe end type type systemtime from structure within uo_atudexe end type end forward type sys_autoudexe_info from structure string filename datetime buildtime string filesit integer needreg integer needrun string dscrp long dt_size datetime local_buildtime string md5 string local_md5 end type type FILETIME from structure long dwLowDateTime long dwHighDateTime end type type SYSTEMTIME from structure integer wYear integer wMonth integer wDayOfWeek integer wDay integer wHour integer wMinute integer wSecond integer wMilliseconds end type global type uo_atudexe from nonvisualobject event ue_other ( ) end type global uo_atudexe uo_atudexe type prototypes Function long GetFullPathName (String lpFileName ,Long nBufferLength,ref string lpBuffer,ref long lpFilePart) library "kernel32" ALIAS FOR "GetFullPathNameA;Ansi" Function long CreateDirectory (string lpNewDirectory ,ref SECURITY_ATTRIBUTES lpSecurityAttributes ) library "kernel32" Alias for "CreateDirectoryA;Ansi" Function long GetFileTime (Long hFile ,ref filetime lpCreationTime ,ref filetime lpLastAccessTime ,ref filetime lpLastWriteTime ) library "kernel32" Alias for "GetFileTime;Ansi" Function long lopen (string lpPathName , long iReadWrite ) library "kernel32" Alias for "_lopen;Ansi" Function long lclose (long hFile) library "kernel32" Alias for "_lclose" Function long FileTimeToSystemTime (ref FILETIME lpFileTime ,ref SYSTEMTIME lpSystemTime ) library "kernel32" Alias for "FileTimeToSystemTime;Ansi" Function long CopyFile (String lpExistingFileName , String lpNewFileName , long bFailIfExists ) library "kernel32" Alias for "CopyFileA;Ansi" Subroutine Sleep(ulong dwMilliseconds) LIBRARY "kernel32.dll" Function long GetWindowsDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetWindowsDirectoryA;Ansi" Function long GetSystemDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetSystemDirectoryA;Ansi" Function long SetFileAttributes (String lpFileName , long dwFileAttributes ) Library "kernel32" Alias for "SetFileAttributesA;Ansi" Function ULong CopyFile(Ref String lpExistingFileName,Ref String lpNewFileName,ULong bFailIfExists) Library "kernel32.dll" Alias FOR "CopyFileA;Ansi"; function boolean UnZipTo(string strZipFileName,string strDirectoryPath,boolean IsKeepPaths,string strPassword) Library 'wfZip18_DLL.dll' alias for "UnZipTo;Ansi"; end prototypes type variables //oleobject md5 //uo_reghelper ll_reghelper private: DataStore FilterData,ds_data int relt=0 string msg="" int i=0,j=0 string importtempfilepath='importtmp' string exporttempfilepath='exporttmp' string exportlogpath='exportlog' string importlogpath='importlog' string inceptpath='inceptdata' string incepttmpfile='_inceptdata.tmp' string fjfilepath = 'fjtemp' string updatexepath='updatexetmp' string tmpzipupdatexefilename='upload.tmp' string updatexelogfilename='updatexe.log' string winregtmp='HKEY_LOCAL_MACHINE\Software\longjoetmp' blob blbdw_data string sys_changetime="sys_changetime" string sys_changeflag="sys_changeflag" string infofilename="_table_info.ifo" //传递的信息文件 string dts_deletelog="dts_deletelog" //删除日志表 end variables forward prototypes private function integer uf_zipfile (string fpath[], string arg_objfilename, ref string a_msg) private function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg) private function string pf_readtifofile (string arg_objfilename, ref string arg_msg) public function integer f_init_syscurpath (ref string arg_msg) public function integer f_trycreate_sys_autoudexe (transaction arg_transaction, ref string arg_msg) public function integer f_del_uploadexe (transaction arg_transaction, string arg_filename, ref string arg_msg) public function datetime pf_getfilecreatetime (string arg_filefullpathname) public function integer f_autoupdateexe (ref transaction arg_transaction, ref string arg_msg) public function integer pf_downloadexe (ref transaction arg_transaction, string arg_filename, ref string arg_msg) public function integer f_uploadexe (ref transaction arg_transaction, string arg_objfilename, string arg_filesit, integer arg_needreg, integer arg_needrun, string arg_dscrp, ref string arg_msg) public function integer f_istlnewfile () public function integer uf_unzipfile (string arg_zipfilename, string arg_objfilepath, ref string a_msg) end prototypes event ue_other;/////////////Autoupdateexe begin in application's begin //uo_atudexe uo_ins_atudexe //uo_ins_atudexe=create uo_atudexe // //ls_rslt=uo_ins_atudexe.f_init_syscurpath(lls_str) //ls_rslt=uo_ins_atudexe.f_autoupdateexe(sqlca,lls_str) // //destroy uo_ins_atudexe //////////////Autoupdateexe end // end event private function integer uf_zipfile (string fpath[], string arg_objfilename, ref string a_msg);//uf_zipfile(fpath[],arg_objfilename,a_msg) Long ll_status = 0,ls_i = 0 OLEObject ZIPObject relt = 1 ZIPObject = Create OLEObject ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGZipfiles") IF ll_status < 0 THEN relt = 0 CHOOSE CASE ll_status CASE -1 a_msg = "Invalid Call: the argument is the Object property of a control" CASE -2 a_msg = "Class name not found" CASE -3 a_msg = "Object could not be created" CASE -4 a_msg = "Could not connect to object" CASE -9 a_msg = "Other error" END CHOOSE GOTO ext END IF arg_objfilename = Trim(arg_objfilename) IF Pos(arg_objfilename, ":\") <= 0 THEN a_msg = "必须输入完整的目标文件文件路径." relt = 0 GOTO ext END IF ZIPObject.ZipFileName = arg_objfilename ZIPObject.UpdatingZip = False // ensures a new zip is created IF UpperBound(fpath) = 0 THEN a_msg = "无压缩文件列表." relt = 0 GOTO ext END IF FOR ls_i = 1 To UpperBound(fpath) ZIPObject.AddFile(fpath[ls_i]) NEXT IF ZIPObject.MakeZipFile() <> 0 THEN relt = 0 a_msg = "压缩文件失败>"+ZIPObject.GetLastMessage GOTO ext1 END IF GOTO ext ext1: /////////////// // if FileExists("c:\upload.tmp") then filedelete("c:\upload.tmp") String str_source, str_des,filename_d,filename_c ULong ulng_result str_source = fpath[1] //源文件 filename_d=Reverse(left(Reverse(str_source),pos(Reverse(str_source),"\") - 1 )) filename_c="c:\" + filename_d if FileExists(filename_c) then filedelete(filename_c) str_des = filename_c //目标文件 ulng_result = CopyFile(str_source,str_des, 0) //IF ulng_result <> 0 THEN // MessageBox("OK","拷贝文件成功!") //END IF Destroy ZIPObject ZIPObject = Create OLEObject ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGZipfiles") ZIPObject.ZipFileName="c:\upload.tmp" ZIPObject.AddFile(filename_c) IF ZIPObject.MakeZipFile() <> 0 THEN relt = 0 a_msg = "压缩文件失败2>"+ZIPObject.GetLastMessage GOTO ext END IF filedelete(filename_c) CopyFile("c:\upload.tmp",arg_objfilename, 0) a_msg="" relt = 1 //////////////// // ext: //IF a_msg <> "" THEN // MessageBox("",a_msg) //END IF Destroy ZIPObject RETURN relt end function private function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg);//pf_writetifofile integer li_FileNum,rslt=1,ls_jh li_FileNum = FileOpen( arg_objfilename,StreamMode!, Write!, LockWrite!, Replace!) if li_FileNum<=0 then arg_msg="打开文件"+infofilename+"失败" rslt=0 fileclose(li_FileNum) goto ext end if ls_jh=FileWrite(li_FileNum, arg_tableinfo) if ls_jh<=0 then arg_msg="写文件"+infofilename+"失败" rslt=0 fileclose(li_FileNum) goto ext end if fileclose(li_FileNum) ext: return rslt end function private function string pf_readtifofile (string arg_objfilename, ref string arg_msg);//pf_readtifofile(arg_objfilename,arg_msg) integer li_FileNum,rslt=1,ls_jh long ll_FLength string str_objstr="" ll_FLength = FileLength(arg_objfilename) li_FileNum = FileOpen( arg_objfilename,StreamMode!) if li_FileNum<=0 then arg_msg="打开文件"+infofilename+"失败" rslt=0 fileclose(li_FileNum) goto ext end if if not ll_FLength<32767 then arg_msg="读文件"+infofilename+"失败,文件超长" rslt=0 fileclose(li_FileNum) goto ext end if ls_jh=Fileread(li_FileNum, str_objstr) if ls_jh<=0 then arg_msg="读文件"+infofilename+"失败" rslt=0 fileclose(li_FileNum) goto ext end if fileclose(li_FileNum) ext: if rslt=0 then str_objstr="" end if return str_objstr end function public function integer f_init_syscurpath (ref string arg_msg);//f_init_syscurpath(arg_msg) long rslt =1 string lpBuffer lpBuffer=Fill('',200) long lpfilepart,li_FileNum security_attributes ls_security_attributes rslt=GetFullPathName(sys_inifilename,196,lpBuffer,lpFilePart) if rslt=0 then arg_msg="提取当前路径失败,可能是因为系统INI文件丢失!" goto ext else sys_cur_path=left(lpBuffer,len(lpBuffer)-len(sys_inifilename)) end if //尝试建立临时目录 li_FileNum = CreateDirectory(sys_cur_path+updatexepath,ls_security_attributes) li_FileNum = CreateDirectory(sys_cur_path+fjfilepath,ls_security_attributes) ext: return rslt end function public function integer f_trycreate_sys_autoudexe (transaction arg_transaction, ref string arg_msg);//f_trycreate_sys_autoudexe long rslt=1 boolean if_need_createnew=false long cnt string createsql_string,t_str,dropsql_string createsql_string="CREATE TABLE sys_autoudexe ( filename char (100) NOT NULL PRIMARY KEY , buildtime datetime NOT NULL , filesit char (30) NOT NULL DEFAULT (''), needreg tinyint NOT NULL DEFAULT (0),needrun tinyint NOT NULL DEFAULT (0), filedata image NOT NULL DEFAULT '' , uploadtime datetime NOT NULL DEFAULT (getdate()), dscrp varchar (100) NOT NULL DEFAULT ('') )" t_str="select count(*) from sys_autoudexe" dropsql_string="DROP TABLE sys_autoudexe" long ls_isnullable Execute immediate :t_str using arg_transaction; if arg_transaction.sqlcode=0 then //已经存在该表 ///////////////检查表的本版,如果是旧的,删除重建 SELECT top 1 c.isnullable into :ls_isnullable FROM sysobjects o INNER JOIN syscolumns c ON o.id = c.id WHERE (o.name = 'sys_autoudexe') AND (c.name = 'filedata') using arg_transaction; if arg_transaction.sqlcode=0 then if ls_isnullable=1 then Execute immediate :dropsql_string using arg_transaction; if arg_transaction.sqlcode<>0 then arg_msg='删除表sys_autoudexe失败>>'+arg_transaction.sqlerrtext rollback using arg_transaction; rslt=0 goto ext end if commit using arg_transaction; if_need_createnew=true end if else arg_msg='检查filedada字段默认值失败>'+arg_transaction.sqlerrtext rslt=0 goto ext end if /////////////// else if_need_createnew=true end if if if_need_createnew then Execute immediate :createsql_string using arg_transaction; if arg_transaction.sqlcode<>0 then arg_msg='建立表sys_autoudexe失败>>'+arg_transaction.sqlerrtext rollback using arg_transaction; rslt=0 goto ext end if commit using arg_transaction; end if ext: return rslt end function public function integer f_del_uploadexe (transaction arg_transaction, string arg_filename, ref string arg_msg);//f_del_uploadexe(arg_transaction,arg_filename,arg_msg) long rslt=1 if isnull(arg_filename) or arg_filename="" then rslt=0 arg_msg='无效文件标识!' goto ext end if DELETE FROM sys_autoudexe WHERE sys_autoudexe.filename = :arg_filename using arg_transaction ; if arg_transaction.sqlcode<>0 then arg_msg='删除记录操作失败>'+arg_transaction.sqlerrtext rslt=0 rollback using arg_transaction; goto ext end if commit using arg_transaction; ext: return rslt end function public function datetime pf_getfilecreatetime (string arg_filefullpathname);//pf_getfilecreatetime long rslt datetime createtime,errdatetime date ls_date time ls_time systemtime ls_systemtime filetime lpCreationTime ,lpLastAccessTime ,lpLastWriteTime long li_FileNum // li_FileNum = lOpen(arg_filefullpathname,0) rslt = GetFileTime (li_FileNum ,lpCreationTime ,lpLastAccessTime ,lpLastWriteTime ) li_FileNum=lclose(li_FileNum) if rslt=0 then return errdatetime //rslt=FileTimeToSystemTime(lpCreationTime,ls_systemtime)// rslt=FileTimeToSystemTime(lpLastWriteTime,ls_systemtime) if rslt=0 then return errdatetime ls_date=date(string(ls_systemtime.wYear)+'.'+& string(ls_systemtime.wmonth)+'.'+& string(ls_systemtime.wDay)) ls_time=time(string(ls_systemtime.wHour)+':'+& string(ls_systemtime.wMinute )+':'+& string(ls_systemtime.wSecond )) createtime =datetime(ls_date,ls_time) return createtime end function public function integer f_autoupdateexe (ref transaction arg_transaction, ref string arg_msg);//f_autoupdateexe(arg_transaction,arg_msg) // //取得临时文件路径 //提取文件包记录 // 循环>> // 比较建立时间 // 是比较新则提取数据包 // 解包新程序文件到临时目录 // 记录文件路径名称 // << //写信息到系统INI给文件复制程序 //调用文件复制程序 //halt IF Not Trim(f_ProfileString (sys_empid,'program','autoupdate','1')) = '1' THEN RETURN 1 Long rslt = 1,prslt = 1 sys_autoudexe_info a_autoudexe_info[] Long count = 0,ls_i,download_count = 0,needdownfile_count = 0,needdownfile_sizetount = 0 String cur_path,tmpfilepathname,orifilefullpathname Blob b_dtdata, b_dtdata_p String needcopyfilelist = '',needrunfilelist = '' arg_msg = '' SetNull(b_dtdata) String str_buffer,WindowsDirectory,SystemDirectory str_buffer = Fill('',200) Long nsize Boolean ifneeddownfile = False,needcomptime = False //md5.ConnectToNewObject ("mymd5.Class1") cur_path = sys_cur_path Int li_force_update,li_allow_update SELECT allow_update INTO :li_allow_update From sys_msg Using arg_transaction; IF arg_transaction.SQLCode <> 0 THEN li_force_update = 0 li_allow_update = 0 END IF IF li_allow_update = 0 THEN RETURN 1 tmpfilepathname = cur_path+updatexepath+'\'+tmpzipupdatexefilename nsize = GetWindowsDirectory(str_buffer,198) WindowsDirectory = Left(str_buffer,nsize) nsize = GetSystemDirectory(str_buffer,198) SystemDirectory = Left(str_buffer,nsize) needcomptime = Trim(f_ProfileString (sys_empid,'program','comptime','0')) = '0' //0-是比较不同就更新,1-比较修改时间前后 Open(w_sys_wait_jdt) //初始化进度条 w_sys_wait_jdt.Show() w_sys_wait_jdt.wf_accepttol(1) w_sys_wait_jdt.wf_inc(0) w_sys_wait_jdt.st_msg.Text = "正在读取更新程序文件列表..." //游标查询新文件列表信息 // sys_autoudexe.md5 DECLARE user_cur CURSOR FOR SELECT sys_autoudexe.filename, sys_autoudexe.buildtime, sys_autoudexe.filesit, sys_autoudexe.needreg, sys_autoudexe.needrun, sys_autoudexe.dscrp, DATALENGTH(sys_autoudexe.fileData) as dt_size FROM sys_autoudexe USING arg_transaction ; count++ OPEN user_cur; FETCH user_cur Into :a_autoudexe_info[count].Filename,:a_autoudexe_info[count].buildtime,:a_autoudexe_info[count].filesit,:a_autoudexe_info[count].needreg,:a_autoudexe_info[count].needrun,:a_autoudexe_info[count].dscrp,:a_autoudexe_info[count].dt_size ; DO WHILE arg_transaction.SQLCode = 0 count++ FETCH user_cur Into :a_autoudexe_info[count].Filename,:a_autoudexe_info[count].buildtime,:a_autoudexe_info[count].filesit,:a_autoudexe_info[count].needreg,:a_autoudexe_info[count].needrun,:a_autoudexe_info[count].dscrp,:a_autoudexe_info[count].dt_size ; LOOP w_sys_wait_jdt.wf_inc(1) count = count - 1 CLOSE user_cur ; IF count = 0 THEN //没有更新文件列表 rslt = 1 GOTO ext END IF FOR ls_i = 1 To count //读取本地文件的建立时间,统计要下载的文件数 IF a_autoudexe_info[ls_i].dt_size > 0 THEN IF Lower(a_autoudexe_info[ls_i].filesit) = '[windows]' THEN orifilefullpathname = WindowsDirectory+'\'+a_autoudexe_info[ls_i].Filename ELSEIF Lower(a_autoudexe_info[ls_i].filesit) = '[windows\system]' THEN orifilefullpathname = SystemDirectory+'\'+a_autoudexe_info[ls_i].Filename ELSEIF Lower(a_autoudexe_info[ls_i].filesit) = '[默认]' THEN orifilefullpathname = cur_path+a_autoudexe_info[ls_i].Filename ELSE orifilefullpathname = cur_path+a_autoudexe_info[ls_i].Filename END IF a_autoudexe_info[ls_i].local_buildtime = pf_getfilecreatetime( orifilefullpathname) // IF FileExists(orifilefullpathname) THEN // a_autoudexe_info[ls_i].local_md5 = String(md5.getMd5(orifilefullpathname)) // END IF // // IF needcomptime THEN ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime < a_autoudexe_info[ls_i].buildtime // ifneeddownfile = a_autoudexe_info[ls_i].local_md5 <> a_autoudexe_info[ls_i].md5 ELSE ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime <> a_autoudexe_info[ls_i].buildtime END IF IF ifneeddownfile THEN needdownfile_count++ IF ifneeddownfile THEN needdownfile_sizetount = needdownfile_sizetount+a_autoudexe_info[ls_i].dt_size END IF NEXT w_sys_wait_jdt.Hide() IF needdownfile_count > 0 And needdownfile_sizetount > 0 THEN // IF MessageBox('询问','服务器上发现新版本的程序(共'+String(needdownfile_sizetount/1024,'#,##0.0')+'KB),是否自动更新本地程序?',Question!,YesNo! ,1) = 2 THEN // rslt = 0 // GOTO ext // END IF MessageBox('系统提示','服务器上发现新版本的程序(共'+String(needdownfile_sizetount/1024,'#,##0.0')+'KB),系统将马上更新') ELSE rslt = 1 GOTO ext END IF w_sys_wait_jdt.Show() w_sys_wait_jdt.wf_accepttol(count) w_sys_wait_jdt.wf_inc(0.5) FOR ls_i = 1 To count //下载文件并解压到临时目录 w_sys_wait_jdt.st_msg.Text = "正在下载文件"+a_autoudexe_info[ls_i].Filename+",请等候..." IF needcomptime THEN ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime < a_autoudexe_info[ls_i].buildtime // ifneeddownfile =a_autoudexe_info[ls_i].local_md5 <> a_autoudexe_info[ls_i].md5 ELSE ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime <> a_autoudexe_info[ls_i].buildtime END IF IF ifneeddownfile THEN prslt = pf_downloadexe(arg_transaction,a_autoudexe_info[ls_i].Filename,arg_msg) IF prslt = 1 THEN download_count++ needcopyfilelist = needcopyfilelist+a_autoudexe_info[ls_i].Filename+',' f_SetProfileString (sys_empid,String(Today())+String(Now(),' h:mm'),a_autoudexe_info[ls_i].Filename, "Download Succeed") ELSE f_SetProfileString (sys_empid,String(Today())+String(Now(),' h:mm'),a_autoudexe_info[ls_i].Filename, "ERR"+arg_msg) END IF ELSE END IF IF a_autoudexe_info[ls_i].needrun = 1 THEN needrunfilelist = needrunfilelist+a_autoudexe_info[ls_i].Filename+',' END IF RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'filesit', RegString!, String(a_autoudexe_info[ls_i].filesit)) RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'needreg', RegString!, String(a_autoudexe_info[ls_i].needreg)) RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'needrun', RegString!, String(a_autoudexe_info[ls_i].needrun)) w_sys_wait_jdt.wf_inc(ls_i) NEXT IF download_count = 0 THEN //没有要更新的文件 rslt = 1 GOTO ext END IF RegistrySet( winregtmp, 'needrunfilelist', RegString!, needrunfilelist) RegistrySet( winregtmp, 'needcopyfilelist', RegString!, needcopyfilelist) MessageBox('提示','服务器上发现新版本程序,系统将自动更新,等待2秒后,主程序将自动重新运行!', Information!, OK! ) Run('atudexe9.exe -autoupdateexe') HALT ext: //Destroy ll_reghelper Close(w_sys_wait_jdt) RETURN rslt end function public function integer pf_downloadexe (ref transaction arg_transaction, string arg_filename, ref string arg_msg);//pf_downloadexe(arg_transaction,arg_filename,arg_msg) //提取数据包 // 解包新程序文件到临时目录 long rslt=1,fend,fend_t string cur_path,tmpfilepathname blob b_dtdata, b_dtdata_p int li_FileNum,ls_i,ls_jh arg_msg='' setnull(b_dtdata) cur_path=sys_cur_path tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename if FileExists(tmpfilepathname) then filedelete(tmpfilepathname) //提取数据包 SELECTBLOB filedata INTO :b_dtdata FROM sys_autoudexe WHERE sys_autoudexe.filename = :arg_filename USING arg_transaction ; if arg_transaction.sqlcode<>0 then rslt=0 arg_msg='提取数据包操作失败>'+arg_transaction.sqlerrtext goto ext end if if len(b_dtdata)<1 or isnull(b_dtdata) then rslt=1 arg_msg='空数据包!' goto ext end if ////写临时文件 fend=len(b_dtdata) if fend<=32765 then fend_t=1 else fend_t=fend/32765 if mod(fend,32765)<>0 then fend_t=fend_t+1 end if end if li_FileNum = FileOpen( tmpfilepathname,StreamMode!, Write!, LockWrite!) if li_FileNum<=0 then arg_msg="打开文件"+tmpfilepathname+"失败" rslt=0 fileclose(li_FileNum) goto ext end if for ls_i = 1 to fend_t b_dtdata_p=blobmid(b_dtdata,1+(ls_i - 1 )*32765,32765) ls_jh=FileWrite(li_FileNum, b_dtdata_p) if ls_jh<=0 then arg_msg="写文件"+tmpfilepathname+"失败" rslt=0 fileclose(li_FileNum) goto ext end if next fileclose(li_FileNum) //解压数据文件 rslt=uf_unzipfile(tmpfilepathname,cur_path+updatexepath,arg_msg) if rslt=0 then arg_msg="解压缩>>"+arg_msg goto ext end if ext: if FileExists(tmpfilepathname) then filedelete(tmpfilepathname) return rslt end function public function integer f_uploadexe (ref transaction arg_transaction, string arg_objfilename, string arg_filesit, integer arg_needreg, integer arg_needrun, string arg_dscrp, ref string arg_msg);//f_uploadexe(arg_transaction,arg_objfilename,arg_filesit,arg_needreg,arg_needrun,arg_dscrp,arg_msg) //生成临时文件名称 //判断参数正确性 //连接COM对象 //压缩目标文件 //插入新记录 long rslt=1,ll_status OLEObject blobcolumnupdateObject string zipfilename[] string tmpfilepathname string cur_path,filename integer li_FileNum,ls_zip_i=0 filetime lpCreationTime,lpLastAccessTime,lpLastWriteTime datetime buildtime string ls_md5 cur_path=sys_cur_path tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename arg_filesit=trim(arg_filesit) //[windows] [默认] [windows\system] arg_dscrp=trim(arg_dscrp) if isnull(arg_dscrp) then arg_dscrp='' arg_objfilename=trim(arg_objfilename) if isnull(arg_objfilename) or trim(arg_objfilename)='' then rslt=0 arg_msg='非有效文件路径' goto ext end if if not FileExists(arg_objfilename) then rslt=0 arg_msg='目标文件不存在' goto ext end if filename=Reverse(left(Reverse(arg_objfilename),pos(Reverse(arg_objfilename),"\") - 1 )) if isnull(filename) or trim(filename)='' then rslt=0 arg_msg='非有效文件名称' goto ext end if buildtime=pf_getfilecreatetime(arg_objfilename) //ls_md5=string(md5.getMd5(arg_objfilename)) SetPointer(HourGlass!) if FileExists(tmpfilepathname) then filedelete(tmpfilepathname) // 压缩文件 ls_zip_i++ zipfilename[ls_zip_i]=arg_objfilename rslt=uf_zipfile(zipfilename,tmpfilepathname,arg_msg) if rslt=0 then arg_msg="文件压缩失败>>"+arg_msg +tmpfilepathname goto ext end if INSERT INTO sys_autoudexe ( filename, buildtime, filesit, needreg, needrun, uploadtime, md5, dscrp ) VALUES ( :filename, :buildtime, :arg_filesit, :arg_needreg, :arg_needrun, getdate(), :ls_md5, :arg_dscrp ) using arg_transaction ; if arg_transaction.sqlcode<>0 then rslt=0 arg_msg='插入新数据传送记录失败>'+arg_transaction.sqlerrtext rollback using arg_transaction; goto ext end if commit using arg_transaction; //if not blobcolumnupdateObject.WriteFileDataToBLOB(arg_msg,'sys_autoudexe', 'filedata', tmpfilepathname , "(filename = '"+filename+"')") then // rslt=0 // arg_msg='写入数据包操作失败>>'+arg_msg // goto ext //end if // //connect using arg_transaction; //读入数据 long flen,loops,ls_i,bytes_read,new_pos blob b_dtdata_p,tot_b flen = FileLength(tmpfilepathname) li_FileNum = FileOpen(tmpfilepathname, StreamMode!, Read!, LockRead!) if li_FileNum=-1 then rslt=0 arg_msg='打开文件'+tmpfilepathname+'操作失败!' fileclose(li_FileNum) goto ext end if IF flen > 32765 THEN IF Mod(flen, 32765) = 0 THEN loops = flen/32765 ELSE loops = (flen/32765) + 1 END IF ELSE loops = 1 END IF new_pos = 1 FOR ls_i = 1 to loops bytes_read = FileRead(li_FileNum, b_dtdata_p) if bytes_read=0 then rslt=0 arg_msg='读取文件'+tmpfilepathname+'操作失败!' fileclose(li_FileNum) goto ext end if tot_b = tot_b + b_dtdata_p NEXT fileclose(li_FileNum) ///////////////////////// //用updateblob Updateblob sys_autoudexe set filedata =:tot_b where (filename = :filename) using arg_transaction; if arg_transaction.sqlcode<>0 then arg_msg='保存文件包失败>'+arg_transaction.sqlerrtext rollback; delete sys_autoudexe where filename=:filename using arg_transaction; if arg_transaction.sqlcode<>0 then rollback using arg_transaction; else commit using arg_transaction; end if rslt=0 goto ext else commit using arg_transaction; end if //////////////// ext: if FileExists(tmpfilepathname) then filedelete(tmpfilepathname) DESTROY blobcolumnupdateObject return rslt end function public function integer f_istlnewfile ();//f_istlnewfile if pos(CommandParm(),'autoupdateexe')=0 then halt if not trim(f_ProfileString (sys_empid,'program','autoupdate','1'))='1' then halt int rslt=1 string needrunfilelist,needcopyfilelist string tmp_needrunfilelist,tmp_needcopyfilelist string needcopyfile[],needrunfile[] string copysur,copyobj string cur_path string objpathflag string str_tmp='' cur_path=sys_cur_path //tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename Sleep(2000) string str_buffer,WindowsDirectory,SystemDirectory str_buffer=fill('',200) long nsize int ls_i=0,ls_j=0,ls_k=0 nsize=GetWindowsDirectory(str_buffer,198) WindowsDirectory=left(str_buffer,nsize) nsize=GetSystemDirectory(str_buffer,198) SystemDirectory=left(str_buffer,nsize) rslt=RegistryGet( winregtmp, 'needrunfilelist', RegString!, needrunfilelist) rslt=RegistryGet( winregtmp, 'needcopyfilelist', RegString!, needcopyfilelist) //needrunfilelist=trim(f_ProfileString (sys_empid,updatexelogfilename,'needrunfilelist','')) //needcopyfilelist=trim(f_ProfileString (sys_empid,updatexelogfilename,'needcopyfilelist','')) needrunfilelist=trim(needrunfilelist) needcopyfilelist=trim(needcopyfilelist) tmp_needrunfilelist=needrunfilelist tmp_needcopyfilelist=needcopyfilelist DO WHILE pos(tmp_needrunfilelist,',')>0 ls_i++ needrunfile[ls_i]=left(tmp_needrunfilelist,pos(tmp_needrunfilelist,',') - 1) tmp_needrunfilelist=mid(tmp_needrunfilelist,pos(tmp_needrunfilelist,',')+1) LOOP DO WHILE pos(tmp_needcopyfilelist,',')>0 ls_k++ needcopyfile[ls_k]=left(tmp_needcopyfilelist,pos(tmp_needcopyfilelist,',') - 1) tmp_needcopyfilelist=mid(tmp_needcopyfilelist,pos(tmp_needcopyfilelist,',')+1) LOOP for ls_j=1 to ls_k copysur=cur_path+updatexepath+'\'+needcopyfile[ls_j] rslt=RegistryGet( winregtmp, needcopyfile[ls_j]+'filesit', RegString!, str_tmp) if trim(str_tmp)='' then str_tmp='[默认]' // objpathflag=lower(trim(f_ProfileString (sys_empid,updatexelogfilename,needcopyfile[ls_j]+'filesit','[默认]'))) objpathflag=lower(str_tmp) if objpathflag='[windows]' then copyobj=WindowsDirectory+'\'+needcopyfile[ls_j] elseif objpathflag='[windows\system]' then copyobj=SystemDirectory+'\'+needcopyfile[ls_j] elseif objpathflag='[默认]' then copyobj=cur_path+needcopyfile[ls_j] else copyobj=cur_path+needcopyfile[ls_j] end if rslt=SetFileAttributes(copyobj,8*16) rslt=CopyFile(copysur,copyobj,0) if rslt<>0 then rslt=RegistryGet( winregtmp, needcopyfile[ls_j]+'needreg', RegString!, str_tmp) if trim(str_tmp)='' then str_tmp='0' if str_tmp='1' then // if trim(f_ProfileString (sys_empid,updatexelogfilename,needcopyfile[ls_j]+'needreg','0'))='1' then run("regsvr32 /s "+copyobj) end if filedelete(copysur) end if next for ls_j=1 to ls_i run(needrunfile[ls_j]) next halt return rslt end function public function integer uf_unzipfile (string arg_zipfilename, string arg_objfilepath, ref string a_msg);//uf_unzipfile(arg_zipfilename,arg_objfilepath,a_msg) Long ll_status = 0,ls_i = 0 OLEObject ZIPObject relt = 1 ZIPObject = Create OLEObject ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGUnzipFiles") IF ll_status < 0 THEN relt = 0 CHOOSE CASE ll_status CASE -1 a_msg = "Invalid Call: the argument is the Object property of a control" CASE -2 a_msg = "Class name not found" CASE -3 a_msg = "Object could not be created" CASE -4 a_msg = "Could not connect to object" CASE -9 a_msg = "Other error" END CHOOSE // GOTO ext END IF IF Not FileExists (arg_zipfilename) THEN a_msg = "UnZipFiles>>无效的文件名" relt = 0 GOTO ext END IF //If Pos( arg_objfilepath, ".") > 0 Then // a_msg= "UnZipFiles>> 无效的文件存放目录路径." // relt=0 // GoTo ext IF DirectoryExists( arg_objfilepath) = False THEN a_msg = "UnZipFiles>> 无效的文件存放目录路径." relt = 0 GOTO ext ELSEIF Pos( arg_objfilepath, ":") <= 0 THEN a_msg = "UnZipFiles>> 必须输入完整的目标文件存放目录路径." relt = 0 GOTO ext END IF try ZIPObject.ZipFileName = arg_zipfilename ZIPObject.ExtractDir = arg_objfilepath // Keep Directory Structure of Zip ZIPObject.HonorDirectories = False IF ZIPObject.Unzip() <> 0 THEN relt = 0 a_msg = "UnZip>> 无法解压文件 " + arg_zipfilename + " :" + ZIPObject.GetLastMessage // GOTO ext END IF Catch(runtimeerror err) if UnZipTo(arg_zipfilename,arg_objfilepath,false,"") then relt = 1 open(w_filemove) else relt = 0 a_msg = "UnZip>> wfZip18_DLL.dll无法解压文件 " + arg_zipfilename end if END TRY ext: Destroy ZIPObject RETURN relt end function on uo_atudexe.create call super::create TriggerEvent( this, "constructor" ) end on on uo_atudexe.destroy TriggerEvent( this, "destructor" ) call super::destroy end on event constructor;String arg_msg Int rslt ds_data = Create datastore // //ll_reghelper = Create uo_reghelper //md5 = Create oleobject //IF ll_reghelper.ConnectToNewObject("mymd5.Class1", sys_cur_path + "mymd5.dll", md5, arg_msg) <> 1 THEN // rslt = 0 // GOTO ext //END IF //RETURN //ext: //MessageBox("连接mymd5.dll时错误",arg_msg) //RETURN end event