ASP在线升级类文件源码
作者:萧月痕 来源:CSDN 时间:2008-10-10 13:09:00
<%
Rem
Rem ## 在线升级类声明
Class Cls_oUpdate
Rem #################################################################
Rem ## 描述: ASP 在线升级类
Rem ## 版本: 1.0.0
Rem ## 作者: 萧月痕
Rem ## MSN: xiaoyuehen(at)msn.com
Rem ## 请将(at)以 @ 替换
Rem ## 版权: 既然共享, 就无所谓版权了. 但必须限于网络传播, 不得用于传统媒体!
Rem ## 如果您能保留这些说明信息, 本人更加感谢!
Rem ## 如果您有更好的代码优化, 相关改进, 请记得告诉我, 非常谢谢!
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 ## 版本信息完整URL, 以 http:// 起头
Rem ## 例: http://localhost/software/Version.htm
UrlVersion = ""
Rem ## 升级URL, 以 http:// 起头, /结尾
Rem ## 例: http://localhost/software/
UrlUpdate = ""
Rem ## 本地更新目录, 以 / 起头, /结尾. 以 / 起头是为当前站点更新.防止写到其他目录.
Rem ## 程序将检测目录是否存在, 不存在则自动创建
UpdateLocalPath = "/"
Rem ## 生成的软件历史文件
UrlHistory = "history.htm"
Rem ## 最后的提示信息
Info = ""
Rem ## 当前版本
LocalVersion = "1.0.0"
Rem ## 最新版本
LastVersion = "1.0.0"
Rem ## 各版本信息文件后缀名
FileType = ".asp"
End Sub
Rem
Rem
Private Sub Class_Terminate()
End Sub
Rem
Rem ## 执行升级动作
Rem
Public function doUpdate()
doUpdate = False
UrlVersion = Trim(UrlVersion)
UrlUpdate = Trim(UrlUpdate)
Rem ## 升级网址检测
If (Left(UrlVersion, 7) <> "http://") Or (Left(UrlUpdate, 7) <> "http://") Then
Info = "版本检测网址为空, 升级网址为空或格式错误(#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 ## 当前版本信息(数字)
sstrLocalVersion = LocalVersion
sintLocalVersion = Replace(sstrLocalVersion, ".", "")
sintLocalVersion = toNum(sintLocalVersion, 0)
Rem ## 版本检测(初始化版本信息, 并进行比较)
If IsLastVersion Then Exit function
Rem ## 开始升级
doUpdate = NowUpdate()
LastVersion = sstrLocalVersion
End function
Rem
Rem ## 检测是否为最新版本
Rem
Private function IsLastVersion()
Rem ## 初始化版本信息(初始化 sarrVersionList 数组)
If iniVersionList Then
Rem ## 若成功, 则比较版本
Dim i
IsLastVersion = True
For i = 0 to UBound(sarrVersionList)
If sarrVersionList(i) > sintLocalVersion Then
Rem ## 若有最新版本, 则退出循环
IsLastVersion = False
Info = "已经是最新版本!"
Exit For
End If
Next
Else
Rem ## 否则返回出错信息
IsLastVersion = True
Info = "获取版本信息时出错!(#2)"
End If
End function
Rem
Rem ## 检测是否为最新版本
Rem
Private function iniVersionList()
iniVersionList = False
Dim strVersion
strVersion = getVersionList()
Rem ## 若返回值为空, 则初始化失败
If strVersion = "" Then
Info = "出错......."
Exit function
End If
sstrVersionList = Replace(strVersion, " ", "")
sarrVersionList = Split(sstrVersionList, vbCrLf)
iniVersionList = True
End function
Rem
Rem ## 检测是否为最新版本
Rem
Private function getVersionList()
getVersionList = GetContent(UrlVersion)
End function
Rem
Rem ## 开始更新
Rem
Private function NowUpdate()
Dim i
For i = UBound(sarrVersionList) to 0 step -1
Call doUpdateVersion(sarrVersionList(i))
Next
Info = "升级完成! <a href=""" & sstrUrlLocal & UrlHistory & """>查看</a>"
End function
Rem
Rem ## 更新版本内容
Rem
Private function doUpdateVersion(strVer)
doUpdateVersion = False
Dim intVer
intVer = toNum(Replace(strVer, ".", ""), 0)
Rem ## 若将更新的版本小于当前版本, 则退出更新
If intVer <= sintLocalVersion Then
Exit function
End If
Dim strFileListContent, arrFileList, strUrlUpdate
strUrlUpdate = sstrUrlUpdate & intVer & FileType
strFileListContent = GetContent(strUrlUpdate)
If strFileListContent = "" Then
Exit function
End If
Rem ## 更新当前版本号
sintLocalVersion = intVer
sstrLocalVersion = strVer
Dim i, arrTmp
Rem ## 获取更新文件列表
arrFileList = Split(strFileListContent, vbCrLf)
Rem ## 更新日志
sstrLogContent = ""
sstrLogContent = sstrLogContent & strVer & ":" & vbCrLf
Rem ## 开始更新
For i = 0 to UBound(arrFileList)
Rem ## 更新格式: 版本号/文件.htm|目的文件
arrTmp = Split(arrFileList(i), "|")
sstrLogContent = sstrLogContent & vbTab & arrTmp(1)
Call doUpdateFile(intVer & "/" & arrTmp(0), arrTmp(1))
Next
Rem ## 写入日志文件
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 ## 更新文件
Rem
Private function doUpdateFile(strSourceFile, strTargetFile)
Dim strContent
strContent = GetContent(sstrUrlUpdate & strSourceFile)
Rem ## 更新并写入日志
If sDoCreateFile(Server.MapPath(sstrUrlLocal & strTargetFile), strContent) Then
sstrLogContent = sstrLogContent & " 成功" & vbCrLf
Else
sstrLogContent = sstrLogContent & " 失败" & vbCrLf
End If
End function
Rem
Rem ## 远程获得内容
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 ## 编码转换 2进制 => 字符串
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 ## 编码转换 2进制 => 字符串
Private function sDoCreateFile(strFileName, ByRef strContent)
sDoCreateFile = False
Dim strPath
strPath = Left(strFileName, InstrRev(strFileName, "\", -1, 1))
Rem ## 检测路径及文件名有效性
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 ## 编码转换 2进制 => 字符串
Private function sDoAppendFile(strFileName, ByRef strContent)
sDoAppendFile = False
Dim strPath
strPath = Left(strFileName, InstrRev(strFileName, "\", -1, 1))
Rem ## 检测路径及文件名有效性
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 ## 建立目录的程序,如果有多级目录,则一级一级的创建
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 ## 长整数转换
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
%>
标签:类,asp,升级,asp
0
投稿
猜你喜欢
VS2008 和.NET 3.5 Beta2常见问题的解决方案
2007-09-23 12:33:00
TensorFlow通过文件名/文件夹名获取标签,并加入队列的实现
2023-02-14 17:08:47
Pytorch数据拼接与拆分操作实现图解
2021-08-01 04:37:05
Python处理mysql数据库
2010-12-03 16:23:00
Python3.7将普通图片(png)转换为SVG图片格式(网站logo图标)动起来
2021-09-26 00:05:53
python list语法学习(带例子)
2023-08-20 05:36:40
使用PyQt的QLabel组件实现选定目标框功能的方法示例
2022-01-08 22:43:21
python flask几分钟实现web服务的例子
2023-05-21 13:04:58
vue+element实现图片上传及裁剪功能
2024-05-29 22:22:12
python 动态迁移solr数据过程解析
2023-03-08 10:19:20
python PyAUtoGUI库实现自动化控制鼠标键盘
2022-07-07 16:47:41
深入浅析Python 中的sklearn模型选择
2023-05-15 19:12:00
在ORACLE里设置访问多个SQL Server数据库
2007-08-17 10:18:00
验证javascript中Object和Function的关系的三段简单代码
2024-04-29 13:43:32
Python实现将多张图片合成视频并加入背景音乐
2022-12-14 19:46:29
Django 解决开发自定义抛出异常的问题
2023-03-05 12:43:55
SQL Server数据库基本概念、组成、常用对象与约束
2024-01-14 02:16:01
MySQL中使用replace、regexp进行正则表达式替换的用法分析
2024-01-15 13:34:02
经验丰富程序员才知道的8种高级Python技巧
2022-12-27 03:05:57
浏览器根据什么来判定脚本失控?[译]
2009-02-20 13:36:00