來(lái)源: "小灰"的專欄
<% 文件名:updata.asp 遠(yuǎn)程地址 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無(wú)法獲知本地程序的安裝時(shí)間" 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建立正則表達(dá)式。 regEx.Pattern = patrn&"=(.+?) "設(shè)置模式,。 regEx.IgnoreCase = True設(shè)置是否區(qū)分字符大小寫,。 regEx.Global = True設(shè)置全局可用性。 Set Matches = regEx.Execute(strng)執(zhí)行搜索,。 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 set s=nothing set s1=nothing set s2=nothing set fso=nothing if err.number<>0 then response.write err.description else response.write "安裝成功" end if end function
%>
<% 文件名稱:pack.asp on error resume next set fso=server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath("./pack.jpg")) then response.Write("pack.jpg已經(jīng)存在") response.End() end if
dim str,s,s1,s2 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=2
call WriteFile(server.MapPath("./"))
s2.charset="gb2312" s2.WriteText(str) s2.Position=0 s2.type=1 s2.Position=0 bin=s2.Read
s2.Position=0 s2.type=2 s2.writeText("time="&now&vbcrlf) s2.writeText("size="&s1.size&vbcrlf) s2.writeText("run="&request.Form("run")&vbcrlf) s2.seteos s2.savetofile(server.mappath("./config.txt"))
s1.write(bin) s1.SetEOS s1.SaveToFile(server.mappath("./pack.jpg"))
s.close s1.close s2.close
set s=nothing set s1=nothing set s2=nothing
if err.number<>0 then response.write err.description else response.Write("完成") end if
Function WriteFile(folderspec) Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(folderspec)
Set fc = f.Files For Each f1 in fc if f1.name<>"pack.asp" then str=str&"file>"&f1.size&">"&replace(folderspec&""&f1.name,server.MapPath("./"),"")&vbcrlf s.LoadFromFile(folderspec&""&f1.name) img=s.Read() s1.Write(img) end if Next
Set fc = f.SubFolders For Each f1 in fc str=str&"folder>0>"&replace(folderspec&""&f1.name,server.MapPath("./"),"")&vbcrlf WriteFile(folderspec&""&f1.name) Next
set fso=nothing End Function %>
ASP升級(jí)程序使用說(shuō)明
本程序分兩部分: 1,、ASP文件打包程序pack.asp 把這個(gè)程序和要打包的程序放到一個(gè)目錄下,,然后運(yùn)行pack.asp,得到pack.jpg和config.txt 2,、ASP在線更新,、下載、安裝程序updata.asp 這個(gè)程序可以用來(lái)檢查是否存在可用更新,,和updata.asp同一目錄要存在上面得到的config.txt,,因?yàn)閏onfig里面有當(dāng)前程序的安裝日期,用來(lái)和網(wǎng)上的程序比較用的,。 使用前,,先修改updata.asp里的url變量的值,使其等于你存放升級(jí)程序的URL,,運(yùn)行updata.asp就可查看是否存在可用更新,,如果存在就可用按著向?qū)б徊揭徊较螺d并安裝更新了。
遠(yuǎn)程地址url下面存放用pack.asp得到的pack.jpg和config.txt
本程序
|