ASP線上升級程式

來源:互聯網
上載者:User
ASP線上升級程式

<%
'檔案名稱:updata.asp
'遠程地址
const url="http://localhost/test/"

action=request("action")
if action="updata" then
 download(url&"config.txt")
 download(url&"pack.jpg")
 response.Write("下載成功<a href='updata.asp?action=install'>安裝</a>")
elseif action="install" then
 str=openfile("config.txt")
 if str="" then
  response.write "缺少本地設定檔config.txt"
 else
  size=RegExpTest("size",str)
  call install("pack.jpg",size)
 end if
else
 str=getpage(url&"config.txt")
 if str="" then
  response.write "不存在可用更新或者本地配置不正確"
  response.end
 end if

 str1=openfile("config.txt")
 if str1="" then
  response.write "缺少本地設定檔config.txt無法獲知本地程式的安裝時間"
  response.end
 end if

 updatatime=RegExpTest("time",str)
 updatatime1=RegExpTest("time",str1)

 if DateDiff("d",updatatime1,updatatime)>0 then
  response.Write("存在可用更新,更新日期:"&updatatime&"<a href='updata.asp?action=updata'>下載</a>")
 else
  response.write "您的程式是最新的了"
 end if
end if

function openfile(filename)
set fso=server.CreateObject("scripting.filesystemobject")
if fso.fileexists(server.MapPath(filename)) then
 set f1=fso.opentextfile(server.mappath(filename),1,true)
 openfile=f1.readall
 f1.close
else
 openfile=""
end if
set fso=nothing
end function

function getpage(url)
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
if xmlhttp.status<>200 then
 getpage=""
else
 getpage=bytes2BSTR(xmlhttp.ResponseBody)
end if
end function

Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function

Function RegExpTest(patrn,strng)
Dim regEx,Match,Matches'建立變數。
Set regEx = New RegExp'建立Regex。
regEx.Pattern = patrn&"=(.+?)\n"'設定模式。
regEx.IgnoreCase = True'設定是否區分字元大小寫。
regEx.Global = True'設定全域可用性。
Set Matches = regEx.Execute(strng)'執行搜尋。
For Each Match in Matches'遍曆匹配集合。
RetStr = Match.Value
Next
RegExpTest = replace(RetStr,patrn&"=","")
End Function

function download(url)
 temp=split(url,"/")
 filename=temp(ubound(temp))
 set xmlhttp=server.createobject("Microsoft.XMLHTTP")
 xmlhttp.open "get",url,false
 xmlhttp.send
 if xmlhttp.status<>200 then
  download=""
 else
  set fso=server.createobject("scripting.filesystemobject")
  if fso.fileexists(server.mappath(filename)) then
   fso.deletefile(server.mappath(filename))
  end if
  set fso=nothing
  img=xmlhttp.ResponseBody
  set objAdostream=server.createobject("ADODB.Stream")
  objAdostream.Open
  objAdostream.type=1
  objAdostream.Write(img)
  objAdostream.SaveToFile(server.mappath(filename))
  objAdostream.SetEOS
  set objAdostream=nothing
  download=filename
 end if
 set xmlhttp=nothing
end function


function install(filename,size)
on error resume next
path=server.mappath("./")

set fso=server.createobject("scripting.filesystemobject")

set s=server.createobject("adodb.stream")
set s1=server.createobject("adodb.stream")
set s2=server.createobject("adodb.stream")

s.open
s1.open
s2.open

s.type=1
s1.type=1
s2.type=1

s.loadfromfile(server.mappath(filename))
s.position=size
s1.write(s.read)
s1.position=0
s1.type=2
s1.charset="gb2312"
s1.position=0
a=split(s1.readtext,vbcrlf)
s.position=0

i=0
while(i<ubound(a))
 b=split(a(i),">")
 if b(0)="folder" then
  if not fso.folderexists(path&b(2)) then
   fso.createfolder(path&b(2))
  end if
 elseif b(0)="file" then
  if fso.fileexists(path&b(2)) then
   fso.deletefile(path&b(2))
  end if
  s2.position=0
  s2.write(s.read(b(1)))
  s2.seteos
  s2.savetofile(path&b(2))
 end if
 i=i+1
wend

s.close
s1.close
s2.close
 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.