Example #1
0
        void DownloadCompleted(bool cancelled)
        {
            client.Dispose();
            client = null;

            if (cancelled)
            {
                try
                {
                    OnDownloadCancelled?.Invoke(this, EventArgs.Empty);
                }
                catch { }
                return;
            }

            setting.SendLog(string.Format("{0}", I18N("DownloadCompleted")));
            if (UpdateCore())
            {
                try
                {
                    OnDownloadCompleted?.Invoke(this, EventArgs.Empty);
                }
                catch { }
            }
            else
            {
                try
                {
                    OnDownloadFail?.Invoke(this, EventArgs.Empty);
                }
                catch { }
            }
        }
Example #2
0
        void Download()
        {
            string fileName = _packageName;
            string tpl      = resData("DownloadLinkTpl");
            string url      = string.Format(tpl, _version, fileName);

            Lib.Utils.SupportProtocolTLS12();
            client = new WebClient();

            int preProgress = -100;

            client.DownloadProgressChanged += (s, a) =>
            {
                var percentage = a.ProgressPercentage;

                if (percentage >= 1)
                {
                    var e = new Model.Data.IntEvent(a.ProgressPercentage);
                    try
                    {
                        OnProgress?.Invoke(this, e);
                    }
                    catch { }
                }

                if (percentage - preProgress >= 20)
                {
                    preProgress = percentage;
                    setting.SendLog(string.Format("{0}: {1}%", I18N("DownloadProgress"), percentage));
                }
            };

            client.DownloadFileCompleted += (s, a) =>
            {
                if (a.Cancelled)
                {
                    OnDownloadCancelled?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    setting.SendLog(string.Format("{0}", I18N("DownloadCompleted")));
                    OnDownloadCompleted?.Invoke(this, EventArgs.Empty);
                }
                client.Dispose();
                client = null;
            };

            setting.SendLog(string.Format("{0}:{1}", I18N("Download"), url));
            client.DownloadFileAsync(new Uri(url), fileName);
        }
Example #3
0
        void DownloadCompleted(bool cancelled)
        {
            webClient?.Dispose();
            webClient = null;

            if (cancelled)
            {
                try
                {
                    OnDownloadCancelled?.Invoke(this, EventArgs.Empty);
                }
                catch { }
                return;
            }

            setting.SendLog(string.Format("{0}", I18N.DownloadCompleted));
            UpdateCore();
        }
Example #4
0
 internal void TriggerDownloadCancelledEvent(DownloadDetails details)
 {
     details.UpdateStatus(DownloadDetails.Status.Paused);
     OnDownloadCancelled?.Invoke(this, details);
 }