最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP在线升级类技巧

日期:10-10    来源:中国设计秀    作者:cnwebshow.com

<%bI3中国设计秀
Rem #####################################################################################bI3中国设计秀
Rem ## 在线升级类声明bI3中国设计秀
Class Cls_oUpdatebI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 描述: asp 在线升级类bI3中国设计秀
  Rem ## 版本: 1.0.0bI3中国设计秀
  Rem ## 作者: 萧月痕bI3中国设计秀
  Rem ## MSN:  xiaoyuehen(at)msn.combI3中国设计秀
  Rem ## 请将(at)以 @ 替换bI3中国设计秀
  Rem ## 版权: 既然共享, 就无所谓版权了. 但必须限于网络传播, 不得用于传统媒体!bI3中国设计秀
  Rem ## 如果您能保留这些说明信息, 本人更加感谢!bI3中国设计秀
  Rem ## 如果您有更好的代码优化, 相关改进, 请记得告诉我, 非常谢谢!bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Public LocalVersion, LastVersion, FileTypebI3中国设计秀
  Public UrlVersion, UrlUpdate, UpdateLocalPath, InfobI3中国设计秀
  Public UrlHistorybI3中国设计秀
  PRivate sstrVersionList, sarrVersionList, sintLocalVersion, sstrLocalVersionbI3中国设计秀
  Private sstrLogContent, sstrHistoryContent, sstrUrlUpdate, sstrUrlLocalbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Private Sub Class_Initialize()bI3中国设计秀
   Rem ## 版本信息完整URL, 以 http:// 起头bI3中国设计秀
   Rem ## 例: http://localhost/software/Version.htmbI3中国设计秀
   UrlVersion     = ""bI3中国设计秀
   bI3中国设计秀
   Rem ## 升级URL, 以 http:// 起头, /结尾bI3中国设计秀
   Rem ## 例: http://localhost/software/bI3中国设计秀
   UrlUpdate     = ""bI3中国设计秀
   bI3中国设计秀
   Rem ## 本地更新目录, 以 / 起头, /结尾. 以 / 起头是为当前站点更新.防止写到其他目录.bI3中国设计秀
   Rem ## 程序将检测目录是否存在, 不存在则自动创建bI3中国设计秀
   UpdateLocalPath  = "/"bI3中国设计秀
   bI3中国设计秀
   Rem ## 生成的软件历史文件bI3中国设计秀
   UrlHistory     = "history.htm"bI3中国设计秀
   bI3中国设计秀
   Rem ## 最后的提示信息bI3中国设计秀
   Info        = ""bI3中国设计秀
   bI3中国设计秀
   Rem ## 当前版本bI3中国设计秀
   LocalVersion    = "1.0.0"bI3中国设计秀
   bI3中国设计秀
   Rem ## 最新版本bI3中国设计秀
   LastVersion    = "1.0.0"bI3中国设计秀
   bI3中国设计秀
   Rem ## 各版本信息文件后缀名bI3中国设计秀
   FileType      = ".asp"bI3中国设计秀
  End SubbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Private Sub Class_Terminate()bI3中国设计秀
  bI3中国设计秀
  End SubbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 执行升级动作bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Public function doUpdate()bI3中国设计秀
   doUpdate = FalsebI3中国设计秀
   bI3中国设计秀
   UrlVersion    = Trim(UrlVersion)bI3中国设计秀
   UrlUpdate    = Trim(UrlUpdate)bI3中国设计秀
   bI3中国设计秀
   Rem ## 升级网址检测bI3中国设计秀
   If (Left(UrlVersion, 7) <> "http://"<IMG SRC="smile/05.gif"> Or (Left(UrlUpdate, 7) <> "http://"<IMG SRC="smile/05.gif"> ThenbI3中国设计秀
    Info = "版本检测网址为空, 升级网址为空或格式错误(#1)"bI3中国设计秀
    Exit functionbI3中国设计秀
   End IfbI3中国设计秀
   bI3中国设计秀
   If Right(UrlUpdate, 1) <> "/" Then bI3中国设计秀
    sstrUrlUpdate = UrlUpdate & "/"bI3中国设计秀
   ElsebI3中国设计秀
    sstrUrlUpdate = UrlUpdatebI3中国设计秀
   End IfbI3中国设计秀
   bI3中国设计秀
   If Right(UpdateLocalPath, 1) <> "/" Then bI3中国设计秀
    sstrUrlLocal = UpdateLocalPath & "/"bI3中国设计秀
   ElsebI3中国设计秀
    sstrUrlLocal = UpdateLocalPathbI3中国设计秀
   End If   bI3中国设计秀
   bI3中国设计秀
   Rem ## 当前版本信息(数字)bI3中国设计秀
   sstrLocalVersion = LocalVersionbI3中国设计秀
   sintLocalVersion = Replace(sstrLocalVersion, ".", ""<IMG SRC="smile/05.gif">bI3中国设计秀
   sintLocalVersion = toNum(sintLocalVersion, 0)bI3中国设计秀
   bI3中国设计秀
   Rem ## 版本检测(初始化版本信息, 并进行比较)bI3中国设计秀
   If IsLastVersion Then Exit functionbI3中国设计秀
   bI3中国设计秀
   Rem ## 开始升级bI3中国设计秀
   doUpdate = NowUpdate()bI3中国设计秀
   LastVersion = sstrLocalVersionbI3中国设计秀
  End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  bI3中国设计秀
  Rem ## 检测是否为最新版本bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function IsLastVersion()bI3中国设计秀
    Rem ## 初始化版本信息(初始化 sarrVersionList 数组)bI3中国设计秀
    If iniVersionList ThenbI3中国设计秀
     Rem ## 若成功, 则比较版本bI3中国设计秀
     Dim ibI3中国设计秀
     IsLastVersion = TruebI3中国设计秀
     For i = 0 to UBound(sarrVersionList)bI3中国设计秀
      If sarrVersionList(i) > sintLocalVersion ThenbI3中国设计秀
       Rem ## 若有最新版本, 则退出循环bI3中国设计秀
       IsLastVersion = FalsebI3中国设计秀
       Info = "已经是最新版本!"bI3中国设计秀
       Exit ForbI3中国设计秀
      End IfbI3中国设计秀
     NextbI3中国设计秀
    ElsebI3中国设计秀
     Rem ## 否则返回出错信息bI3中国设计秀
     IsLastVersion = TruebI3中国设计秀
     Info = "获取版本信息时出错!(#2)"bI3中国设计秀
    End If   bI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 检测是否为最新版本bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function iniVersionList()bI3中国设计秀
    iniVersionList = FalsebI3中国设计秀
    bI3中国设计秀
    Dim strVersionbI3中国设计秀
    strVersion = getVersionList()bI3中国设计秀
    bI3中国设计秀
    Rem ## 若返回值为空, 则初始化失败bI3中国设计秀
    If strVersion = "" ThenbI3中国设计秀
     Info = "出错......."bI3中国设计秀
     Exit functionbI3中国设计秀
    End IfbI3中国设计秀
    bI3中国设计秀
    sstrVersionList = Replace(strVersion, " ", ""<IMG SRC="smile/05.gif">bI3中国设计秀
    sarrVersionList = Split(sstrVersionList, vbCrLf)bI3中国设计秀
    bI3中国设计秀
    iniVersionList = TruebI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 检测是否为最新版本bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function getVersionList()bI3中国设计秀
    getVersionList = GetContent(UrlVersion)bI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 开始更新bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function NowUpdate()bI3中国设计秀
    Dim ibI3中国设计秀
    For i = UBound(sarrVersionList) to 0 step -1bI3中国设计秀
     Call doUpdateVersion(sarrVersionList(i))bI3中国设计秀
    NextbI3中国设计秀
    Info = "升级完成! <a href=""" & sstrUrlLocal & UrlHistory & """>查看</a>"bI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  bI3中国设计秀
  Rem ## 更新版本内容bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function doUpdateVersion(strVer)bI3中国设计秀
    doUpdateVersion = FalsebI3中国设计秀
    bI3中国设计秀
    Dim intVerbI3中国设计秀
    intVer = toNum(Replace(strVer, ".", ""<IMG SRC="smile/05.gif">, 0)bI3中国设计秀
    bI3中国设计秀
    Rem ## 若将更新的版本小于当前版本, 则退出更新bI3中国设计秀
    If intVer <= sintLocalVersion ThenbI3中国设计秀
     Exit functionbI3中国设计秀
    End IfbI3中国设计秀
    bI3中国设计秀
    Dim strFileListContent, arrFileList, strUrlUpdate   bI3中国设计秀
    strUrlUpdate = sstrUrlUpdate & intVer & FileTypebI3中国设计秀
    bI3中国设计秀
    strFileListContent = GetContent(strUrlUpdate)bI3中国设计秀
    bI3中国设计秀
    If strFileListContent = "" ThenbI3中国设计秀
     Exit functionbI3中国设计秀
    End IfbI3中国设计秀
    bI3中国设计秀
    Rem ## 更新当前版本号bI3中国设计秀
    sintLocalVersion = intVerbI3中国设计秀
    sstrLocalVersion = strVerbI3中国设计秀
    bI3中国设计秀
    Dim i, arrTmpbI3中国设计秀
    Rem ## 获取更新文件列表bI3中国设计秀
    arrFileList = Split(strFileListContent, vbCrLf)bI3中国设计秀
    bI3中国设计秀
    Rem ## 更新日志bI3中国设计秀
    sstrLogContent = ""bI3中国设计秀
    sstrLogContent = sstrLogContent & strVer & ":" & vbCrLfbI3中国设计秀
    bI3中国设计秀
    Rem ## 开始更新bI3中国设计秀
    For i = 0 to UBound(arrFileList)bI3中国设计秀
     Rem ## 更新格式: 版本号/文件.htm|目的文件bI3中国设计秀
     arrTmp = Split(arrFileList(i), "|"<IMG SRC="smile/05.gif">bI3中国设计秀
     sstrLogContent = sstrLogContent & vbTab & arrTmp(1)bI3中国设计秀
     Call doUpdateFile(intVer & "/" & arrTmp(0), arrTmp(1))     bI3中国设计秀
    NextbI3中国设计秀
    bI3中国设计秀
    Rem ## 写入日志文件bI3中国设计秀
    sstrLogContent = sstrLogContent & Now() & vbCrLfbI3中国设计秀
    response.Write("<pre>" & sstrLogContent & "</pre>"<IMG SRC="smile/05.gif">bI3中国设计秀
    Call sDoCreateFile(Server.MapPath(sstrUrlLocal & "Log" & intVer & ".htm"<IMG SRC="smile/05.gif">, _                                          "<pre>" & sstrLogContent & "</pre>"<IMG SRC="smile/05.gif">bI3中国设计秀
    Call sDoAppendFile(Server.MapPath(sstrUrlLocal & UrlHistory), "<pre>" & _                                          strVer & "_______" & Now() & "</pre>" & vbCrLf)bI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  bI3中国设计秀
  Rem ## 更新文件bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function doUpdateFile(strSourceFile, strTargetFile)bI3中国设计秀
    Dim strContentbI3中国设计秀
    strContent = GetContent(sstrUrlUpdate & strSourceFile)bI3中国设计秀
    bI3中国设计秀
    Rem ## 更新并写入日志bI3中国设计秀
    If sDoCreateFile(Server.MapPath(sstrUrlLocal & strTargetFile), strContent) Then     bI3中国设计秀
     sstrLogContent = sstrLogContent & "  成功" & vbCrLfbI3中国设计秀
    ElsebI3中国设计秀
     sstrLogContent = sstrLogContent & "  失败" & vbCrLfbI3中国设计秀
    End IfbI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 远程获得内容bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function GetContent(strUrl)bI3中国设计秀
    GetContent = ""bI3中国设计秀
    bI3中国设计秀
    Dim oXhttp, strContentbI3中国设计秀
    Set oXhttp = Server.CreateObject("Microsoft.xmlHTTP"<IMG SRC="smile/05.gif">bI3中国设计秀
    'On Error Resume Next bI3中国设计秀
    With oXhttpbI3中国设计秀
     .Open "GET", strUrl, False, "", ""bI3中国设计秀
     .SendbI3中国设计秀
     If .readystate <> 4 Then Exit functionbI3中国设计秀
     strContent = .ResponsebodybI3中国设计秀
     bI3中国设计秀
     strContent = sBytesToBstr(strContent)bI3中国设计秀
    End WithbI3中国设计秀
    bI3中国设计秀
    Set oXhttp = NothingbI3中国设计秀
    If Err.Number <> 0 ThenbI3中国设计秀
     response.Write(Err.Description)bI3中国设计秀
     Err.ClearbI3中国设计秀
     Exit functionbI3中国设计秀
    End IfbI3中国设计秀
    bI3中国设计秀
    GetContent = strContentbI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 编码转换 2进制 => 字符串bI3中国设计秀
   Private function sBytesToBstr(vIn)bI3中国设计秀
    dim objStreambI3中国设计秀
    set objStream = Server.CreateObject("adodb.stream"<IMG SRC="smile/05.gif">bI3中国设计秀
    objStream.Type    = 1bI3中国设计秀
    objStream.Mode    = 3bI3中国设计秀
    objStream.OpenbI3中国设计秀
    objStream.Write vInbI3中国设计秀
    bI3中国设计秀
    objStream.Position  = 0bI3中国设计秀
    objStream.Type    = 2bI3中国设计秀
    objStream.Charset  = "GB2312"bI3中国设计秀
    sBytesToBstr     = objStream.ReadText bI3中国设计秀
    objStream.ClosebI3中国设计秀
    set objStream    = nothingbI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 编码转换 2进制 => 字符串bI3中国设计秀
   Private function sDoCreateFile(strFileName, ByRef strContent)bI3中国设计秀
    sDoCreateFile = FalsebI3中国设计秀
    Dim strPathbI3中国设计秀
    strPath = Left(strFileName, InstrRev(strFileName, "", -1, 1))bI3中国设计秀
    Rem ## 检测路径及文件名有效性bI3中国设计秀
    If Not(CreateDir(strPath)) Then Exit functionbI3中国设计秀
    'If Not(CheckFileName(strFileName)) Then Exit functionbI3中国设计秀
    bI3中国设计秀
    'response.Write(strFileName)bI3中国设计秀
    Const ForReading = 1, ForWriting = 2, ForAppending = 8bI3中国设计秀
    Dim fso, fbI3中国设计秀
    Set fso = CreateObject("Scripting.FileSystemObject"<IMG SRC="smile/05.gif">bI3中国设计秀
    Set f = fso.OpenTextFile(strFileName, ForWriting, True)bI3中国设计秀
    f.Write strContentbI3中国设计秀
    f.ClosebI3中国设计秀
    Set fso = nothingbI3中国设计秀
    Set f = nothingbI3中国设计秀
    sDoCreateFile = TruebI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 编码转换 2进制 => 字符串bI3中国设计秀
   Private function sDoAppendFile(strFileName, ByRef strContent)bI3中国设计秀
    sDoAppendFile = FalsebI3中国设计秀
    Dim strPathbI3中国设计秀
    strPath = Left(strFileName, InstrRev(strFileName, "", -1, 1))bI3中国设计秀
    Rem ## 检测路径及文件名有效性bI3中国设计秀
    If Not(CreateDir(strPath)) Then Exit functionbI3中国设计秀
    'If Not(CheckFileName(strFileName)) Then Exit functionbI3中国设计秀
    bI3中国设计秀
    'response.Write(strFileName)bI3中国设计秀
    Const ForReading = 1, ForWriting = 2, ForAppending = 8bI3中国设计秀
    Dim fso, fbI3中国设计秀
    Set fso = CreateObject("Scripting.FileSystemObject"<IMG SRC="smile/05.gif">bI3中国设计秀
    Set f = fso.OpenTextFile(strFileName, ForAppending, True)bI3中国设计秀
    f.Write strContentbI3中国设计秀
    f.ClosebI3中国设计秀
    Set fso = nothingbI3中国设计秀
    Set f = nothingbI3中国设计秀
    sDoAppendFile = TruebI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 建立目录的程序,如果有多级目录,则一级一级的创建bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function CreateDir(ByVal strLocalPath)bI3中国设计秀
    Dim i, strPath, objFolder, tmpPath, tmptPathbI3中国设计秀
    Dim arrPathList, intLevelbI3中国设计秀
    bI3中国设计秀
    'On Error Resume NextbI3中国设计秀
    strPath     = Replace(strLocalPath, "", "/"<IMG SRC="smile/05.gif">bI3中国设计秀
    Set objFolder  = server.CreateObject("Scripting.FileSystemObject"<IMG SRC="smile/05.gif">bI3中国设计秀
    arrPathList   = Split(strPath, "/"<IMG SRC="smile/05.gif">bI3中国设计秀
    intLevel     = UBound(arrPathList)bI3中国设计秀
    bI3中国设计秀
    For I = 0 To intLevelbI3中国设计秀
     If I = 0 ThenbI3中国设计秀
      tmptPath = arrPathList(0) & "/"bI3中国设计秀
     ElsebI3中国设计秀
      tmptPath = tmptPath & arrPathList(I) & "/"bI3中国设计秀
     End IfbI3中国设计秀
     tmpPath = Left(tmptPath, Len(tmptPath) - 1)bI3中国设计秀
     If Not objFolder.FolderExists(tmpPath) Then objFolder.CreateFolder tmpPathbI3中国设计秀
    NextbI3中国设计秀
    bI3中国设计秀
    Set objFolder = NothingbI3中国设计秀
    If Err.Number <> 0 ThenbI3中国设计秀
     CreateDir = FalsebI3中国设计秀
     Err.ClearbI3中国设计秀
    ElsebI3中国设计秀
     CreateDir = TruebI3中国设计秀
    End IfbI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
  Rem ## 长整数转换bI3中国设计秀
  Rem #################################################################bI3中国设计秀
   Private function toNum(s, default)bI3中国设计秀
    If IsNumeric(s) and s <> "" thenbI3中国设计秀
     toNum = CLng(s)bI3中国设计秀
    ElsebI3中国设计秀
     toNum = defaultbI3中国设计秀
    End IfbI3中国设计秀
   End functionbI3中国设计秀
  Rem #################################################################bI3中国设计秀
End ClassbI3中国设计秀
Rem #####################################################################################bI3中国设计秀
%>bI3中国设计秀

本文引用地址:/bc/article_46252.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明