示例#1
0
        private void SendMsgHander(DownMsg msg)//下载事件
        {
            int id = msg.Id;

            switch (msg.Tag)       //下载类型
            {
            case DownStatus.Start: //开始下载
                this.Invoke((MethodInvoker) delegate()
                {
                    listView2.Items[id].SubItems[3].Text = "开始下载";
                });
                break;

            case DownStatus.End:                       //下载结束
                this.Invoke((MethodInvoker) delegate() //加入该段可以防止使用方法时的异常
                {
                    if (listView2.Items[id].SubItems[1].Text == "Forge")
                    {
                        listView2.Items[id].SubItems[3].Text = "安装中";
                        try
                        {
                            if (tools.ForgeInstallation(intall, intallverison, java.Text))    //forge安装
                            {
                                MessageBox.Show("Forge安装成功");
                            }
                        }
                        catch (SikaDeerLauncher.SikaDeerLauncherException ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    listView2.Items[id].SubItems[3].Text = "下载完成";
                });
                break;

            case DownStatus.DownLoad:         //下载中
                this.Invoke((MethodInvoker) delegate()
                {
                    listView2.Items[id].SubItems[2].Text = msg.Progress.ToString() + "%"; //下载进度
                    listView2.Items[id].SubItems[4].Text = msg.SpeedInfo;                 //速度
                    listView2.Items[id].SubItems[3].Text = "下载中";
                });
                break;

            case DownStatus.Error:        //下载错误
                this.Invoke((MethodInvoker) delegate()
                {
                    listView2.Items[id].SubItems[3].Text = msg.ErrMessage;    //下载错误提示
                    Application.DoEvents();
                });
                break;
            }
        }
示例#2
0
        private void SendMsgHander(DownMsg msg)
        {
            switch (msg.Tag)
            {
            case DownStatus.Start:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView.Items[msg.Id].SubItems[8].Text = "开始下载";
                    listView.Items[msg.Id].SubItems[7].Text = DateTime.Now.ToString();
                });
                break;

            case DownStatus.GetLength:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView.Items[msg.Id].SubItems[3].Text = msg.LengthInfo;
                    listView.Items[msg.Id].SubItems[8].Text = "连接成功";
                });
                break;

            case DownStatus.End:
            case DownStatus.DownLoad:
                this.Invoke(new MethodInvoker(() =>
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        listView.Items[msg.Id].SubItems[4].Text = msg.Progress.ToString() + "%";
                        listView.Items[msg.Id].SubItems[5].Text = msg.SpeedInfo;
                        listView.Items[msg.Id].SubItems[6].Text = msg.SurplusInfo;
                        if (msg.Tag == DownStatus.DownLoad)
                        {
                            listView.Items[msg.Id].SubItems[8].Text = "下载中";
                        }
                        else
                        {
                            listView.Items[msg.Id].SubItems[8].Text = "下载完成";
                        }
                        Application.DoEvents();
                    });
                }));
                break;

            case DownStatus.Error:
                this.Invoke((MethodInvoker) delegate()
                {
                    listView.Items[msg.Id].SubItems[6].Text = "失败";
                    listView.Items[msg.Id].SubItems[8].Text = msg.ErrMessage;
                    Application.DoEvents();
                });
                break;
            }
        }
示例#3
0
        private void SendMsgHander(DownMsg msg)
        {
            DownStatus tag = msg.Tag;

            if (tag != DownStatus.End)
            {
                if (tag != DownStatus.Error)
                {
                    return;
                }
            }
            else
            {
                Console.WriteLine(Complete);
                Complete++;
                return;
            }
            Failure++;
        }
示例#4
0
        /// <summary>
        /// 下载文件回调
        /// </summary>
        /// <param name="msg">消息字符串</param>
        private void SendMsgHander(DownMsg msg)
        {
            switch (msg.Tag)
            {
            case DownStatus.Start:
                Console.WriteLine("开始下载:" + DateTime.Now.ToString());
                ActiveUpdataInfo(EnumUpdataStatus.DownloadFile, "正在连接服务器");
                break;

            case DownStatus.GetLength:
                Console.WriteLine("连接成功:" + msg.LengthInfo);
                ActiveUpdataInfo(EnumUpdataStatus.DownloadFile, "连接成功");
                break;

            case DownStatus.DownLoad:
                if (msg.Tag == DownStatus.DownLoad)
                {
                    Console.Write("下载中:");
                    ActiveUpdataInfo(EnumUpdataStatus.DownloadFile, "下载中" + msg.Progress.ToString() + "%");
                    //proUpdata.Value = Convert.ToInt32(msg.Progress);
                }
                else
                {
                    Console.Write("下载完成:");
                    ActiveUpdataInfo(EnumUpdataStatus.DownloadFile, "下载完成!");
                    //proUpdata.Value = proUpdata.Maximum;
                    isRunStart = false;
                }
                Console.WriteLine(msg.SizeInfo + "\t" + msg.Progress.ToString() + "%\t" + msg.SpeedInfo + "\t" + msg.SurplusInfo);
                break;

            case DownStatus.End:
                Console.WriteLine("下载完成!!!");
                ActiveUpdataInfo(EnumUpdataStatus.DownloadFile, "下载完成!");

                //开始更新
                if (File.Exists(strDownFilePath))
                {
                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    try
                    {
                        //解压缩文件
                        ActiveUpdataInfo(EnumUpdataStatus.Updata, "解压缩文件中");

                        //ZipFile.ExtractToDirectory(strDownFilePath, System.AppDomain.CurrentDomain.BaseDirectory);
                        ZipHelper.UnZip(strDownFilePath, System.AppDomain.CurrentDomain.BaseDirectory, "", true);

                        //删除压缩包
                        File.Delete(strDownFilePath);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("更新压缩包操作错误:" + ex.Message);
                        ActiveUpdataInfo(EnumUpdataStatus.Error, "更新压缩包操作错误:" + ex.Message);
                    }
                    watch.Stop();
                    TimeSpan timespan = watch.Elapsed;
                    Console.WriteLine("解压缩执行时间:{0}(毫秒)", timespan.TotalMilliseconds);      //总毫秒数

                    Console.WriteLine("更新完成");
                    ActiveUpdataInfo(EnumUpdataStatus.Done, "更新完成");
                    if (IsAutoRun)
                    {
                        string strRunPath = System.AppDomain.CurrentDomain.BaseDirectory + Run;
                        if (File.Exists(strRunPath))
                        {
                            try
                            {
                                System.Diagnostics.Process.Start(strRunPath);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    isRunStart = false;
                }
                break;

            case DownStatus.Error:
                ActiveUpdataInfo(EnumUpdataStatus.Error, "下载失败:" + msg.ErrMessage);
                Console.WriteLine("下载失败:" + msg.ErrMessage);
                isRunStart = false;
                break;

            default:
                isRunStart = false;
                break;
            }
        }
示例#5
0
        private void SendMsgHander(DownMsg msg)
        {
            switch (msg.Tag)
            {
            case DownStatus.Start:
                this.Invoke((MethodInvoker) delegate()
                {
                    Console.WriteLine("开始下载:" + DateTime.Now.ToString());
                    labelInfo.Text = "正在连接服务器";
                });
                break;

            case DownStatus.GetLength:
                this.Invoke((MethodInvoker) delegate()
                {
                    Console.WriteLine("连接成功:" + msg.LengthInfo);
                    labelInfo.Text = "连接成功";
                });
                break;

            case DownStatus.DownLoad:
                this.Invoke(new MethodInvoker(() =>
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        if (msg.Tag == DownStatus.DownLoad)
                        {
                            Console.Write("下载中:");
                            labelInfo.Text  = "下载中" + msg.Progress.ToString() + "%";
                            proUpdata.Value = Convert.ToInt32(msg.Progress);
                        }
                        else
                        {
                            Console.Write("下载完成:");
                            proUpdata.Value = proUpdata.Maximum;
                        }
                        Console.WriteLine(msg.SizeInfo + "\t" + msg.Progress.ToString() + "%\t" + msg.SpeedInfo + "\t" + msg.SurplusInfo);
                        Application.DoEvents();
                    });
                }));
                break;

            case DownStatus.End:
                this.Invoke((MethodInvoker) delegate()
                {
                    Console.WriteLine("下载完成!!!");
                    labelInfo.Text  = "下载完成";
                    proUpdata.Value = proUpdata.Maximum;
                    //System.Diagnostics.Process.Start(strDownFilePath);
                });
                //开始更新
                if (File.Exists(strDownFilePath))
                {
                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    try
                    {
                        //解压缩文件
                        //ZipFile.ExtractToDirectory(strDownFilePath, System.AppDomain.CurrentDomain.BaseDirectory);
                        ZipHelper.UnZip(strDownFilePath, System.AppDomain.CurrentDomain.BaseDirectory, "", true);

                        //删除压缩包
                        File.Delete(strDownFilePath);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("更新压缩包操作错误:" + ex.Message);
                    }
                    watch.Stop();
                    TimeSpan timespan = watch.Elapsed;
                    Console.WriteLine("解压缩执行时间:{0}(毫秒)", timespan.TotalMilliseconds);      //总毫秒数
                    this.Invoke((MethodInvoker) delegate()
                    {
                        Console.WriteLine("更新完成");
                        labelInfo.Text  = "更新完成";
                        proUpdata.Value = proUpdata.Maximum;
                        if (MessageBox.Show("是否运行更新后的程序?", "更新完成", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "BleTestTool.exe");
                        }
                        Application.Exit();
                    });
                }
                break;

            case DownStatus.Error:
                this.Invoke((MethodInvoker) delegate()
                {
                    Console.WriteLine("下载失败:" + msg.ErrMessage);
                    labelInfo.Text = "下载失败:" + msg.ErrMessage;
                });
                break;

            default:
                break;
            }
        }