public void Download(DownloadItemViewModel newDownload)
        {
            if (!AssetCatalog.TryParseDownloadUrl(newDownload.DownloadUrl, out DownloadLocationType type, out string location))
            {
                return;
            }

            switch (type)
            {
            case DownloadLocationType.Url:
                DownloadFileFromUrl(newDownload, location);
                break;


            case DownloadLocationType.GDrive:
                DownloadFileFromGDrive(newDownload, location);
                break;


            case DownloadLocationType.MegaFile:
                DownloadFileFromMega(newDownload, location);

                break;
            }

            newDownload.IsStarted = true;
        }
Example #2
0
        public DownloadItemViewModel Download(string link, string saveFilePath, string description, Action onCancel, Action onComplete)
        {
            DownloadLocationType type;
            string location;

            if (!AssetCatalog.TryParseDownloadUrl(link, out type, out location))
            {
                return(null);
            }

            Action onError = () =>
            {
            };


            DownloadItemViewModel newDownload = new DownloadItemViewModel()
            {
                ItemName      = description,
                OnCancel      = onCancel,
                OnError       = onError,
                OnComplete    = onComplete,
                DownloadSpeed = "Calculating ...",
                DownloadType  = DownloadType.Asset
            };

            switch (type)
            {
            case DownloadLocationType.Url:
                using (var wc = new System.Net.WebClient())
                {
                    newDownload.PerformCancel = () =>
                    {
                        wc.CancelAsync();
                        newDownload.OnCancel?.Invoke();
                    };
                    wc.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                    wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                    wc.DownloadFileAsync(new Uri(location), saveFilePath, newDownload);
                }

                break;

            case DownloadLocationType.GDrive:
                var gd = new GDrive();
                newDownload.PerformCancel = () =>
                {
                    gd.CancelAsync();
                    newDownload.OnCancel?.Invoke();
                };
                gd.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                gd.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                gd.Download(location, saveFilePath, newDownload);
                break;
            }

            newDownload.IsStarted = true;
            return(newDownload);
        }
Example #3
0
        public void Download(DownloadItemViewModel newDownload)
        {
            DownloadLocationType type;
            string location;

            if (!AssetCatalog.TryParseDownloadUrl(newDownload.DownloadUrl, out type, out location))
            {
                return;
            }

            switch (type)
            {
            case DownloadLocationType.Url:
                using (var wc = new System.Net.WebClient())
                {
                    newDownload.PerformCancel = () =>
                    {
                        wc.CancelAsync();
                        newDownload.OnCancel?.Invoke();
                    };
                    wc.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                    wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                    wc.DownloadFileAsync(new Uri(location), newDownload.SaveFilePath, newDownload);
                }

                break;

            case DownloadLocationType.GDrive:
                var gd = new GDrive();
                newDownload.PerformCancel = () =>
                {
                    gd.CancelAsync();
                    newDownload.OnCancel?.Invoke();
                };
                gd.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                gd.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                gd.Download(location, newDownload.SaveFilePath, newDownload);
                break;
            }

            newDownload.IsStarted = true;
        }