public ShortcutSyncSettings(ShortcutSync plugin) { // Injecting your plugin instance is required for Save/Load method because Playnite saves data to a location based on what plugin requested the operation. this.plugin = plugin; // Load saved settings. var savedSettings = plugin.LoadPluginSettings <ShortcutSyncSettings>(); // LoadPluginSettings returns null if not saved data is available. if (savedSettings != null) { var type = savedSettings.GetType(); foreach (var prop in type.GetProperties()) { prop.SetValue(this, prop.GetValue(savedSettings)); } } }
public void BeginEdit() { plugin.settingsView.UpdateTextBlock.Visibility = System.Windows.Visibility.Collapsed; plugin.UpdateAvailable().ContinueWith((task) => { var updateAvailable = task.Result.Available; var url = task.Result.Url; var latestVersion = task.Result.LatestVersion; plugin.settingsView.Dispatcher.Invoke(() => { if (updateAvailable) { plugin.settingsView.UpdateTextBlock.Visibility = System.Windows.Visibility.Visible; plugin.settingsView.UpdateLabel.Text = $"New version {latestVersion} available at:\n"; plugin.settingsView.URL.NavigateUri = new Uri(url); plugin.settingsView.URLLabel.Text = url; } }); }); var bt = plugin.settingsView.SelectFolderButton; bt.Click += Bt_Click; // Get all available source names foreach (var src in plugin.PlayniteApi.Database.Sources) { // Add new sources and disable them by default if (!SourceOptions.ContainsKey(src.Name)) { SourceOptions.Add(src.Name, false); } if (!EnabledPlayActions.ContainsKey(src.Name)) { EnabledPlayActions.Add(src.Name, false); } } if (!SourceOptions.ContainsKey(Constants.UNDEFINEDSOURCE)) { SourceOptions.Add(Constants.UNDEFINEDSOURCE, false); } if (!EnabledPlayActions.ContainsKey(Constants.UNDEFINEDSOURCE)) { EnabledPlayActions.Add(Constants.UNDEFINEDSOURCE, false); } // Set up view var container = plugin.settingsView.SourceNamesStack; container.Children.Clear(); foreach (var srcOpt in SourceOptions) { // Add label and set some properties var label = new Label(); label.Content = srcOpt.Key; label.MinWidth = 50; label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; label.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; label.Height = 20; label.Tag = srcOpt.Key; container.Children.Add(label); } container = plugin.settingsView.SourceSettingsStack; container.Children.Clear(); foreach (var srcOpt in SourceOptions) { // Add checkboxes and set some properties var checkBox = new CheckBox(); checkBox.Content = null; checkBox.IsChecked = srcOpt.Value; checkBox.MinWidth = 50; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBox.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; checkBox.Height = 20; checkBox.Tag = srcOpt.Key; checkBox.ToolTip = $"If enabled, shortcuts to games from {srcOpt.Key} are created and maintained on update."; container.Children.Add(checkBox); } plugin.settingsView.PlayActionSettingsStack.Children.Clear(); foreach (var playActionOpt in EnabledPlayActions) { // Add checkboxes and set some properties var checkBox = new CheckBox(); checkBox.Content = null; checkBox.IsChecked = playActionOpt.Value; checkBox.MinWidth = 50; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBox.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; checkBox.Height = 20; checkBox.Tag = playActionOpt.Key; checkBox.ToolTip = $"If enabled, shortuts try to start games from {playActionOpt.Key} with their native launcher or without any launcher (bypassing Playnite), depending on the existing PlayAction of that game."; plugin.settingsView.PlayActionSettingsStack.Children.Add(checkBox); } plugin.settingsView.ManuallyCreatedShortcutListBox.Items.Clear(); foreach (var id in ManuallyCreatedShortcuts) { var item = new ListBoxItem(); item.Tag = id; item.ContextMenu = new ContextMenu(); var menuItem = new MenuItem { Header = "Remove Entry", Tag = id }; menuItem.Click += RemoveManual_Click; item.ContextMenu.Items.Add(menuItem); var game = plugin.PlayniteApi.Database.Games.Get(id); item.Content = game == null? "Game not found: " + id.ToString() : $"{game.Name} ({ShortcutSync.GetSourceName(game)})"; item.ToolTip = item.Content; plugin.settingsView.ManuallyCreatedShortcutListBox.Items.Add(item); } plugin.settingsView.ExcludedGamesListBox.Items.Clear(); foreach (var id in ExcludedGames) { var item = new ListBoxItem(); item.Tag = id; item.ContextMenu = new ContextMenu(); var menuItem = new MenuItem { Header = "Remove Entry", Tag = id }; menuItem.Click += RemoveExcluded_Click; item.ContextMenu.Items.Add(menuItem); var game = plugin.PlayniteApi.Database.Games.Get(id); item.Content = game == null ? "Game not found: " + id.ToString() : $"{game.Name} ({ShortcutSync.GetSourceName(game)})"; item.ToolTip = item.Content; plugin.settingsView.ExcludedGamesListBox.Items.Add(item); } }