> 웹 프론트엔드 > JS 튜토리얼 > 자동 업데이트 기능_javascript 기술

자동 업데이트 기능_javascript 기술

WBOY
풀어 주다: 2016-05-16 19:25:35
원래의
955명이 탐색했습니다.
코드 복사 코드는 다음과 같습니다.

function CLASS_AUTOUPDATE(instanceName,win)
{
    this.instanceName    = instanceName;
    this.updating        = false;
    this.error            = false;
    this.updateInfo        = "";
    this.nextVersion    = "";
    this.ver            = "";
    this.win            = win;
    this.updatePath        = "";
    this.updateFileName = "";
    this.softName        = "";
    this.refresh();

}
CLASS_AUTOUPDATE.prototype.onafterupdate = function()
{

    var _window                = this.win;
    var tempMessageWidth    = 360;
    var tempMessageHeight    = 160;
    var tempMessageLeft        = (document.body.clientWidth - tempMessageWidth) /2;
    var tempMessageTop        = (document.body.clientHeight - tempMessageHeight) /2;
    var feature = {
        title:"更新完毕",
        width:tempMessageWidth,
        height:tempMessageHeight,
        left:tempMessageLeft,
        top:tempMessageTop,
        borderColor:"#8B89A1",
        backgroundColor:"#FFFFFF",
        color:"#000000",
        titleBackgroundColor:"#8B89A1",
        titleColor:"#FFFFFF",
        dragable:true
    };

    var THIS = this;

    var tempMessageContent    = [];

    //tempMessageContent[tempMessageContent.length] = "
";
    tempMessageContent[tempMessageContent.length] = this.updateInfo;
    //tempMessageContent[tempMessageContent.length] = "

";
    tempMessageContent[tempMessageContent.length] = "
";
    tempMessageContent[tempMessageContent.length] = "
";

    _window.open("updateOk",feature);
    _window.write("updateOk",tempMessageContent.join(""),false);

    _window. items["updateOk"].all("bt_update_ok").onclick = function()
                                                > );                                                         
                                                     }
    _window.items["updateOk"] .onunload =    function()
                                     {                                        
> {
                                              document.location.reload() }
}

}" xml\autoupdate.xml");
if(configXML.error==false)
{
var _update_date,_autoupdate_day,_current_version;

var _save_or_not; var _d = new Date();
var _dd = _d.getFullYear() "-" (_d.getMonth() 1) "-" _d.getDate()

//확인 업데이트 기간 설정입니다
if(configXML.selectSingleNode("/Config/UpdateDate")==null)
{
configXML.setText("/Config","UpdateDate", _dd); > _update_date = _dd;
_save_or_not = true;
}
else
_update_date = configXML.getText("/Config","UpdateDate", "1900-01-01" ); );

_autoupdate_day = "10";
_save_or_not = true;
}
else
{
_autoupdate_day = configXML.getText("/Config"," AutoUpdateDay" , "10");
    }
_autoupdate_day = _autoupdate_day *1; {
configXML.setText("/Config","CurrentVersion", "0.32")

_current_version = " 0.32";
_save_or_not = true;
                                                                             
_current_version = configXML.getText("/Config","CurrentVersion", "0.32")
}
        _현재_버전 = _현재_버전 * 1;


        //判断是否今天去连接服务器
        var _od = new Date(_update_date.replace(/-/g, "/"));
        if(_d.getTime()-_od.getTime()>_autoupdate_day*24*3600*1000)
        {

           var newDoc        = new CLASS_XML();
                newDoc.loadRemoteFile(this.updatePath   this.softName   "/"   this.updateFileName);            

           if(newDoc.selectSingleNode("/Config/CurrentVersion")==null)
            {
             newDoc.setText("/Config","CurrentVersion", "0.32" );
                _new_version = "0.32";
            }
            else
            {
              _new_version = newDoc.getText("/Config","CurrentVersion", "0.32");
            }
           _new_version = _new_version * 1;

           //检查是否유신특본
           if(_new_version>_current_version)
            { ver = 참;
            }

           configXML.setText("/Config","UpdateDate",_dd);
            _save_or_not = true;
        }

        if(_save_or_not)
        {
           configXML.save();
        }

    }

    if(_exist_new_ver)
    {
        var _window                = this.win;
        var tempMessageWidth    = 260;
        var tempMessageHeight    = 120;
        var tempMessageLeft        = (document.body.clientWidth - tempMessageWidth) /2;
        var tempMessageTop        = (document.body.clientHeight - tempMessageHeight) /2;
        var feature = {
            title:"升级",
            width:tempMessageWidth,
            height:tempMessageHeight,
            left:tempMessageLeft,
            top:tempMessageTop,
            borderColor:"#8B89A1",
            backgroundColor:"#FFFFFF",
            color:"#000000",
            titleBackgroundColor:"#8B89A1",
            titleColor:"#FFFFFF",
            dragable:true
        };

        var THIS = this;

        var tempMessageContent    = [];

        //tempMessageContent[tempMessageContent.length] = "
";
        tempMessageContent[tempMessageContent.length] = "
有新版本,是否更新?
";
        //tempMessageContent[tempMessageContent.length] = "

";
        tempMessageContent[tempMessageContent.length] = "
  
";
        tempMessageContent[tempMessageContent.length] = "
";

        _window.open("update_or_not",feature);
        _window.write("update_or_not",tempMessageContent.join(""),false);

        이것입니다. ver = _current_version;

        _window.items["update_or_not"].all("bt_update_yes").onclick = function()
                                   >                                                       _window.close ("업데이트_또는_않음");

                                                      THIS.update()                                                                                                     {
                                                           _window.close("update_or_not")                                                             }
        _window.items["update_or_not"].onunload =    function()
                                     {            > >
CLASS_AUTOUPDATE.prototype.update = function()
{

    this.updating    = !this.updating;

    var t           = new Date();
    var 이것        = 이;

    if(this.error == false)
    {

    //得到新配置文档
    var newDoc        = new CLASS_XML();
        newDoc.loadRemoteFile(this.updatePath   this.softName   "/"   this.updateFileName);

        this.error = newDoc.error;

        if(this.error)
        {
            THIS.updating    = false;
           THIS.updateInfo    = "连接服务器失败";
        }
        else
        {
           var updateFileNodes = newDoc.selectNodes("//SystemFile");
            var updateInfoNode    = newDoc.selectSingleNode("//UpdateInfo");
            var nextVersion        = newDoc.selectSingleNode("//nextversion");

           if(updateInfoNode != null)
            {
               THIS.updateInfo = updateInfoNode.childNodes[0].text;
            }

           if(nextVersion != null)
           {
               THIS.nextVersion = nextVersion.childNodes[0].text ;
            }

            THIS.updateFileList = [];            

           for(var i=0;i            {
              var curUpdateFileName        = updateFileNodes[i].get("name").toLo werCase();
               var curUpdateFileVersion    = updateFileNodes[i].getAttribute("version").toLowerCase();
               var curUpdateFilePath        = updateFileNodes[i].getAttribute("path").toLowerCase();

               if(THIS.systemFiles[curUpdateFileName] == null || THIS.systemFiles[curUpdateFileName] != curUpdateFileVersion)
             {                       > .updateFileList[THIS.updateFileList.length] = 
                   {
                   이름    :curUpdateFileName                      버전    :curUpdateFileVersion,
                      경로    :curUpdateFilePath,
                     유형    :"text"
                   };
               }
            }

            newDoc.dispose();


            if(THIS.updateFileList.length == 0)
            {
               THIS.updating    = false;
               THIS.updateInfo    = "没有需要更新的文件< !--삽입//-->";
            }
else
{
var configXML = new CLASS_XML("xml\autoupdate.xml");
//업데이트 정보 추가
                                                         > .업데이트정보) 🎜> using configXML.root().appendChild(_updateInfo); .selectSingleNode("//nextversion");
                                                       null)
{
var__next = configXML.createElement("nextversion")
var__cdata =configXML .createCDATASection(THIS.nextVersion);

      __next.appendChild(__cdata); configXML.root().appendChild(__next);                  > )));                                                                           , "CurrenTversion", this.ver)

configxml.save ();
}
configXML.dispose();

THIS.updateFile();
}
} }
}
else
{
this.updateInfo = " < ;table width='100%' height='100' cellPadding='10'>구성 파일을 로드하지 못했습니다!";
    }
    this.updating = false;
    this.onafterupdate() ;

}

CLASS_AUTOUPDATE.prototype.updateFile = function(curUpdateId)
{

    var t       = new Date()
    var 이것;

    for(var i= 0;i    {
        var curUpdateFile = this.updateFileList[i]

        if(curUpdateFile. 유형 == "base64")
        {
           var url = this.updatePath    this.softName   "/base64.aspx?src="   curUpdateFile.name   "&t="   t.valueOf()
        }
        else if(curUpdateFile.type == "text")
        {
          var url = this.updatePath   this.softName   "/"   curUpdateFile.path   "/"   curUpdateFile.name;   }

       //下载文件
        var errors     = this.downloadFile(url,curUpdateFile.path,curUpdateFile.name);

        if(this.error==false)
        {
//记录当前版本信息                   
            var configXML    = new CLASS_XML("xml\autoupdate.xml");
            if(configXML.error==false)
            {
              var systemFiles = configXML.selectSingleNode("//SystemFiles");
               if(systemFiles    == null)
               {
                  systemFiles = configXML.createElement("SystemFiles");
                   configXML.selectSingleNode("/Config").appendChild(systemFiles);
               }

               var systemFile    = configXML.selectSingleNode("//SystemFiles/SystemFile[@name='"   curUpdateFile.name.toLowerCase()   "']");

               if(systemFile    == null)
               {
                   systemFile    = configXML.createElement("SystemFile");
                   systemFile.setAttribute("name",curUpdateFile.name.toLowerCase());
                   systemFile.setAttribute("path",curUpdateFile.path.toLowerCase());
                   configXML.selectSingleNode("//SystemFiles").appendChild(systemFile);
                }
                systemFile.setAttribute("version",curUpdateFile.version);

                configXML.save();
                configXML.dispose();

                this.error         = false;
                this.updateInfo  = 오류   "n";
           }
            else
            {
              this.updateInfo  = " 加载配置文件출错!";
            }
        }
    }

}

CLASS_AUTOUPDATE.prototype.downloadFile = function(url,path,filename)
{
    시도
    {
        var xmlHTTP    =    new ActiveXObject("Microsoft.XMLHTTP")

           xmlHTTP.open("Get",url,false);
          xmlHTTP.send()

        if(xmlHTTP.readyState==4&&xmlHTTP.status==200)         
>     this.buildPath(경로)

>        adodbStream.Open()
adodbStream.write(xmlHTTP.responseBody);
            adodbStream.SaveToFile(strLocalURL,2)          adodbStream.Close();
            xmlHTTP            = null;
        }
        else
        {
            this.error        = true;
            return    파일 이름   "下载失败";
        }

        반환 "";
    }
    catch(e)
    {
        this.error        = true;
        반품    e.description;
    }
}
CLASS_AUTOUPDATE.prototype.refresh = function()
{
    var configXML = new CLASS_XML("xml\autoupdate.xml");
    if(configXML.error==false)
    {
        var _softName        = configXML.selectSingleNode ("/Config/SoftName");
        var _updatePath        = configXML.selectSingleNode ("/Config/UpdatePath");
        var _updateFileName    = configXML.selectSingleNode ("/Config/UpdateFileName");

        this.updatePath        = _updatePath     !=null?_updatePath.text    :"http://dooit.3322.org/";
        this.softName        = _softName         !=null?_softName.text        :"cc";
        this.updateFileName = _updateFileName!=null?_updateFileName.text:"autoupdate.xml";

        this.systemFiles = {};
        var tempSystemFileNodes = configXML.selectNodes("/Config/SystemFiles/SystemFile");
        for(var i=0;i        {
            this.systemFiles[tempSystemFileNodes[i].getAttribute("name")] = tempSystemFileNodes[i].getAttribute(" 버전");
        }
    }
    else
    {
        this.error = true;
    }
    configXML.dispose();    
}
CLASS_AUTOUPDATE.prototype.buildPath = function(path)
{
    var _baseUrl    = unescape(document.location.href.substring(document.location.href.lastIndexOf("/") 1 ,-1)).replace(/^file:////i,"").replace(///g,"\");
    var _path        = path.replace(/^s*|s*$/g,"");
    var _fullPath    = "";

    //得到全路径
    if(/^w:\/.test(_path) == false){
        _fullPath = _baseUrl   _path;
    }else{
        _fullPath = _path;
    }

    var p    = _fullPath.split(/\|//g);
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    var t    = "";

    for(var i=0;i        t  = p[i]   "\";

        시도
        {
           if(!fso.FolderExists(t))
           {
                fso.CreateFolder(t);
            }
        }
        catch(e)
        {
            return false;
        }
    }

    true를 반환합니다.
}
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿