热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

自动更新作用

自动更新作用
代码如下:

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.close("updateOk");                                                                
                                                            }
    _window.items["updateOk"].onunload =    function()
                                            {                                                
                                                if(THIS.error==false&&THIS.updateFileList.length>0)
                                                {
                                                    document.location.reload();
                                                }
                                            }

}
CLASS_AUTOUPDATE.prototype.check = function()
{
    var _current_version,_new_version,_exist_new_ver;


    //检查配置文件
    var configXML = new CLASS_XML("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");
        }

        if(configXML.selectSingleNode("/Config/AutoUpdateDay")==null)
        {
            configXML.setText("/Config","AutoUpdateDay", "10");

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

        if(configXML.selectSingleNode("/Config/CurrentVersion")==null)
        {
            configXML.setText("/Config","CurrentVersion", "0.32");

            _current_version = "0.32";
            _save_or_not = true;
        }
        else
        {
            _current_version = configXML.getText("/Config","CurrentVersion", "0.32");
        }
        _current_version = _current_version * 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)
            {
                _exist_new_ver = true;
            }

            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);

        THIS.ver = _current_version;

        _window.items["update_or_not"].all("bt_update_yes").onclick = function()
                                                                {        
                                                                    THIS.ver = _new_version;
                                                                    _window.close("update_or_not");

                                                                    THIS.update();
                                                                }
        _window.items["update_or_not"].all("bt_update_no").onclick = function()
                                                                {        
                                                                    _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 THIS        = this;

    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].getAttribute("name").toLowerCase();
                var curUpdateFileVersion    = updateFileNodes[i].getAttribute("version").toLowerCase();
                var curUpdateFilePath        = updateFileNodes[i].getAttribute("path").toLowerCase();

                if(THIS.systemFiles[curUpdateFileName] == null || THIS.systemFiles[curUpdateFileName] != curUpdateFileVersion)
                {                                    
                    //本地没有该文件或者版本号不一致
                    THIS.updateFileList[THIS.updateFileList.length] = 
                    {
                        name    :curUpdateFileName,
                        version    :curUpdateFileVersion,
                        path    :curUpdateFilePath,
                        type    :"text"
                    };
                }
            }

            newDoc.dispose();


            if(THIS.updateFileList.length == 0)
            {
                THIS.updating    = false;
                THIS.updateInfo    = "没有需要更新的文件";
            }
            else
            {
                var configXML    = new CLASS_XML("xml\\autoupdate.xml");
                //添加更新信息
                if(configXML.error==false&&THIS.updateInfo.length>0)
                {
                    var _updateInfo    = configXML.createElement("UpdateInfo");
                    var _cdata        = configXML.createCDATASection(THIS.updateInfo);

                    _updateInfo        .appendChild(_cdata);
                    configXML.root().appendChild(_updateInfo);

                    //添加下版本预告
                    var _nextVersion = configXML.selectSingleNode("//nextversion");
                    if( _nextVersion==null)
                    {
                        var __next = configXML.createElement("nextversion");
                        var __cdata= configXML.createCDATASection(THIS.nextVersion);

                        __next.appendChild(__cdata);

                        configXML.root().appendChild(__next);
                    }
                    else
                    {
                        if(_nextVersion.childNodes.length==0)
                        {
                            _nextVersion.appendChild(configXML.createCDATASection(""));
                        }
                        _nextVersion.childNodes[0].text = THIS.nextVersion;
                    }

                    configXML.setText("/Config","CurrentVersion",THIS.ver);

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

                THIS.updateFile();
            }
        }            
    }
    else
    {
        this.updateInfo = "加载配置文件失败!";
    }
    this.updating = false;
    this.onafterupdate();

}

CLASS_AUTOUPDATE.prototype.updateFile = function(curUpdateId)
{

    var t        = new Date();
    var THIS    = this;

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

        if(curUpdateFile.type == "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 += errors + "\n";
            }
            else
            {
                this.updateInfo += "加载配置文件出错!";
            }
        }
    }

}

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

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

        if(xmlHTTP.readyState==4&&xmlHTTP.status==200)
        {
            var adodbStream = new ActiveXObject("ADODB" + "." + "Stream");

            //判断目录是否存在,不存在则创建
            this.buildPath(path);

            var strLocalURL = path.length>0?path + "\\" +filename:filename;

            //1=adTypeBinary
            adodbStream.Type= 1;        
            adodbStream.Open();
            adodbStream.write(xmlHTTP.responseBody);
            adodbStream.SaveToFile(strLocalURL,2);
            adodbStream.Close();

            adodbStream        = null;
            xmlHTTP            = null;
        }
        else
        {
            this.error        = true;
            return    filename + "下载失败";
        }

        return "";
    }
    catch(e)
    {
        this.error        = true;
        return    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("version");
        }
    }
    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] + "\\";

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

    return true;
}

推荐阅读
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 基于PgpoolII的PostgreSQL集群安装与配置教程
    本文介绍了基于PgpoolII的PostgreSQL集群的安装与配置教程。Pgpool-II是一个位于PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件,提供了连接池、复制、负载均衡、缓存、看门狗、限制链接等功能,可以用于搭建高可用的PostgreSQL集群。文章详细介绍了通过yum安装Pgpool-II的步骤,并提供了相关的官方参考地址。 ... [详细]
  • YOLOv7基于自己的数据集从零构建模型完整训练、推理计算超详细教程
    本文介绍了关于人工智能、神经网络和深度学习的知识点,并提供了YOLOv7基于自己的数据集从零构建模型完整训练、推理计算的详细教程。文章还提到了郑州最低生活保障的话题。对于从事目标检测任务的人来说,YOLO是一个熟悉的模型。文章还提到了yolov4和yolov6的相关内容,以及选择模型的优化思路。 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • 本文介绍了解决Netty拆包粘包问题的一种方法——使用特殊结束符。在通讯过程中,客户端和服务器协商定义一个特殊的分隔符号,只要没有发送分隔符号,就代表一条数据没有结束。文章还提供了服务端的示例代码。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
author-avatar
AYAKASHIZ
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有