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); } }
public ExeManager() { string fileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } _exeInfoFilePath = Path.Combine(fileDir, "executables.json"); ExeTools = new ExeTools(); if (!File.Exists(_exeInfoFilePath)) { _executables = new List <LeagueExecutable>(); // Exe file is missing, create it _defaultExecutable = SetupFirstExe(); } else { InfoFile savedExeObject = JsonConvert.DeserializeObject <InfoFile>(File.ReadAllText(_exeInfoFilePath)); _executables = savedExeObject.Executables; _defaultExecutable = savedExeObject.DefaultExecutable; } }
public ExecAddForm(ExeTools exeTools) { InitializeComponent(); InitForm(); NewLeagueExec = new LeagueExecutable(); toolTip = new ToolTip(); _exeTools = exeTools; }
public IList <LeagueExecutable> SearchFolderForExecutables(string startPath) { List <LeagueExecutable> foundExecutables = new List <LeagueExecutable>(); if (!Directory.Exists(startPath)) { _log.Warning($"Input path {startPath} does not exist"); throw new DirectoryNotFoundException($"Input path {startPath} does not exist"); } try { // Look for any and all league of legends executables var exeFiles = Directory.EnumerateFiles(startPath, "League of Legends.exe", SearchOption.AllDirectories); foreach (string exePath in exeFiles) { LeagueExecutable newExe = null; try { newExe = ExeTools.CreateNewLeagueExecutable(exePath); } catch (Exception ex) { _log.Error($"{ex.GetType()} trying to create executable for path = \"{exePath}\""); _log.Error(ex.ToString()); continue; } try { newExe.Locale = ExeTools.DetectExecutableLocale(exePath); } catch (Exception ex) { _log.Error($"{ex.GetType()} trying to find locale for path = \"{exePath}\""); _log.Error(ex.ToString()); newExe.Locale = LeagueLocale.EnglishUS; // do not stop operation } // Do we already have an exe with the same target? if (!foundExecutables.Exists(x => x.TargetPath.Equals(newExe.TargetPath, StringComparison.OrdinalIgnoreCase))) { foundExecutables.Add(newExe); } } } catch (Exception e) { _log.Error(e.ToString()); throw; } return(foundExecutables); }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (!(this.DataContext is SettingsManager context)) { return; } // Set color picker note if (context.Settings.AccentColor != null) { AccentColorNoteTextBlock.Text = TryFindResource("AppearanceThemeCustomAccentNote") as String; } //// Change window style (i dont think this works anymore...2020-11-30) var GWL_STYLE = -16; // Maximize box flag var WS_MAXIMIZEBOX = 0x10000; var windowHandle = new WindowInteropHelper((Window)sender).Handle; var value = NativeMethods.GetWindowLong(windowHandle, GWL_STYLE); // Flip maximize box flag _ = NativeMethods.SetWindowLong(windowHandle, GWL_STYLE, (int)(value & ~WS_MAXIMIZEBOX)); // // Set player marker style radio PlayerMarkerStyleOption1.IsChecked = (context.Settings.PlayerMarkerStyle == MarkerStyle.Border); PlayerMarkerStyleOption2.IsChecked = (context.Settings.PlayerMarkerStyle == MarkerStyle.Square); // Set file action radio FileActionOption1.IsChecked = (context.Settings.FileAction == FileAction.Play); FileActionOption2.IsChecked = (context.Settings.FileAction == FileAction.Open); // Set theme mode radio AppearanceThemeOption1.IsChecked = (context.Settings.ThemeMode == 0); AppearanceThemeOption2.IsChecked = (context.Settings.ThemeMode == 1); AppearanceThemeOption3.IsChecked = (context.Settings.ThemeMode == 2); // Load language drop down LanguageComboBox.ItemsSource = LanguageHelper.GetFriendlyLanguageNames(); LanguageComboBox.SelectedIndex = (int)context.Settings.ProgramLanguage; // Load locale drop down var allLocales = Enum.GetNames(typeof(LeagueLocale)) .Where(x => !string.Equals(x, LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase)) .Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); ExecutableLocaleComboBox.ItemsSource = allLocales; ExecutableLocaleComboBox.SelectedIndex = (int)context.Executables.Settings.DefaultLocale; // See if an update exists if (context.TemporaryValues.TryGetBool("UpdateAvailable", out bool update)) { UpdateAvailableButton.Visibility = update ? Visibility.Visible : Visibility.Collapsed; } }
private void Page_Initialized(object sender, EventArgs e) { // Load locales into combo box, set default to English var allLocales = Enum.GetNames(typeof(LeagueLocale)) .Where(x => !string.Equals(x, LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase)) .Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); this.LocaleComboBox.ItemsSource = allLocales; this.LocaleComboBox.SelectedIndex = (int)LeagueLocale.EnglishUS; }
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); } } } }
// This is a backup constructor that should only be called when the original fails when first launched public ExeManager(LeagueExecutable manualDefault) { string fileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data"); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } _exeInfoFilePath = Path.Combine(fileDir, "executables.json"); ExeTools = new ExeTools(); _executables = new List <LeagueExecutable>(); _defaultExecutable = manualDefault; }
private void LoadLeagueExecutable(LeagueExecutable executable) { _executable = executable ?? throw new ArgumentNullException(nameof(executable)); TargetTextBox.Text = executable.TargetPath; NameTextBox.Text = executable.Name; LocaleComboBox.SelectedItem = executable.Locale == LeagueLocale.Custom ? LocaleNames.Last() : LocaleNames.First(x => x.Split('(', ')')[1] == ExeTools.GetLocaleCode(executable.Locale)); LaunchArgsTextBox.Text = PrettifyLaunchArgs(executable.LaunchArguments); CustomLocaleTextBox.Text = executable.CustomLocale; }
private void TargetButton_Click(object sender, RoutedEventArgs e) { 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 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); folderDialog.DefaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok) { var selectedExe = folderDialog.FileName; if (ExeTools.CheckExecutableFile(selectedExe)) { var newExe = ExeTools.CreateNewLeagueExecutable(selectedExe); LoadLeagueExecutable(newExe); } else { var msgBoxResult = MessageBox.Show ( TryFindResource("ExecutableSelectInvalidErrorText") as String, TryFindResource("ExecutableSelectInvalidErrorTitle") as String, MessageBoxButton.OK, MessageBoxImage.Exclamation ); if (msgBoxResult == MessageBoxResult.OK) { TargetButton_Click(null, null); } else { return; } } } } }
public void UpdateExecutableVersion(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } var currentVersion = ExeTools.GetLeagueVersion(executable.TargetPath); if (!executable.PatchNumber.Equals(currentVersion, StringComparison.OrdinalIgnoreCase)) { _log.Information($"Updating executable {executable.Name} from {executable.PatchNumber} -> {currentVersion}"); executable.PatchNumber = currentVersion; } }
public void AddExecutable(LeagueExecutable newExecutable) { // Validate file if (newExecutable == null) { _log.Warning($"Given Executable is null"); throw new ArgumentNullException(nameof(newExecutable)); } // Add character to the end of the name if already exists string name = newExecutable.Name; while (!CheckExecutableName(name)) { name += "+"; } newExecutable.Name = name; // Will throw exception if executable is invalid ExeTools.ValidateLeagueExecutable(newExecutable); Settings.Executables.Add(newExecutable); }
public IList <LeagueExecutable> SearchFolderForExecutables(string startPath) { List <LeagueExecutable> foundExecutables = new List <LeagueExecutable>(); if (!Directory.Exists(startPath)) { _log.Warning($"Input path {startPath} does not exist"); throw new DirectoryNotFoundException($"Input path {startPath} does not exist"); } try { // Look for any and all league of legends executables var exeFiles = Directory.EnumerateFiles(startPath, "League of Legends.exe", SearchOption.AllDirectories); foreach (string exePath in exeFiles) { LeagueExecutable newExe = ExeTools.CreateNewLeagueExecutable(exePath); // Set default locale newExe.Locale = Settings.DefaultLocale; // Do we already have an exe with the same target? if (!foundExecutables.Exists(x => x.TargetPath.Equals(newExe.TargetPath, StringComparison.OrdinalIgnoreCase))) { foundExecutables.Add(newExe); } } } catch (Exception e) { _log.Error(e.ToString()); throw; } return(foundExecutables); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // load locales into drop down, skip parentheses for custom option var allLocales = Enum.GetNames(typeof(LeagueLocale)) .Select(x => x + (x.StartsWith(LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase) ? "" : " (" + ExeTools.GetLocaleCode(x) + ")")); this.LocaleComboBox.ItemsSource = allLocales; }
public ExecutableDetailDialog(LeagueExecutable executable) { if (executable == null) { throw new ArgumentNullException(nameof(executable)); } // load locales into drop down, skip parentheses for custom option LocaleNames = Enum.GetNames(typeof(LeagueLocale)) .Select(x => x + (x.StartsWith(LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase) ? "" : " (" + ExeTools.GetLocaleCode(x) + ")")) .OrderBy(x => x == LeagueLocale.Custom.ToString()) .ThenBy(x => x); InitializeComponent(); LoadLeagueExecutable(executable); _isEditMode = true; Title = TryFindResource("EditButtonText") as string + " " + Title; }
private void Window_Loaded(object sender, RoutedEventArgs e) { var allLocales = Enum.GetNames(typeof(LeagueLocale)).Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); this.LocaleComboBox.ItemsSource = allLocales; }
private void WelcomeSetupRegion_OnLoaded(object sender, RoutedEventArgs e) { var parentWindow = Window.GetWindow(this); if (!(parentWindow is WelcomeSetupWindow parent)) { throw new ArgumentException("Parent window is not WelcomeSetupWindow type"); } _setupSettings = parent.SetupSettings; // Load locales into combo box, set default to English var allLocales = Enum.GetNames(typeof(LeagueLocale)).Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); this.LocaleComboBox.ItemsSource = allLocales; this.LocaleComboBox.SelectedIndex = (int)LeagueLocale.EnglishUS; }
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); } } } }
private void Page_Initialized(object sender, EventArgs e) { // Load locales into combo box, set default to English var allLocales = Enum.GetNames(typeof(LeagueLocale)).Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); this.LocaleComboBox.ItemsSource = allLocales; this.LocaleComboBox.SelectedIndex = (int)LeagueLocale.EnglishUS; }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.MinWidth = this.ActualWidth; this.MinHeight = this.ActualHeight; //this.MaxHeight = this.ActualHeight; var allLocales = Enum.GetNames(typeof(LeagueLocale)).Select(x => x + " (" + ExeTools.GetLocaleCode(x) + ")"); this.LocaleComboBox.ItemsSource = allLocales; }
public ExecutableDetailDialog() { // load locales into drop down, skip parentheses for custom option LocaleNames = Enum.GetNames(typeof(LeagueLocale)) .Select(x => x + (x.StartsWith(LeagueLocale.Custom.ToString(), StringComparison.OrdinalIgnoreCase) ? "" : " (" + ExeTools.GetLocaleCode(x) + ")")) .OrderBy(x => x == LeagueLocale.Custom.ToString()) .ThenBy(x => x); InitializeComponent(); _isEditMode = false; Title = TryFindResource("AddButtonText") as string + " " + Title; }