Пример #1
0
        public async void Download(string line, bool running)
        {
            if (ParseProtocol(line))
            {
                if (await GetData())
                {
                    DownloadWindow downloadWindow = new DownloadWindow(response);
                    downloadWindow.ShowDialog();
                    downloadWindow.Activate();
                    if (downloadWindow.YesNo)
                    {
                        await DownloadFile(URL_TO_ARCHIVE, fileName, new Progress <DownloadProgress>(ReportUpdateProgress),
                                           CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));
                        await ExtractFile($@"{assemblyLocation}\Downloads\{fileName}", response.Game.Replace(" (PC)", ""));

                        if (File.Exists($@"{assemblyLocation}\refresh.aem"))
                        {
                            FileIOWrapper.Delete($@"{assemblyLocation}\refresh.aem");
                        }
                        FileIOWrapper.WriteAllText($@"{assemblyLocation}\refresh.aem", response.Game.Replace(" (PC)", ""));
                    }
                }
            }
            if (running)
            {
                Environment.Exit(0);
            }
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
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);
            }
        }