zoukankan      html  css  js  c++  java
  • 基于C/S模式的程序更新下载

    思路:

    ①检查是否需要更新(通过数据库获取最新版本号和本地版本号进行比对(本地版本号可存在txt文件中,需要进行一定程度上的加密和解密操作))

    ②从指定目录下载最新版本的程序覆盖本地文件(下载的文件时压缩文件)

    ③将压缩文件进行程序内解压缩(有可能客户电脑未安装压缩软件,所以只能通过程序本身来进行解压)

    ④解压完成后调用主程序

    实现:

    下载:WebClient

     1 if (webClient.IsBusy)//是否存在正在进行中的Web请求
     2             {
     3                 webClient.CancelAsync();
     4             }
     5             //为webClient添加事件
     6             webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
     7             webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
     8             //开始下载
     9             string path = exePath + @"\Update.RAR";
    10             webClient.DownloadFileAsync(new Uri(this.txtFilePath.Text), path);
     1  private void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
     2         {
     3 
     4             this.progressBar1.Value = e.ProgressPercentage;
     5             this.lbl_pro.Text = e.ProgressPercentage.ToString() + "%";
     6             this.lbl_detail.Text = string.Format("Downloading....,{0}/{1}(byte)"
     7                                 , e.BytesReceived
     8                                 , e.TotalBytesToReceive);
     9             if (e.TotalBytesToReceive == e.BytesReceived)
    10             {
    11                 this.lbl_detail.Text = ("DownLoad success.Update now, wait a second!");
    12             }
    13         }
     1  private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
     2         {
     3             if (e.Cancelled)
     4             {
     5                 DevExpress.XtraEditors.XtraMessageBox.Show("Download is canceled!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
     6                 return;
     7             }
     8             else
     9             {
    10 
    11                 if (this.lbl_detail.Text == ("DownLoad success.Update now, wait a second!"))
    12                 {
    13                     Thread t = new Thread(//实际上进行更新的方法);
    14                     CheckForIllegalCrossThreadCalls = false;
    15                     t.Start();
    16                 }
    17 
    18             }
    19         }
  • 相关阅读:
    bzoj 1176 cdq分治套树状数组
    Codeforces 669E cdq分治
    Codeforces 1101D 点分治
    Codeforces 1100E 拓扑排序
    Codeforces 1188D Make Equal DP
    Codeforces 1188A 构造
    Codeforces 1188B 式子转化
    Codeforces 1188C DP 鸽巢原理
    Codeforces 1179D 树形DP 斜率优化
    git commit -m "XX"报错 pre -commit hook failed (add --no-verify to bypass)问题
  • 原文地址:https://www.cnblogs.com/JoeyZJ/p/5653252.html
Copyright © 2011-2022 走看看