Click here to know
How to use this class file
<%
Rem ############################################################# #################################################
Rem ## online upgrade class declaration
Class CLS_oupdate
Rem ############################################################# ################
Rem ## Description: ASP Online Upgrade Class
REM ## version: 1.0.0
Rem ## Author: Xiao Yuehen
REM ## msn: xiaoyuehen (at) msn.com
Rem ##, please (at) @ replace
Rem ## copyright: Since sharing, there is no copyright. But it must be limited to network communication, and must not be used in traditional media!
Rem ## If you can keep these description information, I am more thanking!
Rem ## If you have better code optimization, related improvements, please remember tell me, 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 coplass_initialize ()
Rem ## version information complete URL, starting with http: //
Rem ## example: http://localhost/software/Version.htm
URLVERSION = ""
REM ## Upgrade URL, starting with http: //
Rem ## example: http:// localhost / software /
URLUPDATE = ""
Rem ## Local update directory, start, / end. Taking / starting to update for the current site. Prevent writing to other directories.
The REM ## program will detect if the directory exists, and there is no existence.
UpdatelocalPath = "/"
Rem ## generated software history file
URLHISTORY = "history.htm"
Rem ## last prompt information
INFO = ""
Rem ## Current version
Localversion = "1.0.0"
Rem ## latest version
Lastversion = "1.0.0"
REM ## Edition information file suffix name
FILETYPE = ".asp"
End Sub
Rem ############################################################# ################
Rem ############################################################# ################
Private sub coplass_terminate ()
End Sub
Rem ############################################################# ################ Rem ## execution upgrade action
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 = "version detection URL is empty, upgrade URLs are empty or format errors (# 1)"
EXIT FUNCTION
END IF
IF Right (Urlupdate, 1) <> "/" THEN
SSTRURLUPDATE = Urlupdate & "/"
Else
SSTRURLUPDATE = URLUPDATE
END IF
IF Right (UpdatelocalPath, 1) <> "/" THEN
SSTRURLLOCAL = UpdateLocalPath & "/"
Else
SSTRURLLOCAL = UpdateLocalPath
END IF
Rem ## Current Version Information (Digital)
SSTRLOCALVERSION = Localversion
SINTLOCALVERSION = Replace (SSTRLOCALVERSION, ".", "")
SINTLOCALVERSION = Tonum (sintlocalversion, 0)
Rem ## version detection (initialization version information, and compare)
IF islastVersion Then EXIT FUNCTION
Rem ## start upgrade
Doupdate = noupdate ()
Lastversion = SSTRLOCALVERSION
END FUNCTION
Rem ############################################################# ################
Rem ## Detection is the latest version
Rem ############################################################# ################
Private function islastversion ()
Rem ## Initialization version information (initialization SARRVERSIONLIST array)
IF iniversionlist the
REM ## If successful, the comparison version
DIM I
IslastVersion = TRUE
For i = 0 to Ubound (SARRVERSIONLIST)
IF SarrversionList (i)> SINTLOCALVERSION THEN
REM ## If there is a new version, exit the loop
IslastVersion = false
INFO = "is already the latest version!"
EXIT for
END IF
NEXT
Else
Rem ## otherwise returns an error message
IslastVersion = TRUE
INFO = "Error when getting version information! (# 2)"
END IF
END FUNCTION
Rem ############################################################# ############### deb ## detection is the latest version
Rem ############################################################# ################
Private function iniversionList ()
IniversionList = FALSE
DIM STRVERSION
strVersion = getVersionList ()
REM ## If the return value is empty, the initialization failed
If strVersion = "" ""
INFO = "error ......."
EXIT FUNCTION
END IF
SSTRVERSIONLIST = Replace (strVersion, "," ")
SARRVERSIONLIST = Split (SSTRVERSIONLIST, VBCRLF)
IniversionList = TRUE
END FUNCTION
Rem ############################################################# ################
Rem ## Detection is the latest version
Rem ############################################################# ################
Private function getversionList ()
getVersionList = getContent (URLVers)
END FUNCTION
Rem ############################################################# ################
Rem ## start updating
Rem ############################################################# ################
Private function nowupdate ()
DIM I
For i = ubound (SarrversionList) TO 0 Step -1
Call DoupDateVersion (SarrversionList (i))
NEXT
Info = "Upgrade Complete! View "
END FUNCTION
Rem ############################################################# ################
Rem ## update version content
Rem ############################################################# ################
Private function DoupdateVersion (StrVer)
DoupdateVersion = false
DIM INTVER
INTVER = Tonum (Replace (Strver, "," "), 0)
REM ## If the updated version is less than the current version, exit the update
IF intver <= sintlocalversion then
EXIT FUNCTION
END IF
DIM STRFILANTCONTENT, ArrfileList, Strurlupdate
StrurlUpdate = SSTRURLUPDATE & INTVER & FILETYPESTRFILISTCONTENT = GetContent (Strurlupdate)
If strfilelistcontent = "" "" "
EXIT FUNCTION
END IF
Rem ## update the current version number
SINTLOCALVERSION = INTVER
SSTRLOCALVERSION = StrVer
DIM I, Arrtmp
Rem ## Get list of update files
ArrfileList = Split (StrfileListContent, VBCRLF)
Rem ## update log
SSTRLOGCONTENT = ""
SSTRLOGCONTENT = SSTRLOGCONTENT & STRVER & ":" & VBCRLF
Rem ## start updating
For i = 0 to ubound (arrfilelist)
REM ## update format: version number / file .htm | destination file
ArrtMP = Split (ArrfileList (i), "|")
SSTRLOGCONTENT = SSTRLOGCONTENT & VBTAB & ARRTMP (1)
Call Doupdatefile (intver & "/" & arrtmp (0), Arrtmp (1)))
NEXT
REM ## Write log file
SSTRLOGCONTENT = SSTRLOGCONTENT & NOW () & VBCRLF
Response.write ("
" & SSTRLOGCONTENT & " pre>")Call sdocreatefile (Server.Mappath (SSTRURLLOCAL & "Log" & intver & ".htm"), _
"& SSTRLOGCONTENT &" PRE> ")Call SDOAPPENDFILE (Server.MAppath (SSTRURLLOCAL & URLHISTORY), "
" & _ strVer & "_______" & now () & " pre>" & vbrlf)END FUNCTION
Rem ############################################################# ################
Rem ## update file
Rem ############################################################# ################
Private function doupdatefile (strsourcefile, strtargetfile)
DIM STRCONTENT
StrContent = getContent (SSTRURLUPDATE & STRSOLEFILE)
REM ## update and write log
If SDOCREATEFILE (Server.Mappath (SSTRURLLOCAL & StrtargetFile), strcontent) THENSSTRLOGCONTENT = SSTRLOGCONTENT & "Success" & VBCRLF
Else
SSTRLOGCONTENT = SSTRLOGCONTENT & "Failed" & VBCRLF
END IF
END FUNCTION
Rem ############################################################# ################
Rem ## remote access
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, "" ""
Ssend
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 conversion 2 credit => 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 conversion 2 credit => string
Private function sdocreatefile (strfilename, byref strcontent) sdocreatefile = false
DIM STRPATH
StrPath = Left (StrfileName, INSTRREV (Strfilename, "/", -1, 1))
REM ## detection path and file name validity
IF not (createdir (strpath) THEN EXIT FUNCTION
'If not (checkfilename) THEN EXIT FUNCTION
'Response.write (StrfileName)
Const forreading = 1, forWriting = 2, FORAPPPpending = 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 conversion 2 credit => string
Private function SDOAPPENDFILE (STRFILENAME, BYREF STRCONTENT)
SDOAPPENDFILE = FALSE
DIM STRPATH
StrPath = Left (StrfileName, INSTRREV (Strfilename, "/", -1, 1))
REM ## detection path and file name validity
IF not (createdir (strpath) THEN EXIT FUNCTION
'If not (checkfilename) THEN EXIT FUNCTION
'Response.write (StrfileName)
Const forreading = 1, forWriting = 2, FORAPPPpending = 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 ## Establish a program of the directory, if there is a multi-level directory, the first-level level creation
Rem ############################################################# ################
Private function created
DIM I, STRPATH, OBJFOLDER, TMPPATH, TMPTPATHDIM 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 (tmpath) 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 <> "" "
tonum = clng (s)
Else
Tonum = default
END IF
END FUNCTION
Rem ############################################################# ################
END CLASS
Rem ############################################################# #################################################
%>