コード例 #1
0
        private async void Restore_Click(object sender, RoutedEventArgs e)
        {
            var item = ((WorldSaveFile)((Button)e.Source).DataContext);

            if (item == null)
            {
                return;
            }

            var restoreAll = true;

            if (item.IsArchiveFile)
            {
                var confirmationMessage = _globalizer.GetResourceString("WorldSaveRestore_RestoreConfirmationFullLabel");
                confirmationMessage = confirmationMessage.Replace("{fileName}", item.FileName);
                var result = MessageBox.Show(this, confirmationMessage, _globalizer.GetResourceString("WorldSaveRestore_RestoreConfirmationTitle"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
                restoreAll = result == MessageBoxResult.Yes;
            }
            else
            {
                var confirmationMessage = _globalizer.GetResourceString("WorldSaveRestore_RestoreConfirmationLabel");
                confirmationMessage = confirmationMessage.Replace("{fileName}", item.FileName);
                if (MessageBox.Show(this, confirmationMessage, _globalizer.GetResourceString("WorldSaveRestore_RestoreConfirmationTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            var cursor = this.Cursor;

            try
            {
                Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait);
                await Task.Delay(500);

                var restoredFileCount = _profile.RestoreSaveFiles(item.File, item.IsArchiveFile, restoreAll);

                var successMessage = _globalizer.GetResourceString("WorldSaveRestore_RestoreSuccessLabel");
                successMessage = successMessage.Replace("{fileCount}", restoredFileCount.ToString());
                MessageBox.Show(this, successMessage, _globalizer.GetResourceString("WorldSaveRestore_RestoreSuccessTitle"), MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, _globalizer.GetResourceString("WorldSaveRestore_RestoreErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                await LoadWorldSaveFiles();

                Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor);
            }
        }
        private async void Restore_Click(object sender, RoutedEventArgs e)
        {
            var item = ((WorldSaveFile)((Button)e.Source).DataContext);

            if (item == null)
            {
                return;
            }

            var restoreAll = true;

            if (item.IsArchiveFile)
            {
                var message = $"You are about to restore backup file\r\n{item.FileName}.\r\n\r\nSelect Yes to restore the world save, player and tribe files.\r\nSelect No to only restore the world save.\r\nSelect Cancel to quit the restore.";
                var result  = MessageBox.Show(this, message, "Restore Backup Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
                restoreAll = result == MessageBoxResult.Yes;
            }
            else
            {
                var message = $"You are about to restore backup file\r\n{item.FileName}.\r\n\r\nDo you want to continue?";
                if (MessageBox.Show(this, message, "Restore Backup Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            var cursor = this.Cursor;

            try
            {
                Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait);
                await Task.Delay(500);

                var restoredFileCount = _profile.RestoreSaveFiles(item.File, item.IsArchiveFile, restoreAll);

                MessageBox.Show(this, $"The backup file has been restored, {restoredFileCount} file(s) restored.", "Restore Backup Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Restore Backup Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                await LoadWorldSaveFiles();

                Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor);
            }
        }