uo_atudexe.sru 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. $PBExportHeader$uo_atudexe.sru
  2. forward
  3. global type uo_atudexe from nonvisualobject
  4. end type
  5. type sys_autoudexe_info from structure within uo_atudexe
  6. end type
  7. type filetime from structure within uo_atudexe
  8. end type
  9. type systemtime from structure within uo_atudexe
  10. end type
  11. end forward
  12. type sys_autoudexe_info from structure
  13. string filename
  14. datetime buildtime
  15. string filesit
  16. integer needreg
  17. integer needrun
  18. string dscrp
  19. long dt_size
  20. datetime local_buildtime
  21. string md5
  22. string local_md5
  23. end type
  24. type FILETIME from structure
  25. long dwLowDateTime
  26. long dwHighDateTime
  27. end type
  28. type SYSTEMTIME from structure
  29. integer wYear
  30. integer wMonth
  31. integer wDayOfWeek
  32. integer wDay
  33. integer wHour
  34. integer wMinute
  35. integer wSecond
  36. integer wMilliseconds
  37. end type
  38. global type uo_atudexe from nonvisualobject
  39. event ue_other ( )
  40. end type
  41. global uo_atudexe uo_atudexe
  42. type prototypes
  43. Function long GetFullPathName (String lpFileName ,Long nBufferLength,ref string lpBuffer,ref long lpFilePart) library "kernel32" ALIAS FOR "GetFullPathNameA;Ansi"
  44. Function long CreateDirectory (string lpNewDirectory ,ref SECURITY_ATTRIBUTES lpSecurityAttributes ) library "kernel32" Alias for "CreateDirectoryA;Ansi"
  45. Function long GetFileTime (Long hFile ,ref filetime lpCreationTime ,ref filetime lpLastAccessTime ,ref filetime lpLastWriteTime ) library "kernel32" Alias for "GetFileTime;Ansi"
  46. Function long lopen (string lpPathName , long iReadWrite ) library "kernel32" Alias for "_lopen;Ansi"
  47. Function long lclose (long hFile) library "kernel32" Alias for "_lclose"
  48. Function long FileTimeToSystemTime (ref FILETIME lpFileTime ,ref SYSTEMTIME lpSystemTime ) library "kernel32" Alias for "FileTimeToSystemTime;Ansi"
  49. Function long CopyFile (String lpExistingFileName , String lpNewFileName , long bFailIfExists ) library "kernel32" Alias for "CopyFileA;Ansi"
  50. Subroutine Sleep(ulong dwMilliseconds) LIBRARY "kernel32.dll"
  51. Function long GetWindowsDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetWindowsDirectoryA;Ansi"
  52. Function long GetSystemDirectory (ref string lpBuffer,long nSize) Library "kernel32" Alias for "GetSystemDirectoryA;Ansi"
  53. Function long SetFileAttributes (String lpFileName , long dwFileAttributes ) Library "kernel32" Alias for "SetFileAttributesA;Ansi"
  54. Function ULong CopyFile(Ref String lpExistingFileName,Ref String lpNewFileName,ULong bFailIfExists) Library "kernel32.dll" Alias FOR "CopyFileA;Ansi";
  55. function boolean UnZipTo(string strZipFileName,string strDirectoryPath,boolean IsKeepPaths,string strPassword) Library 'wfZip18_DLL.dll' alias for "UnZipTo;Ansi";
  56. end prototypes
  57. type variables
  58. //oleobject md5
  59. //uo_reghelper ll_reghelper
  60. private:
  61. DataStore FilterData,ds_data
  62. int relt=0
  63. string msg=""
  64. int i=0,j=0
  65. string importtempfilepath='importtmp'
  66. string exporttempfilepath='exporttmp'
  67. string exportlogpath='exportlog'
  68. string importlogpath='importlog'
  69. string inceptpath='inceptdata'
  70. string incepttmpfile='_inceptdata.tmp'
  71. string fjfilepath = 'fjtemp'
  72. string updatexepath='updatexetmp'
  73. string tmpzipupdatexefilename='upload.tmp'
  74. string updatexelogfilename='updatexe.log'
  75. string winregtmp='HKEY_LOCAL_MACHINE\Software\longjoetmp'
  76. blob blbdw_data
  77. string sys_changetime="sys_changetime"
  78. string sys_changeflag="sys_changeflag"
  79. string infofilename="_table_info.ifo" //传递的信息文件
  80. string dts_deletelog="dts_deletelog" //删除日志表
  81. end variables
  82. forward prototypes
  83. private function integer uf_zipfile (string fpath[], string arg_objfilename, ref string a_msg)
  84. private function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg)
  85. private function string pf_readtifofile (string arg_objfilename, ref string arg_msg)
  86. public function integer f_init_syscurpath (ref string arg_msg)
  87. public function integer f_trycreate_sys_autoudexe (transaction arg_transaction, ref string arg_msg)
  88. public function integer f_del_uploadexe (transaction arg_transaction, string arg_filename, ref string arg_msg)
  89. public function datetime pf_getfilecreatetime (string arg_filefullpathname)
  90. public function integer f_autoupdateexe (ref transaction arg_transaction, ref string arg_msg)
  91. public function integer pf_downloadexe (ref transaction arg_transaction, string arg_filename, ref string arg_msg)
  92. 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)
  93. public function integer f_istlnewfile ()
  94. public function integer uf_unzipfile (string arg_zipfilename, string arg_objfilepath, ref string a_msg)
  95. end prototypes
  96. event ue_other;/////////////Autoupdateexe begin in application's begin
  97. //uo_atudexe uo_ins_atudexe
  98. //uo_ins_atudexe=create uo_atudexe
  99. //
  100. //ls_rslt=uo_ins_atudexe.f_init_syscurpath(lls_str)
  101. //ls_rslt=uo_ins_atudexe.f_autoupdateexe(sqlca,lls_str)
  102. //
  103. //destroy uo_ins_atudexe
  104. //////////////Autoupdateexe end
  105. //
  106. end event
  107. private function integer uf_zipfile (string fpath[], string arg_objfilename, ref string a_msg);//uf_zipfile(fpath[],arg_objfilename,a_msg)
  108. Long ll_status = 0,ls_i = 0
  109. OLEObject ZIPObject
  110. relt = 1
  111. ZIPObject = Create OLEObject
  112. ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGZipfiles")
  113. IF ll_status < 0 THEN
  114. relt = 0
  115. CHOOSE CASE ll_status
  116. CASE -1
  117. a_msg = "Invalid Call: the argument is the Object property of a control"
  118. CASE -2
  119. a_msg = "Class name not found"
  120. CASE -3
  121. a_msg = "Object could not be created"
  122. CASE -4
  123. a_msg = "Could not connect to object"
  124. CASE -9
  125. a_msg = "Other error"
  126. END CHOOSE
  127. GOTO ext
  128. END IF
  129. arg_objfilename = Trim(arg_objfilename)
  130. IF Pos(arg_objfilename, ":\") <= 0 THEN
  131. a_msg = "必须输入完整的目标文件文件路径."
  132. relt = 0
  133. GOTO ext
  134. END IF
  135. ZIPObject.ZipFileName = arg_objfilename
  136. ZIPObject.UpdatingZip = False // ensures a new zip is created
  137. IF UpperBound(fpath) = 0 THEN
  138. a_msg = "无压缩文件列表."
  139. relt = 0
  140. GOTO ext
  141. END IF
  142. FOR ls_i = 1 To UpperBound(fpath)
  143. ZIPObject.AddFile(fpath[ls_i])
  144. NEXT
  145. IF ZIPObject.MakeZipFile() <> 0 THEN
  146. relt = 0
  147. a_msg = "压缩文件失败>"+ZIPObject.GetLastMessage
  148. GOTO ext1
  149. END IF
  150. GOTO ext
  151. ext1:
  152. /////////////// //
  153. if FileExists("c:\upload.tmp") then filedelete("c:\upload.tmp")
  154. String str_source, str_des,filename_d,filename_c
  155. ULong ulng_result
  156. str_source = fpath[1] //源文件
  157. filename_d=Reverse(left(Reverse(str_source),pos(Reverse(str_source),"\") - 1 ))
  158. filename_c="c:\" + filename_d
  159. if FileExists(filename_c) then filedelete(filename_c)
  160. str_des = filename_c //目标文件
  161. ulng_result = CopyFile(str_source,str_des, 0)
  162. //IF ulng_result <> 0 THEN
  163. // MessageBox("OK","拷贝文件成功!")
  164. //END IF
  165. Destroy ZIPObject
  166. ZIPObject = Create OLEObject
  167. ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGZipfiles")
  168. ZIPObject.ZipFileName="c:\upload.tmp"
  169. ZIPObject.AddFile(filename_c)
  170. IF ZIPObject.MakeZipFile() <> 0 THEN
  171. relt = 0
  172. a_msg = "压缩文件失败2>"+ZIPObject.GetLastMessage
  173. GOTO ext
  174. END IF
  175. filedelete(filename_c)
  176. CopyFile("c:\upload.tmp",arg_objfilename, 0)
  177. a_msg=""
  178. relt = 1
  179. //////////////// //
  180. ext:
  181. //IF a_msg <> "" THEN
  182. // MessageBox("",a_msg)
  183. //END IF
  184. Destroy ZIPObject
  185. RETURN relt
  186. end function
  187. private function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg);//pf_writetifofile
  188. integer li_FileNum,rslt=1,ls_jh
  189. li_FileNum = FileOpen( arg_objfilename,StreamMode!, Write!, LockWrite!, Replace!)
  190. if li_FileNum<=0 then
  191. arg_msg="打开文件"+infofilename+"失败"
  192. rslt=0
  193. fileclose(li_FileNum)
  194. goto ext
  195. end if
  196. ls_jh=FileWrite(li_FileNum, arg_tableinfo)
  197. if ls_jh<=0 then
  198. arg_msg="写文件"+infofilename+"失败"
  199. rslt=0
  200. fileclose(li_FileNum)
  201. goto ext
  202. end if
  203. fileclose(li_FileNum)
  204. ext:
  205. return rslt
  206. end function
  207. private function string pf_readtifofile (string arg_objfilename, ref string arg_msg);//pf_readtifofile(arg_objfilename,arg_msg)
  208. integer li_FileNum,rslt=1,ls_jh
  209. long ll_FLength
  210. string str_objstr=""
  211. ll_FLength = FileLength(arg_objfilename)
  212. li_FileNum = FileOpen( arg_objfilename,StreamMode!)
  213. if li_FileNum<=0 then
  214. arg_msg="打开文件"+infofilename+"失败"
  215. rslt=0
  216. fileclose(li_FileNum)
  217. goto ext
  218. end if
  219. if not ll_FLength<32767 then
  220. arg_msg="读文件"+infofilename+"失败,文件超长"
  221. rslt=0
  222. fileclose(li_FileNum)
  223. goto ext
  224. end if
  225. ls_jh=Fileread(li_FileNum, str_objstr)
  226. if ls_jh<=0 then
  227. arg_msg="读文件"+infofilename+"失败"
  228. rslt=0
  229. fileclose(li_FileNum)
  230. goto ext
  231. end if
  232. fileclose(li_FileNum)
  233. ext:
  234. if rslt=0 then
  235. str_objstr=""
  236. end if
  237. return str_objstr
  238. end function
  239. public function integer f_init_syscurpath (ref string arg_msg);//f_init_syscurpath(arg_msg)
  240. long rslt =1
  241. string lpBuffer
  242. lpBuffer=Fill('',200)
  243. long lpfilepart,li_FileNum
  244. security_attributes ls_security_attributes
  245. rslt=GetFullPathName(sys_inifilename,196,lpBuffer,lpFilePart)
  246. if rslt=0 then
  247. arg_msg="提取当前路径失败,可能是因为系统INI文件丢失!"
  248. goto ext
  249. else
  250. sys_cur_path=left(lpBuffer,len(lpBuffer)-len(sys_inifilename))
  251. end if
  252. //尝试建立临时目录
  253. li_FileNum = CreateDirectory(sys_cur_path+updatexepath,ls_security_attributes)
  254. li_FileNum = CreateDirectory(sys_cur_path+fjfilepath,ls_security_attributes)
  255. ext:
  256. return rslt
  257. end function
  258. public function integer f_trycreate_sys_autoudexe (transaction arg_transaction, ref string arg_msg);//f_trycreate_sys_autoudexe
  259. long rslt=1
  260. boolean if_need_createnew=false
  261. long cnt
  262. string createsql_string,t_str,dropsql_string
  263. 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 ('') )"
  264. t_str="select count(*) from sys_autoudexe"
  265. dropsql_string="DROP TABLE sys_autoudexe"
  266. long ls_isnullable
  267. Execute immediate :t_str using arg_transaction;
  268. if arg_transaction.sqlcode=0 then //已经存在该表
  269. ///////////////检查表的本版,如果是旧的,删除重建
  270. SELECT top 1 c.isnullable into :ls_isnullable
  271. FROM sysobjects o INNER JOIN
  272. syscolumns c ON o.id = c.id
  273. WHERE (o.name = 'sys_autoudexe') AND (c.name = 'filedata') using arg_transaction;
  274. if arg_transaction.sqlcode=0 then
  275. if ls_isnullable=1 then
  276. Execute immediate :dropsql_string using arg_transaction;
  277. if arg_transaction.sqlcode<>0 then
  278. arg_msg='删除表sys_autoudexe失败>>'+arg_transaction.sqlerrtext
  279. rollback using arg_transaction;
  280. rslt=0
  281. goto ext
  282. end if
  283. commit using arg_transaction;
  284. if_need_createnew=true
  285. end if
  286. else
  287. arg_msg='检查filedada字段默认值失败>'+arg_transaction.sqlerrtext
  288. rslt=0
  289. goto ext
  290. end if
  291. ///////////////
  292. else
  293. if_need_createnew=true
  294. end if
  295. if if_need_createnew then
  296. Execute immediate :createsql_string using arg_transaction;
  297. if arg_transaction.sqlcode<>0 then
  298. arg_msg='建立表sys_autoudexe失败>>'+arg_transaction.sqlerrtext
  299. rollback using arg_transaction;
  300. rslt=0
  301. goto ext
  302. end if
  303. commit using arg_transaction;
  304. end if
  305. ext:
  306. return rslt
  307. end function
  308. 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)
  309. long rslt=1
  310. if isnull(arg_filename) or arg_filename="" then
  311. rslt=0
  312. arg_msg='无效文件标识!'
  313. goto ext
  314. end if
  315. DELETE FROM sys_autoudexe
  316. WHERE sys_autoudexe.filename = :arg_filename
  317. using arg_transaction ;
  318. if arg_transaction.sqlcode<>0 then
  319. arg_msg='删除记录操作失败>'+arg_transaction.sqlerrtext
  320. rslt=0
  321. rollback using arg_transaction;
  322. goto ext
  323. end if
  324. commit using arg_transaction;
  325. ext:
  326. return rslt
  327. end function
  328. public function datetime pf_getfilecreatetime (string arg_filefullpathname);//pf_getfilecreatetime
  329. long rslt
  330. datetime createtime,errdatetime
  331. date ls_date
  332. time ls_time
  333. systemtime ls_systemtime
  334. filetime lpCreationTime ,lpLastAccessTime ,lpLastWriteTime
  335. long li_FileNum
  336. //
  337. li_FileNum = lOpen(arg_filefullpathname,0)
  338. rslt = GetFileTime (li_FileNum ,lpCreationTime ,lpLastAccessTime ,lpLastWriteTime )
  339. li_FileNum=lclose(li_FileNum)
  340. if rslt=0 then return errdatetime
  341. //rslt=FileTimeToSystemTime(lpCreationTime,ls_systemtime)//
  342. rslt=FileTimeToSystemTime(lpLastWriteTime,ls_systemtime)
  343. if rslt=0 then return errdatetime
  344. ls_date=date(string(ls_systemtime.wYear)+'.'+&
  345. string(ls_systemtime.wmonth)+'.'+&
  346. string(ls_systemtime.wDay))
  347. ls_time=time(string(ls_systemtime.wHour)+':'+&
  348. string(ls_systemtime.wMinute )+':'+&
  349. string(ls_systemtime.wSecond ))
  350. createtime =datetime(ls_date,ls_time)
  351. return createtime
  352. end function
  353. public function integer f_autoupdateexe (ref transaction arg_transaction, ref string arg_msg);//f_autoupdateexe(arg_transaction,arg_msg)
  354. //
  355. //取得临时文件路径
  356. //提取文件包记录
  357. // 循环>>
  358. // 比较建立时间
  359. // 是比较新则提取数据包
  360. // 解包新程序文件到临时目录
  361. // 记录文件路径名称
  362. // <<
  363. //写信息到系统INI给文件复制程序
  364. //调用文件复制程序
  365. //halt
  366. IF Not Trim(f_ProfileString (sys_empid,'program','autoupdate','1')) = '1' THEN RETURN 1
  367. Long rslt = 1,prslt = 1
  368. sys_autoudexe_info a_autoudexe_info[]
  369. Long count = 0,ls_i,download_count = 0,needdownfile_count = 0,needdownfile_sizetount = 0
  370. String cur_path,tmpfilepathname,orifilefullpathname
  371. Blob b_dtdata, b_dtdata_p
  372. String needcopyfilelist = '',needrunfilelist = ''
  373. arg_msg = ''
  374. SetNull(b_dtdata)
  375. String str_buffer,WindowsDirectory,SystemDirectory
  376. str_buffer = Fill('',200)
  377. Long nsize
  378. Boolean ifneeddownfile = False,needcomptime = False
  379. //md5.ConnectToNewObject ("mymd5.Class1")
  380. cur_path = sys_cur_path
  381. Int li_force_update,li_allow_update
  382. SELECT allow_update INTO :li_allow_update
  383. From sys_msg Using arg_transaction;
  384. IF arg_transaction.SQLCode <> 0 THEN
  385. li_force_update = 0
  386. li_allow_update = 0
  387. END IF
  388. IF li_allow_update = 0 THEN RETURN 1
  389. tmpfilepathname = cur_path+updatexepath+'\'+tmpzipupdatexefilename
  390. nsize = GetWindowsDirectory(str_buffer,198)
  391. WindowsDirectory = Left(str_buffer,nsize)
  392. nsize = GetSystemDirectory(str_buffer,198)
  393. SystemDirectory = Left(str_buffer,nsize)
  394. needcomptime = Trim(f_ProfileString (sys_empid,'program','comptime','0')) = '0' //0-是比较不同就更新,1-比较修改时间前后
  395. Open(w_sys_wait_jdt) //初始化进度条
  396. w_sys_wait_jdt.Show()
  397. w_sys_wait_jdt.wf_accepttol(1)
  398. w_sys_wait_jdt.wf_inc(0)
  399. w_sys_wait_jdt.st_msg.Text = "正在读取更新程序文件列表..."
  400. //游标查询新文件列表信息
  401. // sys_autoudexe.md5
  402. DECLARE user_cur CURSOR FOR
  403. SELECT sys_autoudexe.filename,
  404. sys_autoudexe.buildtime,
  405. sys_autoudexe.filesit,
  406. sys_autoudexe.needreg,
  407. sys_autoudexe.needrun,
  408. sys_autoudexe.dscrp,
  409. DATALENGTH(sys_autoudexe.fileData) as dt_size
  410. FROM sys_autoudexe USING arg_transaction
  411. ;
  412. count++
  413. OPEN user_cur;
  414. 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 ;
  415. DO WHILE arg_transaction.SQLCode = 0
  416. count++
  417. 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 ;
  418. LOOP
  419. w_sys_wait_jdt.wf_inc(1)
  420. count = count - 1
  421. CLOSE user_cur ;
  422. IF count = 0 THEN //没有更新文件列表
  423. rslt = 1
  424. GOTO ext
  425. END IF
  426. FOR ls_i = 1 To count //读取本地文件的建立时间,统计要下载的文件数
  427. IF a_autoudexe_info[ls_i].dt_size > 0 THEN
  428. IF Lower(a_autoudexe_info[ls_i].filesit) = '[windows]' THEN
  429. orifilefullpathname = WindowsDirectory+'\'+a_autoudexe_info[ls_i].Filename
  430. ELSEIF Lower(a_autoudexe_info[ls_i].filesit) = '[windows\system]' THEN
  431. orifilefullpathname = SystemDirectory+'\'+a_autoudexe_info[ls_i].Filename
  432. ELSEIF Lower(a_autoudexe_info[ls_i].filesit) = '[默认]' THEN
  433. orifilefullpathname = cur_path+a_autoudexe_info[ls_i].Filename
  434. ELSE
  435. orifilefullpathname = cur_path+a_autoudexe_info[ls_i].Filename
  436. END IF
  437. a_autoudexe_info[ls_i].local_buildtime = pf_getfilecreatetime( orifilefullpathname)
  438. // IF FileExists(orifilefullpathname) THEN
  439. // a_autoudexe_info[ls_i].local_md5 = String(md5.getMd5(orifilefullpathname))
  440. // END IF
  441. //
  442. //
  443. IF needcomptime THEN
  444. ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime < a_autoudexe_info[ls_i].buildtime
  445. // ifneeddownfile = a_autoudexe_info[ls_i].local_md5 <> a_autoudexe_info[ls_i].md5
  446. ELSE
  447. ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime <> a_autoudexe_info[ls_i].buildtime
  448. END IF
  449. IF ifneeddownfile THEN needdownfile_count++
  450. IF ifneeddownfile THEN needdownfile_sizetount = needdownfile_sizetount+a_autoudexe_info[ls_i].dt_size
  451. END IF
  452. NEXT
  453. w_sys_wait_jdt.Hide()
  454. IF needdownfile_count > 0 And needdownfile_sizetount > 0 THEN
  455. // IF MessageBox('询问','服务器上发现新版本的程序(共'+String(needdownfile_sizetount/1024,'#,##0.0')+'KB),是否自动更新本地程序?',Question!,YesNo! ,1) = 2 THEN
  456. // rslt = 0
  457. // GOTO ext
  458. // END IF
  459. MessageBox('系统提示','服务器上发现新版本的程序(共'+String(needdownfile_sizetount/1024,'#,##0.0')+'KB),系统将马上更新')
  460. ELSE
  461. rslt = 1
  462. GOTO ext
  463. END IF
  464. w_sys_wait_jdt.Show()
  465. w_sys_wait_jdt.wf_accepttol(count)
  466. w_sys_wait_jdt.wf_inc(0.5)
  467. FOR ls_i = 1 To count //下载文件并解压到临时目录
  468. w_sys_wait_jdt.st_msg.Text = "正在下载文件"+a_autoudexe_info[ls_i].Filename+",请等候..."
  469. IF needcomptime THEN
  470. ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime < a_autoudexe_info[ls_i].buildtime
  471. // ifneeddownfile =a_autoudexe_info[ls_i].local_md5 <> a_autoudexe_info[ls_i].md5
  472. ELSE
  473. ifneeddownfile = a_autoudexe_info[ls_i].local_buildtime <> a_autoudexe_info[ls_i].buildtime
  474. END IF
  475. IF ifneeddownfile THEN
  476. prslt = pf_downloadexe(arg_transaction,a_autoudexe_info[ls_i].Filename,arg_msg)
  477. IF prslt = 1 THEN
  478. download_count++
  479. needcopyfilelist = needcopyfilelist+a_autoudexe_info[ls_i].Filename+','
  480. f_SetProfileString (sys_empid,String(Today())+String(Now(),' h:mm'),a_autoudexe_info[ls_i].Filename, "Download Succeed")
  481. ELSE
  482. f_SetProfileString (sys_empid,String(Today())+String(Now(),' h:mm'),a_autoudexe_info[ls_i].Filename, "ERR"+arg_msg)
  483. END IF
  484. ELSE
  485. END IF
  486. IF a_autoudexe_info[ls_i].needrun = 1 THEN
  487. needrunfilelist = needrunfilelist+a_autoudexe_info[ls_i].Filename+','
  488. END IF
  489. RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'filesit', RegString!, String(a_autoudexe_info[ls_i].filesit))
  490. RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'needreg', RegString!, String(a_autoudexe_info[ls_i].needreg))
  491. RegistrySet( winregtmp, a_autoudexe_info[ls_i].Filename+'needrun', RegString!, String(a_autoudexe_info[ls_i].needrun))
  492. w_sys_wait_jdt.wf_inc(ls_i)
  493. NEXT
  494. IF download_count = 0 THEN //没有要更新的文件
  495. rslt = 1
  496. GOTO ext
  497. END IF
  498. RegistrySet( winregtmp, 'needrunfilelist', RegString!, needrunfilelist)
  499. RegistrySet( winregtmp, 'needcopyfilelist', RegString!, needcopyfilelist)
  500. MessageBox('提示','服务器上发现新版本程序,系统将自动更新,等待2秒后,主程序将自动重新运行!', Information!, OK! )
  501. Run('atudexe9.exe -autoupdateexe')
  502. HALT
  503. ext:
  504. //Destroy ll_reghelper
  505. Close(w_sys_wait_jdt)
  506. RETURN rslt
  507. end function
  508. public function integer pf_downloadexe (ref transaction arg_transaction, string arg_filename, ref string arg_msg);//pf_downloadexe(arg_transaction,arg_filename,arg_msg)
  509. //提取数据包
  510. // 解包新程序文件到临时目录
  511. long rslt=1,fend,fend_t
  512. string cur_path,tmpfilepathname
  513. blob b_dtdata, b_dtdata_p
  514. int li_FileNum,ls_i,ls_jh
  515. arg_msg=''
  516. setnull(b_dtdata)
  517. cur_path=sys_cur_path
  518. tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename
  519. if FileExists(tmpfilepathname) then filedelete(tmpfilepathname)
  520. //提取数据包
  521. SELECTBLOB filedata
  522. INTO :b_dtdata
  523. FROM sys_autoudexe
  524. WHERE sys_autoudexe.filename = :arg_filename
  525. USING arg_transaction ;
  526. if arg_transaction.sqlcode<>0 then
  527. rslt=0
  528. arg_msg='提取数据包操作失败>'+arg_transaction.sqlerrtext
  529. goto ext
  530. end if
  531. if len(b_dtdata)<1 or isnull(b_dtdata) then
  532. rslt=1
  533. arg_msg='空数据包!'
  534. goto ext
  535. end if
  536. ////写临时文件
  537. fend=len(b_dtdata)
  538. if fend<=32765 then
  539. fend_t=1
  540. else
  541. fend_t=fend/32765
  542. if mod(fend,32765)<>0 then
  543. fend_t=fend_t+1
  544. end if
  545. end if
  546. li_FileNum = FileOpen( tmpfilepathname,StreamMode!, Write!, LockWrite!)
  547. if li_FileNum<=0 then
  548. arg_msg="打开文件"+tmpfilepathname+"失败"
  549. rslt=0
  550. fileclose(li_FileNum)
  551. goto ext
  552. end if
  553. for ls_i = 1 to fend_t
  554. b_dtdata_p=blobmid(b_dtdata,1+(ls_i - 1 )*32765,32765)
  555. ls_jh=FileWrite(li_FileNum, b_dtdata_p)
  556. if ls_jh<=0 then
  557. arg_msg="写文件"+tmpfilepathname+"失败"
  558. rslt=0
  559. fileclose(li_FileNum)
  560. goto ext
  561. end if
  562. next
  563. fileclose(li_FileNum)
  564. //解压数据文件
  565. rslt=uf_unzipfile(tmpfilepathname,cur_path+updatexepath,arg_msg)
  566. if rslt=0 then
  567. arg_msg="解压缩>>"+arg_msg
  568. goto ext
  569. end if
  570. ext:
  571. if FileExists(tmpfilepathname) then filedelete(tmpfilepathname)
  572. return rslt
  573. end function
  574. 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)
  575. //生成临时文件名称
  576. //判断参数正确性
  577. //连接COM对象
  578. //压缩目标文件
  579. //插入新记录
  580. long rslt=1,ll_status
  581. OLEObject blobcolumnupdateObject
  582. string zipfilename[]
  583. string tmpfilepathname
  584. string cur_path,filename
  585. integer li_FileNum,ls_zip_i=0
  586. filetime lpCreationTime,lpLastAccessTime,lpLastWriteTime
  587. datetime buildtime
  588. string ls_md5
  589. cur_path=sys_cur_path
  590. tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename
  591. arg_filesit=trim(arg_filesit) //[windows] [默认] [windows\system]
  592. arg_dscrp=trim(arg_dscrp)
  593. if isnull(arg_dscrp) then arg_dscrp=''
  594. arg_objfilename=trim(arg_objfilename)
  595. if isnull(arg_objfilename) or trim(arg_objfilename)='' then
  596. rslt=0
  597. arg_msg='非有效文件路径'
  598. goto ext
  599. end if
  600. if not FileExists(arg_objfilename) then
  601. rslt=0
  602. arg_msg='目标文件不存在'
  603. goto ext
  604. end if
  605. filename=Reverse(left(Reverse(arg_objfilename),pos(Reverse(arg_objfilename),"\") - 1 ))
  606. if isnull(filename) or trim(filename)='' then
  607. rslt=0
  608. arg_msg='非有效文件名称'
  609. goto ext
  610. end if
  611. buildtime=pf_getfilecreatetime(arg_objfilename)
  612. //ls_md5=string(md5.getMd5(arg_objfilename))
  613. SetPointer(HourGlass!)
  614. if FileExists(tmpfilepathname) then filedelete(tmpfilepathname)
  615. // 压缩文件
  616. ls_zip_i++
  617. zipfilename[ls_zip_i]=arg_objfilename
  618. rslt=uf_zipfile(zipfilename,tmpfilepathname,arg_msg)
  619. if rslt=0 then
  620. arg_msg="文件压缩失败>>"+arg_msg +tmpfilepathname
  621. goto ext
  622. end if
  623. INSERT INTO sys_autoudexe
  624. ( filename,
  625. buildtime,
  626. filesit,
  627. needreg,
  628. needrun,
  629. uploadtime,
  630. md5,
  631. dscrp )
  632. VALUES ( :filename,
  633. :buildtime,
  634. :arg_filesit,
  635. :arg_needreg,
  636. :arg_needrun,
  637. getdate(),
  638. :ls_md5,
  639. :arg_dscrp )
  640. using arg_transaction ;
  641. if arg_transaction.sqlcode<>0 then
  642. rslt=0
  643. arg_msg='插入新数据传送记录失败>'+arg_transaction.sqlerrtext
  644. rollback using arg_transaction;
  645. goto ext
  646. end if
  647. commit using arg_transaction;
  648. //if not blobcolumnupdateObject.WriteFileDataToBLOB(arg_msg,'sys_autoudexe', 'filedata', tmpfilepathname , "(filename = '"+filename+"')") then
  649. // rslt=0
  650. // arg_msg='写入数据包操作失败>>'+arg_msg
  651. // goto ext
  652. //end if
  653. //
  654. //connect using arg_transaction;
  655. //读入数据
  656. long flen,loops,ls_i,bytes_read,new_pos
  657. blob b_dtdata_p,tot_b
  658. flen = FileLength(tmpfilepathname)
  659. li_FileNum = FileOpen(tmpfilepathname, StreamMode!, Read!, LockRead!)
  660. if li_FileNum=-1 then
  661. rslt=0
  662. arg_msg='打开文件'+tmpfilepathname+'操作失败!'
  663. fileclose(li_FileNum)
  664. goto ext
  665. end if
  666. IF flen > 32765 THEN
  667. IF Mod(flen, 32765) = 0 THEN
  668. loops = flen/32765
  669. ELSE
  670. loops = (flen/32765) + 1
  671. END IF
  672. ELSE
  673. loops = 1
  674. END IF
  675. new_pos = 1
  676. FOR ls_i = 1 to loops
  677. bytes_read = FileRead(li_FileNum, b_dtdata_p)
  678. if bytes_read=0 then
  679. rslt=0
  680. arg_msg='读取文件'+tmpfilepathname+'操作失败!'
  681. fileclose(li_FileNum)
  682. goto ext
  683. end if
  684. tot_b = tot_b + b_dtdata_p
  685. NEXT
  686. fileclose(li_FileNum)
  687. /////////////////////////
  688. //用updateblob
  689. Updateblob sys_autoudexe set filedata =:tot_b where (filename = :filename) using arg_transaction;
  690. if arg_transaction.sqlcode<>0 then
  691. arg_msg='保存文件包失败>'+arg_transaction.sqlerrtext
  692. rollback;
  693. delete sys_autoudexe
  694. where filename=:filename using arg_transaction;
  695. if arg_transaction.sqlcode<>0 then
  696. rollback using arg_transaction;
  697. else
  698. commit using arg_transaction;
  699. end if
  700. rslt=0
  701. goto ext
  702. else
  703. commit using arg_transaction;
  704. end if
  705. ////////////////
  706. ext:
  707. if FileExists(tmpfilepathname) then filedelete(tmpfilepathname)
  708. DESTROY blobcolumnupdateObject
  709. return rslt
  710. end function
  711. public function integer f_istlnewfile ();//f_istlnewfile
  712. if pos(CommandParm(),'autoupdateexe')=0 then halt
  713. if not trim(f_ProfileString (sys_empid,'program','autoupdate','1'))='1' then halt
  714. int rslt=1
  715. string needrunfilelist,needcopyfilelist
  716. string tmp_needrunfilelist,tmp_needcopyfilelist
  717. string needcopyfile[],needrunfile[]
  718. string copysur,copyobj
  719. string cur_path
  720. string objpathflag
  721. string str_tmp=''
  722. cur_path=sys_cur_path
  723. //tmpfilepathname=cur_path+updatexepath+'\'+tmpzipupdatexefilename
  724. Sleep(2000)
  725. string str_buffer,WindowsDirectory,SystemDirectory
  726. str_buffer=fill('',200)
  727. long nsize
  728. int ls_i=0,ls_j=0,ls_k=0
  729. nsize=GetWindowsDirectory(str_buffer,198)
  730. WindowsDirectory=left(str_buffer,nsize)
  731. nsize=GetSystemDirectory(str_buffer,198)
  732. SystemDirectory=left(str_buffer,nsize)
  733. rslt=RegistryGet( winregtmp, 'needrunfilelist', RegString!, needrunfilelist)
  734. rslt=RegistryGet( winregtmp, 'needcopyfilelist', RegString!, needcopyfilelist)
  735. //needrunfilelist=trim(f_ProfileString (sys_empid,updatexelogfilename,'needrunfilelist',''))
  736. //needcopyfilelist=trim(f_ProfileString (sys_empid,updatexelogfilename,'needcopyfilelist',''))
  737. needrunfilelist=trim(needrunfilelist)
  738. needcopyfilelist=trim(needcopyfilelist)
  739. tmp_needrunfilelist=needrunfilelist
  740. tmp_needcopyfilelist=needcopyfilelist
  741. DO WHILE pos(tmp_needrunfilelist,',')>0
  742. ls_i++
  743. needrunfile[ls_i]=left(tmp_needrunfilelist,pos(tmp_needrunfilelist,',') - 1)
  744. tmp_needrunfilelist=mid(tmp_needrunfilelist,pos(tmp_needrunfilelist,',')+1)
  745. LOOP
  746. DO WHILE pos(tmp_needcopyfilelist,',')>0
  747. ls_k++
  748. needcopyfile[ls_k]=left(tmp_needcopyfilelist,pos(tmp_needcopyfilelist,',') - 1)
  749. tmp_needcopyfilelist=mid(tmp_needcopyfilelist,pos(tmp_needcopyfilelist,',')+1)
  750. LOOP
  751. for ls_j=1 to ls_k
  752. copysur=cur_path+updatexepath+'\'+needcopyfile[ls_j]
  753. rslt=RegistryGet( winregtmp, needcopyfile[ls_j]+'filesit', RegString!, str_tmp)
  754. if trim(str_tmp)='' then str_tmp='[默认]'
  755. // objpathflag=lower(trim(f_ProfileString (sys_empid,updatexelogfilename,needcopyfile[ls_j]+'filesit','[默认]')))
  756. objpathflag=lower(str_tmp)
  757. if objpathflag='[windows]' then
  758. copyobj=WindowsDirectory+'\'+needcopyfile[ls_j]
  759. elseif objpathflag='[windows\system]' then
  760. copyobj=SystemDirectory+'\'+needcopyfile[ls_j]
  761. elseif objpathflag='[默认]' then
  762. copyobj=cur_path+needcopyfile[ls_j]
  763. else
  764. copyobj=cur_path+needcopyfile[ls_j]
  765. end if
  766. rslt=SetFileAttributes(copyobj,8*16)
  767. rslt=CopyFile(copysur,copyobj,0)
  768. if rslt<>0 then
  769. rslt=RegistryGet( winregtmp, needcopyfile[ls_j]+'needreg', RegString!, str_tmp)
  770. if trim(str_tmp)='' then str_tmp='0'
  771. if str_tmp='1' then
  772. // if trim(f_ProfileString (sys_empid,updatexelogfilename,needcopyfile[ls_j]+'needreg','0'))='1' then
  773. run("regsvr32 /s "+copyobj)
  774. end if
  775. filedelete(copysur)
  776. end if
  777. next
  778. for ls_j=1 to ls_i
  779. run(needrunfile[ls_j])
  780. next
  781. halt
  782. return rslt
  783. end function
  784. public function integer uf_unzipfile (string arg_zipfilename, string arg_objfilepath, ref string a_msg);//uf_unzipfile(arg_zipfilename,arg_objfilepath,a_msg)
  785. Long ll_status = 0,ls_i = 0
  786. OLEObject ZIPObject
  787. relt = 1
  788. ZIPObject = Create OLEObject
  789. ll_status = ZIPObject.ConnectToNewObject("CGZiplibrary.CGUnzipFiles")
  790. IF ll_status < 0 THEN
  791. relt = 0
  792. CHOOSE CASE ll_status
  793. CASE -1
  794. a_msg = "Invalid Call: the argument is the Object property of a control"
  795. CASE -2
  796. a_msg = "Class name not found"
  797. CASE -3
  798. a_msg = "Object could not be created"
  799. CASE -4
  800. a_msg = "Could not connect to object"
  801. CASE -9
  802. a_msg = "Other error"
  803. END CHOOSE
  804. // GOTO ext
  805. END IF
  806. IF Not FileExists (arg_zipfilename) THEN
  807. a_msg = "UnZipFiles>>无效的文件名"
  808. relt = 0
  809. GOTO ext
  810. END IF
  811. //If Pos( arg_objfilepath, ".") > 0 Then
  812. // a_msg= "UnZipFiles>> 无效的文件存放目录路径."
  813. // relt=0
  814. // GoTo ext
  815. IF DirectoryExists( arg_objfilepath) = False THEN
  816. a_msg = "UnZipFiles>> 无效的文件存放目录路径."
  817. relt = 0
  818. GOTO ext
  819. ELSEIF Pos( arg_objfilepath, ":") <= 0 THEN
  820. a_msg = "UnZipFiles>> 必须输入完整的目标文件存放目录路径."
  821. relt = 0
  822. GOTO ext
  823. END IF
  824. try
  825. ZIPObject.ZipFileName = arg_zipfilename
  826. ZIPObject.ExtractDir = arg_objfilepath
  827. // Keep Directory Structure of Zip
  828. ZIPObject.HonorDirectories = False
  829. IF ZIPObject.Unzip() <> 0 THEN
  830. relt = 0
  831. a_msg = "UnZip>> 无法解压文件 " + arg_zipfilename + " :" + ZIPObject.GetLastMessage
  832. // GOTO ext
  833. END IF
  834. Catch(runtimeerror err)
  835. if UnZipTo(arg_zipfilename,arg_objfilepath,false,"") then
  836. relt = 1
  837. open(w_filemove)
  838. else
  839. relt = 0
  840. a_msg = "UnZip>> wfZip18_DLL.dll无法解压文件 " + arg_zipfilename
  841. end if
  842. END TRY
  843. ext:
  844. Destroy ZIPObject
  845. RETURN relt
  846. end function
  847. on uo_atudexe.create
  848. call super::create
  849. TriggerEvent( this, "constructor" )
  850. end on
  851. on uo_atudexe.destroy
  852. TriggerEvent( this, "destructor" )
  853. call super::destroy
  854. end on
  855. event constructor;String arg_msg
  856. Int rslt
  857. ds_data = Create datastore
  858. //
  859. //ll_reghelper = Create uo_reghelper
  860. //md5 = Create oleobject
  861. //IF ll_reghelper.ConnectToNewObject("mymd5.Class1", sys_cur_path + "mymd5.dll", md5, arg_msg) <> 1 THEN
  862. // rslt = 0
  863. // GOTO ext
  864. //END IF
  865. //RETURN
  866. //ext:
  867. //MessageBox("连接mymd5.dll时错误",arg_msg)
  868. //RETURN
  869. end event