private async Task DownloadDependency(ModDependencyInfo dependency, IProgress <double> progress, CancellationToken cancellationToken, string token)
        {
            var info = await ModWebsite.GetExtendedInfoAsync(dependency.Name);

            var latestRelease = info.GetLatestRelease(dependency.FactorioVersion);

            if ((dependency.Version != null) && (latestRelease.Version < dependency.Version))
            {
                MessageBox.Show(Window,
                                string.Format(App.Instance.GetLocalizedMessage("DependencyUnavailable", MessageType.Information), dependency.Name, dependency.Version),
                                App.Instance.GetLocalizedMessageTitle("DependencyUnavailable", MessageType.Information),
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                await ModWebsite.DownloadReleaseAsync(latestRelease, GlobalCredentials.Instance.Username, token, progress, cancellationToken, Mods, Modpacks);
            }
        }
        private async Task DownloadSelectedModRelease()
        {
            string token;

            if (GlobalCredentials.Instance.LogIn(Window, out token))
            {
                var progressWindow = new ProgressWindow {
                    Owner = Window
                };
                var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("DownloadingAction");
                progressViewModel.ProgressDescription = string.Format(App.Instance.GetLocalizedResourceString("DownloadingDescription"), selectedRelease.FileName);

                progressViewModel.CanCancel = true;
                var cancellationSource = new CancellationTokenSource();
                progressViewModel.CancelRequested += (sender, e) => cancellationSource.Cancel();

                var progress = new Progress <double>(p => progressViewModel.Progress = p);

                Mod newMod;
                try
                {
                    Task closeWindowTask = null;
                    try
                    {
                        Task <Mod> downloadTask = ModWebsite.DownloadReleaseAsync(selectedRelease,
                                                                                  GlobalCredentials.Instance.Username, token,
                                                                                  progress, cancellationSource.Token, InstalledMods, MainViewModel.Instance.Modpacks);

                        closeWindowTask = downloadTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                        progressWindow.ShowDialog();

                        newMod = await downloadTask;
                    }
                    finally
                    {
                        if (closeWindowTask != null)
                        {
                            await closeWindowTask;
                        }
                    }
                }
                catch (HttpRequestException)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("InternetConnection", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("InternetConnection", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (!cancellationSource.IsCancellationRequested)
                {
                    if (newMod != null)
                    {
                        InstalledMods.Add(newMod);
                    }
                    UpdateSelectedReleases();
                }
            }
        }
示例#3
0
 private async Task DownloadDependency(ModDependencyInfo dependency, IProgress <double> progress, CancellationToken cancellationToken, string token)
 {
     var release = dependency.Release;
     await ModWebsite.DownloadReleaseAsync(release, GlobalCredentials.Instance.Username, token, progress, cancellationToken, Mods, Modpacks);
 }