Exemplo n.º 1
0
        private async Task RemoveSelectedVersion()
        {
            if (MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("RemoveFactorioVersion", MessageType.Question),
                                App.Instance.GetLocalizedMessageTitle("RemoveFactorioVersion", MessageType.Question),
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var progressWindow = new ProgressWindow()
                {
                    Owner = Window
                };
                var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("RemovingFactorioVersionAction");
                progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("DeletingFilesDescription");
                progressViewModel.IsIndeterminate     = true;

                Task deleteTask = Task.Run(() =>
                {
                    SelectedVersion.DeleteLinks();
                    SelectedVersion.Directory.Delete(true);
                });

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

                await deleteTask;
                await closeWindowTask;

                FactorioVersions.Remove(SelectedVersion);
            }
        }
Exemplo n.º 2
0
        private async Task RemoveSelectedVersion()
        {
            if (SelectedVersion == null)
            {
                return;
            }

            if (MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("RemoveFactorioVersion", MessageType.Question),
                                App.Instance.GetLocalizedMessageTitle("RemoveFactorioVersion", MessageType.Question),
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var progressWindow = new ProgressWindow {
                    Owner = Window
                };
                var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("RemovingFactorioVersionAction");
                progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("DeletingFilesDescription");
                progressViewModel.IsIndeterminate     = true;
                progressViewModel.CanCancel           = false;

                Task closeWindowTask = null;
                try
                {
                    Task deleteTask = SelectedVersion.DeleteAsync();

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

                    await deleteTask;
                }
                finally
                {
                    if (closeWindowTask != null)
                    {
                        await closeWindowTask;
                    }
                }

                FactorioVersions.Remove(SelectedVersion);
            }
        }