Пример #1
0
        private void DownloadDataAsync_Click(object sender, RoutedEventArgs e)
        {
            DownloadWindow downloadWind = new DownloadWindow();

            App.Current.MainWindow = downloadWind;
            this.Close();
            downloadWind.Show();
        }
Пример #2
0
 //获取新版本
 private void GetNewVersion()
 {
     if (LocalVersion == NewVersion)
     {
         MessageBox.Show("你正在使用最新版本!");
     }
     else if (LocalVersion != NewVersion && File.Exists(UpdateXmlPath))
     {
         DownloadWindow DW = new DownloadWindow();
         DW.Show();
     }
 }
Пример #3
0
        private void OnDownloadButtonClick(object sender, RoutedEventArgs e)
        {
            if (AnimeGrid.SelectedItem == null)
            {
                return;
            }
            var anime  = AnimeGrid.SelectedItem as Anime;
            var window = new DownloadWindow(anime, _password, _config);

            window.Show();
            window.StartDownload();
        }
Пример #4
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     progressBar.Value += 1;
     if (progressBar.Value >= 100)
     {
         timer.Stop();
         progressBar.Value = 0;
         DownloadWindow mainWindow = new DownloadWindow();
         mainWindow.Show();
         this.Close();
     }
 }
Пример #5
0
        /// <summary>
        /// 下载
        /// </summary>
        private void DownloadNewversion_()
        {
            DownloadWindow DW = new DownloadWindow();

            DW.Show();
            Download = true;
            //添加下载完成/下载进度事件
            client.DownloadFileCompleted   += new AsyncCompletedEventHandler(Completed);
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            //
            stopwatch.Start();
            // 开始异步下载
            Uri newVersionDownloadURL = new Uri(NewVersionDownloadURL);

            client.DownloadFileAsync(newVersionDownloadURL, CurrentPath + NewVersionFileName + ".zip");
        }
Пример #6
0
        public static void AddDownload(DownloadFileInfo downloadItem)
        {
            DownloadWindow tempWindow = null;

            lock (DownloadWindows)
            {
                if (!DownloadWindows.TryGetValue(downloadItem.Id, out tempWindow))//不在缓存列表
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.FileName = downloadItem.SuggestedFileName;
                    sfd.Filter   = "所有文件|*";

                    var res = sfd.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        tempWindow = new DownloadWindow();
                        var vm = new DownloadItemViewModel()
                        {
                            FullPath      = sfd.FileName,
                            ID            = downloadItem.Id,
                            ReceivedBytes = 0,
                            Url           = downloadItem.Url,
                            TotalBytes    = downloadItem.TotalBytes
                        };
                        tempWindow.Closed += (s, e) =>
                        {
                            tempWindow.DataContext = null;
                            tempWindow.Close();
                            DownloadWindows.TryRemove(downloadItem.Id, out tempWindow);
                        };
                        tempWindow.DataContext = vm;
                        tempWindow.Show();
                        tempWindow.Activate();

                        DownloadWindows.TryAdd(downloadItem.Id, tempWindow);
                    }
                }
            }
        }
Пример #7
0
        protected virtual async Task ShowDownloadWindow(Channel channel)
        {
            var viewModel    = new DownloadWindowViewModel(AppInfo, _logger, RemoteContentDownloader);
            var artifactPath = CreateTempPath(channel.ArtifactUrl);
            var window       = new DownloadWindow {
                DataContext = viewModel
            };

            bool[] finishedDownloading = { false };
            viewModel.ContinueWithInstallationCommand = new DelegateCommand(e =>
            {
                _logger.Log("Continue after downloading artifact");
                _analyticsLogger.LogContinueWithInstallation();
                OnArtifactDownloadedEvent(new SingleEventArgs <string>(artifactPath));
                window.Close();
                if (ShouldOpenArtifact(channel, artifactPath))
                {
                    OpenArtifact(artifactPath);
                    _logger.Log("Opened artifact");
                }
            }, o => finishedDownloading[0]);

            SetOwner(window);
            OnWindowWillBeDisplayed(window, channel);
            window.Show();

            var savedAt = await viewModel.StartAsync(channel, artifactPath).ConfigureAwait(true);

            finishedDownloading[0] = true;
            ((DelegateCommand)viewModel.ContinueWithInstallationCommand).RaiseCanExecuteChanged();

            if (string.IsNullOrWhiteSpace(savedAt))
            {
                window.Close();
                ShowErrorWindow();
            }
        }
Пример #8
0
        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            DownloadWindow DownloadWindow = new DownloadWindow();

            DownloadWindow.Show();
        }
Пример #9
0
        public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
        {
            try
            {
                if (!string.IsNullOrEmpty(downloadItem.FullPath))
                {
                    DownloadWindow tempWindow = null;

                    if (DownloadWindows.TryGetValue(downloadItem.Id, out tempWindow))//存在缓存里
                    {
                        var vm = tempWindow.DataContext as DownloadItemViewModel;
                        vm.ReceivedBytes = downloadItem.ReceivedBytes;
                        vm.TotalBytes    = downloadItem.TotalBytes;

                        if (downloadItem.IsComplete)//删除完成删除
                        {
                            tempWindow.Close();
                            callback.Dispose();
                            DownloadWindows.TryRemove(downloadItem.Id, out tempWindow);
                        }
                    }
                    else
                    {
                        if (CacheList.Count(c => c.ID == downloadItem.Id) > 0)
                        {
                            return;
                        }

                        tempWindow = new DownloadWindow();
                        var vm = new DownloadItemViewModel()
                        {
                            FullPath      = downloadItem.FullPath,
                            ID            = downloadItem.Id,
                            ReceivedBytes = downloadItem.ReceivedBytes,
                            TotalBytes    = downloadItem.TotalBytes,
                            Url           = downloadItem.Url
                        };

                        tempWindow.Closed += (s, e) =>
                        {
                            CacheList.Add(new CacheModel()
                            {
                                ID = downloadItem.Id, AddTime = DateTime.Now
                            });
                            downloadItem.IsCancelled = true;
                            tempWindow.DataContext   = null;
                            tempWindow.Close();
                            callback.Dispose();
                            DownloadWindows.TryRemove(downloadItem.Id, out tempWindow);

                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                if (hideWindow != null)
                                {
                                    hideWindow.Close();
                                }
                            }));
                        };
                        tempWindow.DataContext = vm;
                        tempWindow.Show();
                        tempWindow.Activate();

                        DownloadWindows.TryAdd(downloadItem.Id, tempWindow);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }