Esempio n. 1
0
        private void DeleteReplayFile_OnClick(object sender, RoutedEventArgs e)
        {
            if (!(Window.GetWindow(this)?.DataContext is MainWindowViewModel context))
            {
                return;
            }
            if (!(this.DataContext is ReplayPreview replay))
            {
                return;
            }

            // create the flyout
            var flyout = FlyoutHelper.CreateFlyout(includeButton: true, includeCustom: false);

            // set the flyout texts
            flyout.SetFlyoutButtonText(TryFindResource("DeleteReplayFile") as String);
            flyout.SetFlyoutLabelText(TryFindResource("DeleteFlyoutLabel") as String);

            // set button click function
            flyout.GetFlyoutButton().Click += async(object eSender, RoutedEventArgs eConfirm) =>
            {
                await context.DeleteReplayFile(replay).ConfigureAwait(false);

                // Hide the flyout
                this.Dispatcher.Invoke(() =>
                {
                    flyout.Hide();
                });
            };

            // Show the flyout and focus it
            flyout.ShowAt(FilenameText);
            flyout.GetFlyoutButton().Focus();
        }
        private void RemoveExecutableButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(this.DataContext is SettingsManager context))
            {
                return;
            }
            if (!(ExecutablesListBox.SelectedItem is LeagueExecutable selectedExecutable))
            {
                return;
            }
            ;

            // Create confirmation flyout
            var confirmFlyout = FlyoutHelper.CreateFlyout();

            confirmFlyout.SetFlyoutLabelText(TryFindResource("ConfirmText") as String);
            confirmFlyout.SetFlyoutButtonText(TryFindResource("YesText") as String);

            confirmFlyout.GetFlyoutButton().Click += (object eSender, RoutedEventArgs eConfirm) =>
            {
                context.Executables.DeleteExecutable(selectedExecutable.Name);

                EditExecutableButton.IsEnabled   = false;
                RemoveExecutableButton.IsEnabled = false;
                confirmFlyout.Hide();
            };

            // Show the flyout
            confirmFlyout.ShowAt(RemoveExecutableButton);
        }
        private void SaveButton_Click(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (!(DataContext is ExecutableManager context))
            {
                return;
            }

            // Reset error
            _blockClose = false;

            if (_executable == null)
            {
                _blockClose = true;

                // show fly out
                Flyout flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as string);
                flyout.ShowAt(TargetTextBox);

                return;
            }

            try
            {
                _executable.Name       = NameTextBox.Text;
                _executable.TargetPath = TargetTextBox.Text;

                string locale = LocaleComboBox.SelectedItem as string;

                if ((LocaleComboBox.SelectedItem as string) == LeagueLocale.Custom.ToString())
                {
                    _executable.Locale       = LeagueLocale.Custom;
                    _executable.CustomLocale = CustomLocaleTextBox.Text;
                }
                else
                {
                    _executable.Locale = ExeTools.GetLocaleEnum((LocaleComboBox.SelectedItem as string).Split('(', ')')[1]);
                }

                if (_isEditMode)
                {
                    Hide();
                }
                else
                {
                    context.AddExecutable(_executable);
                }

                Hide();
            }
            catch (Exception)
            {
                _blockClose = true;

                // show fly out
                Flyout flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("ExecutableSaveNullText") as string);
                flyout.ShowAt(TargetTextBox);
            }
        }
        private void RemoveKnownPlayerButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(this.DataContext is SettingsManager context))
            {
                return;
            }
            if (!(KnownPlayersListBox.SelectedItem is PlayerMarker selectedPlayer))
            {
                return;
            }

            // Create confirmation flyout
            var confirmFlyout = FlyoutHelper.CreateFlyout();

            confirmFlyout.SetFlyoutLabelText(TryFindResource("ConfirmText") as String);
            confirmFlyout.SetFlyoutButtonText(TryFindResource("YesText") as String);

            confirmFlyout.GetFlyoutButton().Click += (object eSender, RoutedEventArgs eConfirm) =>
            {
                context.Settings.KnownPlayers.Remove(selectedPlayer);

                EditKnownPlayerButton.IsEnabled   = false;
                RemoveKnownPlayerButton.IsEnabled = false;
                confirmFlyout.Hide();
            };

            // Show the flyout
            confirmFlyout.ShowAt(RemoveKnownPlayerButton);
        }
Esempio n. 5
0
        private void RenameReplayFile_OnClick(object sender, RoutedEventArgs e)
        {
            if (!(Window.GetWindow(this)?.DataContext is MainWindowViewModel context))
            {
                return;
            }
            if (!(this.DataContext is ReplayPreview replay))
            {
                return;
            }

            var flyout = FlyoutHelper.CreateFlyout(includeButton: true, includeCustom: true);

            flyout.GetFlyoutLabel().Visibility = Visibility.Collapsed;
            flyout.SetFlyoutButtonText(TryFindResource("RenameReplayFile") as String);

            // Create textbox to add as flyout custom element
            var fileNameBox = new TextBox
            {
                Text       = replay.DisplayName,
                IsReadOnly = false,
                MinWidth   = 200
            };

            Grid.SetColumn(fileNameBox, 0);
            Grid.SetRow(fileNameBox, 1);
            (flyout.Content as Grid).Children.Add(fileNameBox);

            // Handle save button
            flyout.GetFlyoutButton().Click += (object eSender, RoutedEventArgs eConfirm) =>
            {
                // Rename the file and see if an error was returned
                var error = context.RenameFile(replay, fileNameBox.Text);

                if (error != null)
                {
                    // Display the error using the label
                    flyout.SetFlyoutLabelText(error.Replace('\n', ' '));
                    flyout.GetFlyoutLabel().Visibility = Visibility.Visible;
                    flyout.GetFlyoutLabel().Foreground = TryFindResource("SystemControlErrorTextForegroundBrush") as Brush;
                    fileNameBox.Margin = new Thickness(0, 0, 0, 0);
                }
                else
                {
                    // Hide the flyout
                    this.Dispatcher.Invoke(() =>
                    {
                        flyout.Hide();
                    });
                }
            };

            // Show the flyout and focus it
            flyout.ShowAt(FilenameText);
            fileNameBox.SelectAll();
            fileNameBox.Focus();
        }
        private void TargetButton_Click(object sender, RoutedEventArgs e)
        {
            _blockClose = false;

            var initialDirectory = TargetTextBox.Text;

            if (String.IsNullOrEmpty(initialDirectory))
            {
                initialDirectory = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
            }
            else
            {
                initialDirectory = Path.GetDirectoryName(initialDirectory);
            }

            using (var folderDialog = new CommonOpenFileDialog())
            {
                folderDialog.Title                     = TryFindResource("ExecutableSelectDialogText") as String;
                folderDialog.IsFolderPicker            = false;
                folderDialog.AddToMostRecentlyUsedList = false;
                folderDialog.AllowNonFileSystemItems   = false;
                folderDialog.EnsureFileExists          = true;
                folderDialog.EnsurePathExists          = true;
                folderDialog.EnsureReadOnly            = false;
                folderDialog.EnsureValidNames          = true;
                folderDialog.Multiselect               = false;
                folderDialog.ShowPlacesList            = true;

                folderDialog.InitialDirectory = initialDirectory;
                folderDialog.DefaultDirectory = initialDirectory;

                if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    var selectedExe = folderDialog.FileName;

                    if (ExeTools.CheckExecutableFile(selectedExe))
                    {
                        var newExe = ExeTools.CreateNewLeagueExecutable(selectedExe);
                        LoadLeagueExecutable(newExe);
                    }
                    else
                    {
                        _blockClose = true;

                        // show fly out
                        var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                        flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as String);
                        flyout.ShowAt(TargetButton);
                    }
                }
            }
        }
Esempio n. 7
0
        // Window has been rendered to the screen
        private async void Window_ContentRendered(object sender, EventArgs e)
        {
            if (!_settingsManager.Settings.AutoUpdateCheck)
            {
                return;
            }

            string latestVersion;

            try
            {
                _log.Information("Checking for updates...");
                latestVersion = await GithubConnection.GetLatestVersion().ConfigureAwait(true);
            }
            catch (HttpRequestException ex)
            {
                _log.Warning("Failed to check for updates - " + ex.ToString());
                return; // keep in mind when adding anything to this function!
            }

            if (String.IsNullOrEmpty(latestVersion))
            {
                _log.Warning("Failed to check for updates - github returned nothing or error code");
                return; // keep in mind when adding anything to this function!
            }

            var assemblyName    = Assembly.GetEntryAssembly()?.GetName();
            var assemblyVersion = assemblyName.Version.ToString(3);

            if (latestVersion.Equals(assemblyVersion, StringComparison.OrdinalIgnoreCase))
            {
                _settingsManager.TemporaryValues["UpdateAvailable"] = false;
            }
            else
            {
                _settingsManager.TemporaryValues["UpdateAvailable"] = true;

                var updateNotif = FlyoutHelper.CreateFlyout(true, true);
                updateNotif.SetFlyoutLabelText(TryFindResource("UpdateAvailableNotifText") as String);
                updateNotif.SetFlyoutButtonText(TryFindResource("UpdateAvailableNotifButton") as String);

                updateNotif.GetFlyoutButton().Click += (object e1, RoutedEventArgs a) =>
                {
                    Process.Start((TryFindResource("GitHubReleasesLink") as Uri).ToString());
                };

                updateNotif.Placement = ModernWpf.Controls.Primitives.FlyoutPlacementMode.Bottom;
                updateNotif.ShowAt(SettingsButton);
            }

            return;
        }
        private void SaveButton_Click(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (!(this.DataContext is ExecutableManager context))
            {
                return;
            }

            // Reset error
            _blockClose = false;

            if (_executable == null)
            {
                _blockClose = true;

                // show fly out
                var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as String);
                flyout.ShowAt(TargetTextBox);

                return;
            }

            try
            {
                _executable.Name         = NameTextBox.Text;
                _executable.TargetPath   = TargetTextBox.Text;
                _executable.Locale       = LocaleComboBox.SelectedIndex == Enum.GetNames(typeof(LeagueLocale)).Length - 1 ? LeagueLocale.Custom : (LeagueLocale)LocaleComboBox.SelectedIndex;
                _executable.CustomLocale = CustomLocaleTextBox.Text;

                if (_isEditMode)
                {
                    this.Hide();
                }
                else
                {
                    context.AddExecutable(_executable);
                }

                this.Hide();
            }
            catch (Exception)
            {
                _blockClose = true;

                // show fly out
                var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("ExecutableSaveNullText") as String);
                flyout.ShowAt(TargetTextBox);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Handler for LoadMoreButton
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LoadMoreButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(this.DataContext is MainWindowViewModel context))
            {
                return;
            }

            if (context.LoadReplaysFromDatabase() == 0)
            {
                // Create and show flyout above the button
                var flyout = FlyoutHelper.CreateFlyout(includeButton: false, includeCustom: false);
                flyout.SetFlyoutLabelText(TryFindResource("NoReplaysFoundTitle") as string);

                flyout.ShowAt(LoadMoreButton);

                return;
            }

            // Hide the button bar once we've loaded more
            ReplayPageBar.Visibility = Visibility.Collapsed;
            await context.LoadPreviewPlayerThumbnails().ConfigureAwait(true);
        }
        private void EditLaunchArgsButton_Click(object sender, RoutedEventArgs e)
        {
            if (_executable == null)
            {
                // show fly out
                var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as String);
                flyout.ShowAt(EditLaunchArgsButton);

                return;
            }

            var parent = Window.GetWindow(this);

            var editDialog = new ExecutableLaunchArgsWindow(_executable)
            {
                Top   = parent.Top + 50,
                Left  = parent.Left + 50,
                Owner = parent
            };

            editDialog.ShowDialog();
            LaunchArgsTextBox.Text = PrettifyLaunchArgs(_executable.LaunchArguments);
        }
        private void SaveButton_Click(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (!(this.DataContext is ObservableCollection <PlayerMarker> context))
            {
                return;
            }

            string inputName = NameTextBox.Text;
            string noteText  = NoteTextBox.Text;
            string colorText = MarkerColorPicker.SelectedColorHex;

            // Hide error, reset the block
            _blockClose = false;

            // Validate if input information is OK
            if (String.IsNullOrWhiteSpace(inputName))
            {
                // Show error
                _blockClose = true;

                var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                flyout.SetFlyoutLabelText(TryFindResource("PlayerMarkerNameIsEmptyErrorText") as String);
                flyout.ShowAt(NameTextBox);

                return;
            }

            // Check if name already exists
            if (!_isEditMode)   // If we are creating a new item, no need to check old name collision
            {
                var existingItem = context.Where
                                   (
                    x => x.Name.Equals(inputName, StringComparison.OrdinalIgnoreCase)
                                   ).FirstOrDefault();

                // Name already exists
                if (existingItem != null)
                {
                    _blockClose = true;

                    var errorText = (TryFindResource("PlayerMarkerAlreadyExistsErrorText") as String)
                                    .Replace("$", inputName);

                    var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                    flyout.SetFlyoutLabelText(errorText);
                    flyout.ShowAt(NameTextBox);

                    return;
                }

                // New one, add it!!!!!
                var newMarker = new PlayerMarker
                {
                    Name  = inputName,
                    Color = colorText,
                    Note  = noteText
                };
                context.Add(newMarker);
                this.Hide();
            }
            else
            {
                // Make sure you aren't changing the name to another marker
                var existingItem = context.Where
                                   (
                    x => x.Name.Equals(inputName, StringComparison.OrdinalIgnoreCase) &&
                    !x.Name.Equals(_oldName, StringComparison.OrdinalIgnoreCase)
                                   ).FirstOrDefault();

                // Name already exists
                if (existingItem != null)
                {
                    _blockClose = true;

                    var errorText = (TryFindResource("PlayerMarkerAlreadyExistsErrorText") as String)
                                    .Replace("$", inputName);

                    var flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                    flyout.SetFlyoutLabelText(errorText);
                    flyout.ShowAt(NameTextBox);

                    return;
                }

                // New one, add it!!!!!
                _marker.Name  = inputName;
                _marker.Color = colorText;
                _marker.Note  = noteText;
                this.Hide();
            }
        }
        private void TargetButton_Click(object sender, RoutedEventArgs e)
        {
            _blockClose = false;

            string initialDirectory = TargetTextBox.Text;

            initialDirectory = string.IsNullOrEmpty(initialDirectory)
                ? Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System))
                : Path.GetDirectoryName(initialDirectory);

            using (CommonOpenFileDialog folderDialog = new CommonOpenFileDialog())
            {
                folderDialog.Title                     = TryFindResource("ExecutableSelectDialogText") as string;
                folderDialog.IsFolderPicker            = false;
                folderDialog.AddToMostRecentlyUsedList = false;
                folderDialog.AllowNonFileSystemItems   = false;
                folderDialog.EnsureFileExists          = true;
                folderDialog.EnsurePathExists          = true;
                folderDialog.EnsureReadOnly            = false;
                folderDialog.EnsureValidNames          = true;
                folderDialog.Multiselect               = false;
                folderDialog.ShowPlacesList            = true;

                folderDialog.InitialDirectory = initialDirectory;
                folderDialog.DefaultDirectory = initialDirectory;

                if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    string selectedExe = folderDialog.FileName;

                    if (ExeTools.CheckExecutableFile(selectedExe))
                    {
                        LeagueExecutable newExe = null;

                        try
                        {
                            newExe = ExeTools.CreateNewLeagueExecutable(selectedExe);

                            try
                            {
                                newExe.Locale = ExeTools.DetectExecutableLocale(selectedExe);
                            }
                            catch (Exception)
                            {
                                newExe.Locale = LeagueLocale.EnglishUS;
                                // do not stop operation
                            }

                            LoadLeagueExecutable(newExe);
                        }
                        catch (Exception)
                        {
                            _blockClose = true;

                            // show fly out
                            Flyout flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                            flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as string);
                            flyout.ShowAt(TargetButton);
                        }
                    }
                    else
                    {
                        _blockClose = true;

                        // show fly out
                        Flyout flyout = FlyoutHelper.CreateFlyout(includeButton: false);
                        flyout.SetFlyoutLabelText(TryFindResource("ExecutableSelectInvalidErrorText") as string);
                        flyout.ShowAt(TargetButton);
                    }
                }
            }
        }