⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloading.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc
{
    using Imps.Client.Pc.BizControls;
    using Imps.Client.Pc.Controls;
    using Imps.Client.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Threading;
    using System.Windows.Forms;

    public class Downloading : XIMDialog
    {
        private long _downloaded;
        private Downloader _downloader = new Downloader();
        private Thread _downloadThread;
        private string _downloadUrl;
        private IFrameworkWindow _mainWnd;
        private UpdateInfo _updateInfo;
        private WorkPathInfo _workPath = new WorkPathInfo();
        private XButton buttonCancel;
        private IContainer components;
        private ProgressBar downloadProgress;
        private LinkLabel lDownloadURL;
        private Label lMessage;
        private Panel panel1;

        internal Downloading(UpdateInfo updateInfo, IFrameworkWindow mainWnd, string downloadUrl)
        {
            this.InitializeComponent();
            this._mainWnd = mainWnd;
            this._updateInfo = updateInfo;
            this._downloadUrl = downloadUrl;
            this.downloadProgress.Maximum = 100;
            this.downloadProgress.Value = 0;
            this._downloader.PartDownloaded += new EventHandler<PartDownloadedEventArgs>(this.downloader_PartDownloaded);
            this._downloader.EndDownload += new EventHandler<EndDownloadedEventArgs>(this.downloader_EndDownload);
            this.lDownloadURL.Text = this._downloadUrl;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult result;
            lock (this._downloader.DownloadLocker)
            {
                result = MessageBox.Show("更新正在进行中,您确定要退出吗?", "退出更新", MessageBoxButtons.OKCancel);
            }
            if (result == DialogResult.OK)
            {
                if (this._downloadThread != null)
                {
                    this._downloadThread.Abort();
                }
                base.DialogResult = DialogResult.No;
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void downloader()
        {
            try
            {
                string fullPath = StaticTools.GetFullPath(this._workPath.ClientUpdateFile);
                this._downloader.Download(this._downloadUrl, fullPath);
            }
            catch
            {
            }
        }

        private void downloader_EndDownload(object sender, EndDownloadedEventArgs e)
        {
            this.downloadProgress.Value = 100;
            if (e.IsComplete)
            {
                base.DialogResult = DialogResult.Yes;
                base.Close();
            }
            else
            {
                using (DownloadError error = new DownloadError(this._updateInfo, this._mainWnd, this._downloadUrl))
                {
                    if (error.ShowDialog() == DialogResult.Yes)
                    {
                        this._downloaded = 0L;
                        this.downloadProgress.Value = 0;
                        base.Activate();
                        this.StartDownloader();
                        return;
                    }
                }
                base.DialogResult = DialogResult.No;
            }
        }

        private void downloader_PartDownloaded(object sender, PartDownloadedEventArgs e)
        {
            try
            {
                this._downloaded += e.Size;
                this.downloadProgress.Value = (int) ((this._downloaded * 100L) / this._updateInfo.Size);
            }
            catch
            {
                this.downloadProgress.Value = 100;
            }
        }

        private void Downloading_Load(object sender, EventArgs e)
        {
            this.StartDownloader();
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(Downloading));
            this.downloadProgress = new ProgressBar();
            this.buttonCancel = new XButton();
            this.lMessage = new Label();
            this.lDownloadURL = new LinkLabel();
            this.panel1 = new Panel();
            this.panel1.SuspendLayout();
            base.SuspendLayout();
            this.downloadProgress.Location = new Point(12, 0x3e);
            this.downloadProgress.Name = "downloadProgress";
            this.downloadProgress.Size = new Size(410, 0x17);
            this.downloadProgress.TabIndex = 0;
            this.downloadProgress.Value = 50;
            this.buttonCancel.Location = new Point(0x1b6, 0x3e);
            this.buttonCancel.Name = "buttonCancel";
            this.buttonCancel.Size = new Size(0x4b, 0x17);
            this.buttonCancel.TabIndex = 1;
            this.buttonCancel.Text = "退出";
            this.buttonCancel.UseVisualStyleBackColor = true;
            this.buttonCancel.Click += new EventHandler(this.buttonCancel_Click);
            this.lMessage.AutoSize = true;
            this.lMessage.Location = new Point(12, 13);
            this.lMessage.Name = "lMessage";
            this.lMessage.Size = new Size(0x10f, 13);
            this.lMessage.TabIndex = 2;
            this.lMessage.Text = "如果下载速度缓慢,您可以自行到以下网址下载:";
            this.lDownloadURL.AutoSize = true;
            this.lDownloadURL.Location = new Point(12, 0x24);
            this.lDownloadURL.Name = "lDownloadURL";
            this.lDownloadURL.Size = new Size(0x4d, 13);
            this.lDownloadURL.TabIndex = 3;
            this.lDownloadURL.TabStop = true;
            this.lDownloadURL.Text = "DownloadURL";
            this.lDownloadURL.LinkClicked += new LinkLabelLinkClickedEventHandler(this.lDownloadURL_LinkClicked);
            this.panel1.BackColor = Color.Transparent;
            this.panel1.Controls.Add(this.lMessage);
            this.panel1.Controls.Add(this.lDownloadURL);
            this.panel1.Controls.Add(this.downloadProgress);
            this.panel1.Controls.Add(this.buttonCancel);
            this.panel1.Dock = DockStyle.Fill;
            this.panel1.Location = new Point(6, 0x19);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x215, 120);
            this.panel1.TabIndex = 4;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x22e, 0x99);
            base.Controls.Add(this.panel1);
            base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "Downloading";
            base.Padding = new Padding(6, 0x19, 0x13, 8);
            base.StartPosition = FormStartPosition.CenterScreen;
            base.Text = "正在下载更新";
            base.Load += new EventHandler(this.Downloading_Load);
            base.Controls.SetChildIndex(this.panel1, 0);
            base.Controls.SetChildIndex(base.menubar, 0);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void lDownloadURL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ShellHelper.StartUrl(this._downloadUrl);
        }

        private void StartDownloader()
        {
            this._downloadThread = new Thread(new ThreadStart(this.downloader));
            this._downloadThread.Start();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -