基本信息
源码名称:在线更新服务端,客户端程序升级
源码大小:0.21M
文件格式:.rar
开发语言:C#
更新时间:2017-07-15
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 5 元 
   源码介绍
 实现客户端和服务端升级服务器的通信,根据XML文件下载升级文件

     private bool DoenloadUpdateFile()
        {
            _downLoadSaveTempPath = _downLoadSaveFileName;
            if (!Directory.Exists(_downLoadSaveTempPath))
            {
                Directory.CreateDirectory(_downLoadSaveTempPath);
            }
            int updateFileCount = _updateFileList.Count;
            SetUpdateProBar((updateFileCount > 0 ? updateFileCount : 1) * 100, true);
            for (int i = 0; i < updateFileCount; i )
            {
                SetUpdateLab(string.Format("正在更新第{0}个文件:{1}", (i 1).ToString(), _updateFileList[i]), Enum.UpdateState.downloading);
                using (WebClient wcDown = new WebClient())
                {
                    try
                    {
                        wcDown.DownloadFile(_downLoadUrl _updateFileList[i], _downLoadSaveTempPath _updateFileList[i]);
                    }
                    catch (Exception ex)
                    {   
                        return false;
                    }
                }
                SetUpdateProBar(100, false);
                Thread.Sleep(100);
            }

            return true;
        }

        private void ReplaceFile()
        {
            SetUpdateLab("正在重启程序", Enum.UpdateState.closeingmain);
            OpreateMainForm(true);
            Thread.Sleep(1000);
            SetUpdateLab("开始替换文件", Enum.UpdateState.replacing);
            try
            {
                foreach (string fileName in _updateFileList)
                {
                    string moveNewPath = AppDomain.CurrentDomain.BaseDirectory fileName;
                    if (File.Exists(moveNewPath)) File.Delete(moveNewPath);
                    File.Move(_downLoadSaveTempPath fileName, moveNewPath);
                }
                //LrdComm.Helper.FileIO.DeleteFolder(_downLoadSaveTempPath);
            }
            catch (System.Exception ex)
            {

                SetUpdateLab(string.Format("替换文件时出错:{0}", ex.ToString()), UpdateApp.Enum.UpdateState.error);
                return;
            }
            SaveLocalXml();
            Thread.Sleep(500);
            SetUpdateLab("正在重启程序", Enum.UpdateState.startmain);
            OpreateMainForm(false);
            Thread.Sleep(500);
            SetUpdateLab("更新完成", Enum.UpdateState.success);
        }