Click here to learn how to use this class of Files
<% REM ##################################### ######################################## ######## REM ## class cls_oupdate REM ####################### ######################################## # REM # description: ASP online update class REM # version: 1.0.0 REM # Author: Xiao Yue mark REM # MSN: xiaoyuehen (AT) msn.com REM # Please () replace REM with @ # copyright: It doesn't matter if you share it. however, it must be limited to network communication and cannot be used in traditional media! Rem # If you can retain these instructions, I would like to thank you more! Rem # If you have better code optimization and related improvements, please remember to let me know. Thank you very much! Rem ####################################### ######################### public localversion, lastversion, filetype public urlversion, urlupdate, updatelocalpath, info public urlhistory private sstrversionlist, sarrversionlist, sintlocalversion, sstrlocalversion private sstrlogcontent, sstrhistorycontent, sstrurlupdate, sstrurllocal REM ###################################### ########################## # Private sub class_initialize () REM # complete version URL, starting with http: // REM # example: http: // localhost/software/version.htm urlversion = "" REM # Upgrade the URL, starting with http: // and ending with REM # example: http: // localhost/software/urlupdate = "" REM # update the local directory, starting with/and ending. starting with/is the current site update. prevent writing to other directories. rem # The program checks whether the directory exists, if it does not exist, updatelocalpath = "/" REM # The generated software history file urlhistory = "history.htm" REM # The Last prompt message info = "" REM # current version Loc Alversion = "1.0.0" REM # lastversion = "1.0.0" REM # The suffix of each version information file: filetype = ". ASP "End sub REM ################################### ############################# REM ######### ######################################## ############### private sub class_terminate () end sub REM ##################################### ########################### REM ## execute the update operation REM ##### ############################### ########################### Public function doupdate () doupdate = false urlversion = trim (urlversion) urlupdate = trim (urlupdate) REM # Upgrade URL Detection If (left (urlversion, 7) <> "http ://") or (left (urlupdate, 7) <> "http: //") then info = "the version check URL is empty, the upgrade URL is empty, or the format is incorrect (#1) "Exit function end if right (urlupdate, 1) <>"/"then sstrurlupdate = urlupdate &"/"else sstrurlupdate = urlupdate end if right (UPDA Telocalpath, 1) <> "/" then sstrurllocal = updatelocalpath & "/" else sstrurllocal = updatelocalpath end if REM # current version information (number) sstrlocalversion = localversion sintlocalversion = Replace (sstrlocalversion ,". "," ") sintlocalversion = tonum (sintlocalversion, 0) REM # Version Detection (initialize and compare version information) if islastversion then exit function REM # Start to upgrade doupdate = nowupdate () lastversion = sstrlocalversion end Function Rem ####################################### ######################### REM ## check whether the latest version is rem ##### ######################################## ################### private function islastversion () rem # initialize version information (initialize the sarrversionlist array) If iniversionlist then REM # If yes, compare the version dim I islastversion = true for I = 0 to ubound (sarrversionlist) if sarrversionlist (I)> sintlocalversion then REM # if the latest version is available, exit Ring islastversion = false info = "it is already the latest version! "Exit for end if next else REM # Otherwise, an error message islastversion = true info =" error occurred while obtaining the version information! (#2) "end if end function REM ################################## ############################## REM ## check whether the latest version of REM is used ######################################## ######################### private function iniversionlist () iniversionlist = false dim strversion = getversionlist () REM # If the returned value is null, initialization fails if strversion = "" then info = "error ....... "Exit function end if sstrversionlist = Replace (strv Ersion, "", "") sarrversionlist = Split (sstrversionlist, vbcrlf) iniversionlist = true end function REM ################################## ############################## REM ## check whether the latest version of REM is used ######################################## ######################### private function getversionlist () getversionlist = getcontent (urlversion) end function REM ##################################### ############## ############# REM ## start to update REM #################### ######################################## ##### private function nowupdate () dim I for I = ubound (sarrversionlist) to 0 step-1 call doupdateversion (sarrversionlist (I) next info = "upgrade complete! <A href = "" & sstrurllocal & urlhistory & "> View </a>" end function REM ############### ######################################## ########## REM ## update version content REM ####################### ######################################## # private function doupdateversion (strver) doupdateversion = false dim intver = tonum (replace (strver ,". "," "), 0) REM # If the updated version is earlier than the current version, exit if intver <= sintlocalversion then exit function end if Dim strfilelistcontent, arrfilelist, strurlupdate expires = strong & intver & filetype strfilelistcontent = getcontent (strurlupdate) If strfilelistcontent = "" Then exit function end if REM # update the current version sintlocalversion = intver sstrlocalversion = strver dim I, arrtmp REM # obtain the Update file list arrfilelist = Split (strfilelistcontent, vbcrlf) REM # Update log sstrlogcontent = "" sstrlogcontent = sstrlogcontent & strver &": "& vbcrlf REM # Start to update for I = 0 to ubound (arrfilelist) REM # update format: Version Number/file .htm | target file arrtmp = Split (arrfilelist (I ), "|") sstrlogcontent = sstrlogcontent & vbtab & arrtmp (1) Call doupdatefile (intver & "/" & arrtmp (0), arrtmp (1 )) next REM # Write the log file sstrlogcontent = sstrlogcontent & now () & vbcrlf response. write ("<PRE>" & sstrlogcontent & "</PRE>") Call sdocreatefile (server. mappath (sstrurllocal & "log" & intver &". htm "),_
"<PRE>" & sstrlogcontent & "</PRE>") Call sdoappendfile (server. mappath (sstrurllocal & urlhistory), "<PRE> "&_
Strver & "_______" & now () & "</PRE>" & vbcrlf) end function REM ##################################### ########################### REM ## update an object REM ###### ######################################## ################## private function doupdatefile (strsourcefile, strtargetfile) dim strcontent = getcontent (sstrurlupdate & strsourcefile) REM # update and write the log if sdocreatefile (server. mappath (sstrurllocal & strtargetfile), strcontent) then sstrlogcontent = sstrlogcontent & "" & vbcrlf else sstrlogcontent = sstrlogcontent & "" & vbcrlf end if end function REM ############### ######################################## ######### REM ## obtain content remotely through REM ####################### ######################################## # private function getcontent (strurl) getcontent = "" dim oxhttp, strcontent set oxhttp = server. createobject ("Microsoft. XMLHTTP ") 'on error resume next with oxhttp. open "get", strurl, false ,"","". send if. readystate <> 4 then exit function strcontent =. responsebody strcontent = sbytestobstr (strcontent) end with set oxhttp = nothing if err. number <> 0 then response. write (err. description) Err. clear exit function end if getcontent = strcontent end function REM ############################# #################################### REM ### ######################################## ##################### REM ## encoding and conversion in binary format => string private function sbytestobstr (VIN) dim objstream set objstream = server. createobject ("ADODB. stream ") objstream. type = 1 objstream. mode = 3 objstream. open objstream. write Vin objstream. position = 0 objstream. type = 2 objstream. charset = "gb2312" sbytestobstr = objstream. readtext objstream. close set objstream = nothing end function REM ################################ ################################# REM ###### ######################################## ################## REM ## encoding and conversion in binary notation => string private function sdocreatefile (strfilename, byref strcontent) sdocreatefile = false dim strpath = left (strfilename, limit Rev (strfilename, "/",-1, 1 )) rem # check the validity of the path and file name if not (createdir (strpath) Then exit function 'If not (checkfilename (strfilename) Then exit function' response. write (strfilename) const forreading = 1, forwriting = 2, forappending = 8 dim FSO, F set FSO = Createobject ("scripting. fileSystemObject ") set f = FSO. opentextfile (strfilename, forwriting, true) F. write strcontent F. close set FSO = nothing set f = nothing sdocreatefile = true end function REM ######################### ######################################## rem ####################################### ######################### REM # encoding and conversion in binary format => string private function sdoappendfile (strfilename, byref strcontent) sdoappendfile = false dim strpath = left (strfilename, limit Rev (strfilename, "/",-1, 1 )) rem # check the validity of the path and file name if not (createdir (strpath) Then exit function 'If not (checkfilename (strfilename) Then exit function' response. write (strfilename) const forreading = 1, forwriting = 2, forappending = 8 dim FSO, F set FSO = Createobject ("scripting. fileSystemObject ") set f = FSO. opentextfile (strfilename, forappending, true) F. write strcontent F. close set FSO = nothing set f = nothing sdoappendfile = true end function REM ######################### ######################################## rem # create a directory program, if there are multi-level directories, create REM ################################## ############################## private function createdir (byval strlocalpath) dim I, strpath, objfolder, tmppath, tmptpath dim arrpathlist, intlevel 'on error resume next strpath = Replace (strlocalpath, "/", "/") set objfolder = server. createobject ("scripting. fileSystemObject ") arrpathlist = Split (strpath,"/") intlevel = ubound (arrpathlist) for I = 0 to intlevel if I = 0 then tmptpath = arrpathlist (0) & "/" else tmptpath = tmptpath & arrpathlist (I) & "/" end if tmppath = left (tmptpath, Len (tmptpath)-1) if not objfolder. folderexists (tmppath) Then objfolder. createfolder tmppath next set objfolder = nothing if err. number <> 0 then createdir = false err. clear else createdir = true end if end function REM ############################## ################################### REM ## long integer conversion REM ###################################### ########################## private function tonum (S, default) If isnumeric (s) and S <> "" Then tonum = clng (s) else tonum = default end if end function REM ############################### ################################## end class REM ### ######################################## ######################################## ##%>