Ejemplo n.º 1
0
 private void DeleteDownload(object obj)
 {
     if (obj is DownloadItemViewModel item)
     {
         Downloads.Remove(item);
     }
 }
Ejemplo n.º 2
0
        private void DeleteDownload()
        {
            if (!DownloadStatus.Equals("Complete"))
            {
                string sMessageBoxText = "Attempting to delete incomplete download. Continue?";
                string sCaption        = "Incomplete Download!";

                MessageBoxButton btnMessageBox = MessageBoxButton.YesNoCancel;
                MessageBoxImage  icnMessageBox = MessageBoxImage.Warning;

                MessageBoxResult rsltMessageBox = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);

                switch (rsltMessageBox)
                {
                case MessageBoxResult.Yes:
                    Downloads.Remove(this);
                    break;

                case MessageBoxResult.No:
                    /* ... */
                    break;

                case MessageBoxResult.Cancel:
                    /* ... */
                    break;
                }
            }
            else
            {
                Downloads.Remove(this);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Timer_Tick(object sender, EventArgs e)
        {
            if (Current != null)
            {
                // ダウンロード中データが存在する場合は中断
                return;
            }
            if (!Downloads.Any())
            {
                // ステータス完了状態に移行
                IsDownloding = false;
                Message      = "";

                // ダウンロード待ちが存在しない場合は中断
                return;
            }

            // ダウンロード中に設定
            Current = Downloads.First();
            Downloads.Remove(Current);

            // ステータス更新
            IsDownloding = true;
            Message      = string.Format("ID:{0} ダウンロード中 / {1} ファイル ダウンロード待ち ", Current.VideoId, Downloads.Count());

            // ダウンロード開始
            await Download(Current);

            Current = null;
        }
Ejemplo n.º 4
0
 public void RemoveDownload(Download download)
 {
     lock (Downloads)
     {
         Downloads.Remove(download);
     }
 }
Ejemplo n.º 5
0
        public void RefreshDownloads()
        {
            var downloads = DownloadManager.GetDownloads();

            foreach (var download in downloads)
            {
                var existingDownload = Downloads.FirstOrDefault(d => d.Id == download.Id);

                if (existingDownload != null)
                {
                    existingDownload.UpdateValues(download);
                }
                else
                {
                    Downloads.Add(new DownloadViewModel(download));
                }
            }

            var nonExistantDownloads = new List <DownloadViewModel>();

            foreach (var nonExistantDownload in Downloads.Where(d => !downloads.Any(existinDownload => existinDownload.Id == d.Id)))
            {
                nonExistantDownloads.Add(nonExistantDownload);
            }

            foreach (var toRemove in nonExistantDownloads)
            {
                Downloads.Remove(toRemove);
            }
        }
Ejemplo n.º 6
0
        public bool RemoveDownload(Download download)
        {
            if (!CanRemoveDownload(download))
            {
                return(false);
            }

            download.PropertyChanged -= Download_PropertyChanged;
            Downloads.Remove(download);

            FirePropertyChanged(nameof(TotalDownloads));

            // Update download indices
            int index = download.Index;

            foreach (Download dl in downloads.OrderBy(x => x.Index))
            {
                if (dl.Index > download.Index)
                {
                    dl.Index = index++;
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        private void DownloadSort(TransferObjectModel transferObject)
        {
            if (Downloads.Contains(transferObject))
            {
                if (!Downloads.Remove(transferObject))
                {
                    return;
                }
            }

            var inserted = false;

            for (var i = 0; i <= Downloads.Count - 1; i++)
            {
                if ((int)transferObject.Status <= (int)Downloads[i].Status)
                {
                    Downloads.Insert(i, transferObject);
                    inserted = true;
                    break;
                }
            }

            if (!inserted)
            {
                Downloads.Add(transferObject);
            }
        }
Ejemplo n.º 8
0
        private void SteamWorkshop_OnItemDownloaded(object sender, Workshop.DownloadItemEventArgs e)
        {
            if (e.Result.m_eResult != EResult.k_EResultOK)
            {
                MessageBox.Show($"{e.Result.m_nPublishedFileId}: {e.Result.m_eResult}");
                return;
            }

            var m = Downloads.SingleOrDefault(x => x.WorkshopID == (long)e.Result.m_nPublishedFileId.m_PublishedFileId);

            if (m != null)
            {
                // Fill fields
                m.RemoveState(ModState.NotInstalled);
                m.RealizeIDAndPath(m.Path);
                m.Image = null; // Use default image again

                // load info
                var info = new ModInfo(m.GetModInfoFile());

                // Move mod
                Downloads.Remove(m);
                Mods.AddMod(info.Category, m);

                // update listitem
                //var item = modlist_listview.Items.Cast<ListViewItem>().Single(i => (i.Tag as ModEntry).SourceID == m.SourceID);
                //UpdateModListItem(item, info.Category);
            }
            m = Mods.All.Single(x => x.WorkshopID == (long)e.Result.m_nPublishedFileId.m_PublishedFileId);

            MessageBox.Show($"{m.Name} finished download.");
        }
Ejemplo n.º 9
0
        public async Task RemoveDownload(DownloadItem download)
        {
            download.StatusChanged -= downloadItem_StatusChanged;
            await download.Stop();

            Downloads.Remove(download);
        }
Ejemplo n.º 10
0
 private void CancelCommandExecute(DownloadItem param)
 {
     if (_dialogService.Confirm("Are you sure you want to cancel download?", "Part of the ship, part of the crew"))
     {
         param.CancelDownload();
         Downloads.Remove(param);
     }
 }
Ejemplo n.º 11
0
        private void DownloadViewModel_RemoveFromCollection(object sender, EventArgs <DownloadedChapterInfo> eventArgs)
        {
            var downloadViewModel = (DownloadViewModel)sender;

            downloadViewModel.RemoveFromCollection -= DownloadViewModel_RemoveFromCollection;
            downloadViewModel.DownloadStarted      -= DownloadViewModel_DownloadStarted;
            downloadViewModel.DownloadCompleted    -= DownloadViewModel_DownloadCompleted;

            Downloads.Remove(downloadViewModel);

            ServiceLocator.Instance.GetService <ILibraryManager>().RemoveDownloadInfo(eventArgs.Value);
        }
Ejemplo n.º 12
0
        private void NextSequenceItem(Download download)
        {
            lock (Downloads)
            {
                if (download != null)
                {
                    download.DownloadFileCompleted -= SequanceDownloadCompleted;
                    Downloads.Remove(download);
                }
            }

            TakeSequanceItem();
        }
Ejemplo n.º 13
0
        public bool RemoveDownload(Download download)
        {
            if (!CanRemoveDownload(download))
            {
                return(false);
            }

            download.PropertyChanged -= Download_PropertyChanged;
            Downloads.Remove(download);

            FirePropertyChanged(nameof(TotalDownloads));

            return(true);
        }
Ejemplo n.º 14
0
        private async void OnDownloadProgressChanged(object sender, TransferItem e)
        {
            await _dispatcherWrapper.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (DownloadsState == ContentState.Loading)
                {
                    return;
                }

                DownloadsState = ContentState.Normal;
                var item       = Downloads.FirstOrDefault(d => d.OperationGuid == e.OperationGuid);
                if (item == null)
                {
                    if (e.Status != BackgroundTransferStatus.Completed &&
                        e.Status != BackgroundTransferStatus.Canceled)
                    {
                        return;
                    }

                    Downloads.Add(new TransferItemViewModel(e, _locService));
                    item = Downloads.FirstOrDefault(d => d.OperationGuid == e.OperationGuid);
                    if (item == null)
                    {
                        return;
                    }
                }
                else
                {
                    item.Operation = e;
                }

                if (item.Status == BackgroundTransferStatus.Completed ||
                    item.Status == BackgroundTransferStatus.Canceled)
                {
                    Downloads.Remove(item);
                }

                if (Downloads.Count == 0)
                {
                    DownloadsState = ContentState.NoData;
                }
                else
                {
                    Downloads.OrderBy(d => d.Status, new TransferStatusComparer());
                }

                CancelAllDownloadsCommand.RaiseCanExecuteChanged();
            });
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Allows for async
        /// </summary>
        private void download()
        {
            foreach (FileDownload download in Downloads.ToList())
            {
                if (!download.IsChecked)
                {
                    Downloads.Remove(download);
                    continue;
                }

                download.StartDownload();
            }

            CanDownload = false;
        }
Ejemplo n.º 16
0
        private void DownloadCommandExecute()
        {
            var item = new DownloadItem(
                DownloadUri.Value,
                Path.GetRandomFileName()
                );

            Downloads.Add(item);
            try {
                item.StartDownload();
            } catch (Exception ex) {
                _dialogService.Error($"Error: {ex.Message}", "Download error");
                Downloads.Remove(item);
            }

            DownloadUri.Value = null;
        }
Ejemplo n.º 17
0
        private void AddDownload(DownloadViewModel download)
        {
            // Find an existing download for this file path
            var existingDownload = Downloads.FirstOrDefault(d => d.FilePath == download.FilePath);

            // If it exists - cancel and remove it
            if (existingDownload != null)
            {
                if (existingDownload.CanCancel)
                {
                    existingDownload.Cancel();
                }

                Downloads.Remove(existingDownload);
            }

            // Add to the beginning
            Downloads.Insert(0, download);
        }
Ejemplo n.º 18
0
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnCollectionChanged(e);

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (var item in e.NewItems)
                {
                    var transferObject = (TransferObjectModel)item;

                    switch (transferObject.Type)
                    {
                    case TransferType.Download:
                        DownloadSort(transferObject);
                        break;

                    case TransferType.Upload:
                        UploadSort(transferObject);
                        break;
                    }
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var item in e.OldItems)
                {
                    var transferObject = (TransferObjectModel)item;

                    switch (transferObject.Type)
                    {
                    case TransferType.Download:
                        Downloads.Remove(transferObject);
                        break;

                    case TransferType.Upload:
                        Uploads.Remove(transferObject);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private void SteamWorkshop_OnItemDownloaded(object sender, Workshop.DownloadItemEventArgs e)
        {
            if (e.Result.m_eResult != EResult.k_EResultOK)
            {
                MessageBox.Show($"{e.Result.m_nPublishedFileId}: {e.Result.m_eResult}");
                return;
            }

            var m = Downloads.SingleOrDefault(x => x.WorkshopID == (long)e.Result.m_nPublishedFileId.m_PublishedFileId);

            if (m != null)
            {
                // look for .XComMod file
                var infoFile = Directory.GetFiles(m.Path, "*.XComMod", SearchOption.TopDirectoryOnly).SingleOrDefault();
                if (infoFile == null)
                {
                    throw new Exception("Invalid Download");
                }

                // Fill fields
                m.State &= ~ModState.NotInstalled;
                m.ID     = Path.GetFileNameWithoutExtension(infoFile);
                m.Image  = null; // Use default image again

                // load info
                var info = new ModInfo(m.GetModInfoFile());

                // Move mod
                Downloads.Remove(m);
                Mods.AddMod(info.Category, m);

                // update listitem
                //var item = modlist_listview.Items.Cast<ListViewItem>().Single(i => (i.Tag as ModEntry).SourceID == m.SourceID);
                //UpdateModListItem(item, info.Category);
            }
            m = Mods.All.Single(x => x.WorkshopID == (long)e.Result.m_nPublishedFileId.m_PublishedFileId);

            MessageBox.Show($"{m.Name} finished download.");
        }
Ejemplo n.º 20
0
 public void ClearCompletedDownloads()
 {
     Downloads.Where((x) => x.DownloadState == PackageDownloadHandle.State.Installed ||
                     x.DownloadState == PackageDownloadHandle.State.Error).ToList().ForEach(x => Downloads.Remove(x));
 }
Ejemplo n.º 21
0
 public void CancelDownload(Download download)
 {
     download.Cancel();
     Downloads.Remove(download);
     download.Queue.RemoveDownload(download);
 }
Ejemplo n.º 22
0
 public static void RemoveDownload(Download dl)
 {
     dl.Stop();
     Downloads.Remove(dl);
 }
Ejemplo n.º 23
0
        private void DownloaderEvent(object sender, EventArgs e)
        {
            switch (e)
            {
            case DownloadItemAddedEventArgs downloadItemAddedEvent:
                DownloadItemViewModel newDownloadItemViewModel = ToDownloadItemViewModel(downloadItemAddedEvent.AddedDownloadItem);
                downloadDictionary[newDownloadItemViewModel.Id] = newDownloadItemViewModel;
                ExecuteInUiThread(() =>
                {
                    Downloads.Add(newDownloadItemViewModel);
                    UpdateNonSelectionButtonStates();
                });
                break;

            case DownloadItemChangedEventArgs downloadItemChangedEvent:
                DownloadItem          changedDownloadItem          = downloadItemChangedEvent.ChangedDownloadItem;
                DownloadItemViewModel changedDownloadItemViewModel = downloadDictionary[changedDownloadItem.Id];
                bool statusChanged = changedDownloadItemViewModel.Status != changedDownloadItem.Status;
                ExecuteInUiThread(() =>
                {
                    changedDownloadItemViewModel.Name = changedDownloadItem.FileName;
                    if (statusChanged)
                    {
                        changedDownloadItemViewModel.Status = changedDownloadItem.Status;
                    }
                    changedDownloadItemViewModel.ProgressText  = GetDownloadProgressText(changedDownloadItem);
                    changedDownloadItemViewModel.ProgressValue = GetDownloadProgressValue(changedDownloadItem);
                    if (statusChanged)
                    {
                        if (changedDownloadItemViewModel.IsSelected)
                        {
                            UpdateSelectionButtonStates();
                        }
                        UpdateNonSelectionButtonStates();
                    }
                });
                break;

            case DownloadItemRemovedEventArgs downloadItemRemovedEvent:
                DownloadItem          removedDownloadItem          = downloadItemRemovedEvent.RemovedDownloadItem;
                DownloadItemViewModel removedDownloadItemViewModel = downloadDictionary[removedDownloadItem.Id];
                ExecuteInUiThread(() =>
                {
                    bool isSelected = removedDownloadItemViewModel.IsSelected;
                    Downloads.Remove(removedDownloadItemViewModel);
                    if (isSelected)
                    {
                        UpdateSelectionButtonStates();
                    }
                    UpdateNonSelectionButtonStates();
                });
                break;

            case DownloadItemLogLineEventArgs downloadItemLogLineEvent:
                DownloadItemViewModel downloadItemViewModel = downloadDictionary[downloadItemLogLineEvent.DownloadItemId];
                if (downloadItemLogLineEvent.LineIndex >= downloadItemViewModel.Logs.Count)
                {
                    ExecuteInUiThread(() => downloadItemViewModel.Logs.Add(ToDownloadItemLogLineViewModel(downloadItemLogLineEvent.LogLine)));
                }
                break;
            }
        }