Skip to content

Commit

Permalink
Ability to hide file types in Game List (Ryujinx#4555)
Browse files Browse the repository at this point in the history
* Added HiddenFileTypes to config state, and check to file enumeration

* Added hiddenfiletypes checkboxes to the UI

* Added Ava version of HiddenFileTypes

* Inverted Hide to Show with file types, minor formatting

* all variables with a reference to 'hidden' is now 'shown'

* one more variable name changed

* review feedback

* added FileTypes extension methof to get the correlating config value

* moved extension method to new folder and file in Ryujinx.Ui.Common

* added default case for ToggleFileType

* changed exception type to OutOfRangeException
  • Loading branch information
NitroTears committed Apr 16, 2023
1 parent 5c89e22 commit c5258cf
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 5 deletions.
1 change: 1 addition & 0 deletions Ryujinx.Ava/Assets/Locales/en_US.json
Expand Up @@ -429,6 +429,7 @@
"DlcManagerEnableAllButton": "Enable All",
"DlcManagerDisableAllButton": "Disable All",
"MenuBarOptionsChangeLanguage": "Change Language",
"MenuBarShowFileTypes": "Show File Types",
"CommonSort": "Sort",
"CommonShowNames": "Show Names",
"CommonFavorite": "Favorite",
Expand Down
17 changes: 17 additions & 0 deletions Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs
Expand Up @@ -1336,6 +1336,23 @@ public void ChangeLanguage(object languageCode)
}
}

public void ToggleFileType(string fileType)
{
_ = fileType switch
{
"NSP" => ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.NSP,
"PFS0" => ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.PFS0,
"XCI" => ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.XCI,
"NCA" => ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.NCA,
"NRO" => ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.NRO,
"NSO" => ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value = !ConfigurationState.Instance.Ui.ShownFileTypes.NSO,
_ => throw new ArgumentOutOfRangeException(fileType),
};

ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
LoadApplications();
}

public async void ManageProfiles()
{
await NavigationDialogHost.Show(AccountManager, ContentManager, VirtualFileSystem, LibHacHorizonManager.RyujinxClient);
Expand Down
1 change: 1 addition & 0 deletions Ryujinx.Ava/UI/Views/Main/MainMenuBarView.axaml
Expand Up @@ -78,6 +78,7 @@
</MenuItem>
<Separator />
<MenuItem Name="ChangeLanguageMenuItem" Header="{locale:Locale MenuBarOptionsChangeLanguage}" />
<MenuItem Name="ToggleFileTypesMenuItem" Header="{locale:Locale MenuBarShowFileTypes}" />
<Separator />
<MenuItem
Click="OpenSettings"
Expand Down
28 changes: 27 additions & 1 deletion Ryujinx.Ava/UI/Views/Main/MainMenuBarView.axaml.cs
Expand Up @@ -11,6 +11,8 @@
using Ryujinx.Common.Utilities;
using Ryujinx.HLE.HOS;
using Ryujinx.Modules;
using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Helper;
using System;
using System.Collections.Generic;
Expand All @@ -29,6 +31,30 @@ public MainMenuBarView()
{
InitializeComponent();

ToggleFileTypesMenuItem.Items = GenerateToggleFileTypeItems();
ChangeLanguageMenuItem.Items = GenerateLanguageMenuItems();
}

private CheckBox[] GenerateToggleFileTypeItems()
{
List<CheckBox> checkBoxes = new();

foreach (var item in Enum.GetValues(typeof (FileTypes)))
{
string fileName = Enum.GetName(typeof (FileTypes), item);
checkBoxes.Add(new CheckBox()
{
Content = $".{fileName}",
IsChecked = ((FileTypes)item).GetConfigValue(ConfigurationState.Instance.Ui.ShownFileTypes),
Command = MiniCommand.Create(() => ViewModel.ToggleFileType(fileName))
});
}

return checkBoxes.ToArray();
}

private MenuItem[] GenerateLanguageMenuItems()
{
List<MenuItem> menuItems = new();

string localePath = "Ryujinx.Ava/Assets/Locales";
Expand Down Expand Up @@ -61,7 +87,7 @@ public MainMenuBarView()
menuItems.Add(menuItem);
}

ChangeLanguageMenuItem.Items = menuItems.ToArray();
return menuItems.ToArray();
}

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Expand Down
15 changes: 14 additions & 1 deletion Ryujinx.Ui.Common/App/ApplicationLibrary.cs
Expand Up @@ -14,9 +14,11 @@
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.HLE.Loaders.Npdm;
using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Configuration.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -109,7 +111,18 @@ public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage

try
{
foreach (string app in Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories))
IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories).Where(file =>
{
return
(Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value) ||
(Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value) ||
(Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value) ||
(Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value) ||
(Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value) ||
(Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value);
});

foreach (string app in files)
{
if (_cancellationToken.Token.IsCancellationRequested)
{
Expand Down
7 changes: 6 additions & 1 deletion Ryujinx.Ui.Common/Configuration/ConfigurationFileFormat.cs
Expand Up @@ -14,7 +14,7 @@ public class ConfigurationFileFormat
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 44;
public const int CurrentVersion = 45;

/// <summary>
/// Version of the configuration file format
Expand Down Expand Up @@ -246,6 +246,11 @@ public class ConfigurationFileFormat
/// </summary>
public List<string> GameDirs { get; set; }

/// <summary>
/// A list of file types to be hidden in the games List
/// </summary>
public ShownFileTypes ShownFileTypes { get; set; }

/// <summary>
/// Language Code for the UI
/// </summary>
Expand Down
71 changes: 69 additions & 2 deletions Ryujinx.Ui.Common/Configuration/ConfigurationState.cs
Expand Up @@ -60,6 +60,29 @@ public ColumnSortSettings()
}
}

/// <summary>
/// Used to toggle which file types are shown in the UI
/// </summary>
public class ShownFileTypeSettings
{
public ReactiveObject<bool> NSP { get; private set; }
public ReactiveObject<bool> PFS0 { get; private set; }
public ReactiveObject<bool> XCI { get; private set; }
public ReactiveObject<bool> NCA { get; private set; }
public ReactiveObject<bool> NRO { get; private set; }
public ReactiveObject<bool> NSO { get; private set; }

public ShownFileTypeSettings()
{
NSP = new ReactiveObject<bool>();
PFS0 = new ReactiveObject<bool>();
XCI = new ReactiveObject<bool>();
NCA = new ReactiveObject<bool>();
NRO = new ReactiveObject<bool>();
NSO = new ReactiveObject<bool>();
}
}

/// <summary>
/// Used to toggle columns in the GUI
/// </summary>
Expand All @@ -75,6 +98,11 @@ public ColumnSortSettings()
/// </summary>
public ReactiveObject<List<string>> GameDirs { get; private set; }

/// <summary>
/// A list of file types to be hidden in the games List
/// </summary>
public ShownFileTypeSettings ShownFileTypes { get; private set; }

/// <summary>
/// Language Code for the UI
/// </summary>
Expand Down Expand Up @@ -135,6 +163,7 @@ public UiSection()
GuiColumns = new Columns();
ColumnSort = new ColumnSortSettings();
GameDirs = new ReactiveObject<List<string>>();
ShownFileTypes = new ShownFileTypeSettings();
EnableCustomTheme = new ReactiveObject<bool>();
CustomThemePath = new ReactiveObject<string>();
BaseStyle = new ReactiveObject<string>();
Expand Down Expand Up @@ -618,6 +647,15 @@ public ConfigurationFileFormat ToFileFormat()
SortAscending = Ui.ColumnSort.SortAscending
},
GameDirs = Ui.GameDirs,
ShownFileTypes = new ShownFileTypes
{
NSP = Ui.ShownFileTypes.NSP,
PFS0 = Ui.ShownFileTypes.PFS0,
XCI = Ui.ShownFileTypes.XCI,
NCA = Ui.ShownFileTypes.NCA,
NRO = Ui.ShownFileTypes.NRO,
NSO = Ui.ShownFileTypes.NSO,
},
LanguageCode = Ui.LanguageCode,
EnableCustomTheme = Ui.EnableCustomTheme,
CustomThemePath = Ui.CustomThemePath,
Expand Down Expand Up @@ -702,7 +740,13 @@ public void LoadDefault()
Ui.ColumnSort.SortColumnId.Value = 0;
Ui.ColumnSort.SortAscending.Value = false;
Ui.GameDirs.Value = new List<string>();
Ui.EnableCustomTheme.Value = false;
Ui.ShownFileTypes.NSP.Value = true;
Ui.ShownFileTypes.PFS0.Value = true;
Ui.ShownFileTypes.XCI.Value = true;
Ui.ShownFileTypes.NCA.Value = true;
Ui.ShownFileTypes.NRO.Value = true;
Ui.ShownFileTypes.NSO.Value = true;
Ui.EnableCustomTheme.Value = true;
Ui.LanguageCode.Value = "en_US";
Ui.CustomThemePath.Value = "";
Ui.BaseStyle.Value = "Dark";
Expand Down Expand Up @@ -1238,7 +1282,7 @@ public ConfigurationLoadResult Load(ConfigurationFileFormat configurationFileFor

if (configurationFileFormat.Version < 44)
{
Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 42.");
Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 44.");

configurationFileFormat.AntiAliasing = AntiAliasing.None;
configurationFileFormat.ScalingFilter = ScalingFilter.Bilinear;
Expand All @@ -1247,6 +1291,23 @@ public ConfigurationLoadResult Load(ConfigurationFileFormat configurationFileFor
configurationFileUpdated = true;
}

if (configurationFileFormat.Version < 45)
{
Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 45.");

configurationFileFormat.ShownFileTypes = new ShownFileTypes
{
NSP = true,
PFS0 = true,
XCI = true,
NCA = true,
NRO = true,
NSO = true
};

configurationFileUpdated = true;
}

Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
Graphics.ResScale.Value = configurationFileFormat.ResScale;
Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
Expand Down Expand Up @@ -1305,6 +1366,12 @@ public ConfigurationLoadResult Load(ConfigurationFileFormat configurationFileFor
Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
Ui.GameDirs.Value = configurationFileFormat.GameDirs;
Ui.ShownFileTypes.NSP.Value = configurationFileFormat.ShownFileTypes.NSP;
Ui.ShownFileTypes.PFS0.Value = configurationFileFormat.ShownFileTypes.PFS0;
Ui.ShownFileTypes.XCI.Value = configurationFileFormat.ShownFileTypes.XCI;
Ui.ShownFileTypes.NCA.Value = configurationFileFormat.ShownFileTypes.NCA;
Ui.ShownFileTypes.NRO.Value = configurationFileFormat.ShownFileTypes.NRO;
Ui.ShownFileTypes.NSO.Value = configurationFileFormat.ShownFileTypes.NSO;
Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
Ui.LanguageCode.Value = configurationFileFormat.LanguageCode;
Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
Expand Down
12 changes: 12 additions & 0 deletions Ryujinx.Ui.Common/Configuration/FileTypes.cs
@@ -0,0 +1,12 @@
namespace Ryujinx.Ui.Common
{
public enum FileTypes
{
NSP,
PFS0,
XCI,
NCA,
NRO,
NSO
}
}
12 changes: 12 additions & 0 deletions Ryujinx.Ui.Common/Configuration/Ui/ShownFileTypes.cs
@@ -0,0 +1,12 @@
namespace Ryujinx.Ui.Common.Configuration.Ui
{
public struct ShownFileTypes
{
public bool NSP { get; set; }
public bool PFS0 { get; set; }
public bool XCI { get; set; }
public bool NCA { get; set; }
public bool NRO { get; set; }
public bool NSO { get; set; }
}
}
25 changes: 25 additions & 0 deletions Ryujinx.Ui.Common/Extensions/FileTypeExtensions.cs
@@ -0,0 +1,25 @@
using System;
using static Ryujinx.Ui.Common.Configuration.ConfigurationState.UiSection;

namespace Ryujinx.Ui.Common
{
public static class FileTypesExtensions
{
/// <summary>
/// Gets the current <see cref="ShownFileTypeSettings"/> value for the correlating FileType name.
/// </summary>
/// <param name="type">The name of the <see cref="ShownFileTypeSettings"/> parameter to get the value of.</param>
/// <param name="config">The config instance to get the value from.</param>
/// <returns>The current value of the setting. Value is <see langword="true"/> if the file type is the be shown on the games list, <see langword="false"/> otherwise.</returns>
public static bool GetConfigValue(this FileTypes type, ShownFileTypeSettings config) => type switch
{
FileTypes.NSP => config.NSP.Value,
FileTypes.PFS0 => config.PFS0.Value,
FileTypes.XCI => config.XCI.Value,
FileTypes.NCA => config.NCA.Value,
FileTypes.NRO => config.NRO.Value,
FileTypes.NSO => config.NSO.Value,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
}
}

0 comments on commit c5258cf

Please sign in to comment.