/ src / Ryujinx / UI / Views / Settings / SettingsUIView.axaml.cs
SettingsUIView.axaml.cs
 1  using Avalonia.Controls;
 2  using Avalonia.Interactivity;
 3  using Avalonia.Platform.Storage;
 4  using Avalonia.VisualTree;
 5  using Ryujinx.Ava.Common.Locale;
 6  using Ryujinx.Ava.UI.ViewModels;
 7  using System.Collections.Generic;
 8  using System.IO;
 9  using System.Linq;
10  
11  namespace Ryujinx.Ava.UI.Views.Settings
12  {
13      public partial class SettingsUiView : UserControl
14      {
15          public SettingsViewModel ViewModel;
16  
17          public SettingsUiView()
18          {
19              InitializeComponent();
20          }
21  
22          private async void AddButton_OnClick(object sender, RoutedEventArgs e)
23          {
24              string path = PathBox.Text;
25  
26              if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
27              {
28                  ViewModel.GameDirectories.Add(path);
29                  ViewModel.DirectoryChanged = true;
30              }
31              else
32              {
33                  if (this.GetVisualRoot() is Window window)
34                  {
35                      var result = await window.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
36                      {
37                          AllowMultiple = false,
38                      });
39  
40                      if (result.Count > 0)
41                      {
42                          ViewModel.GameDirectories.Add(result[0].Path.LocalPath);
43                          ViewModel.DirectoryChanged = true;
44                      }
45                  }
46              }
47          }
48  
49          private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
50          {
51              int oldIndex = GameList.SelectedIndex;
52  
53              foreach (string path in new List<string>(GameList.SelectedItems.Cast<string>()))
54              {
55                  ViewModel.GameDirectories.Remove(path);
56                  ViewModel.DirectoryChanged = true;
57              }
58  
59              if (GameList.ItemCount > 0)
60              {
61                  GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
62              }
63          }
64      }
65  }