forked from Mirror/Ryujinx
da4e0856c9
* controller image changes depending on the selected controller type the new controller image assets are temporary until i get new ones * Game list scans subdirs for games * Key file existence check * Only shows Program NCAs in Application list * Change shown GUI columns without restarting * Sort by column if you click on the column header Columns are sorted as text so there are inaccuracies on some columns * Fix sort on Time Played, Last Played and File Size columns * Add ability to designate favourite games #1 TODO: - Make fav games persistent - Fix invisible check marks due to theme * Add ability to designate favourite games #2 Also removed default theme * Added a Windows specific build condition and a Linux bug fix * bugfix * Load metadata from JSONs * Temp bug fix for MacOS * lil clean up * requested changes * Misc fixes * edited schema and config * Show the TitleID of games on the title bar * gui column config option have names * Async loading of game list * bugfix and cleanup * thog's requested changes * requested changes and cleanup still need to fix the gtk seizure * Fix issue where an ExeFS as a NSP didn't show up in the application list * Minor fixes * catch glib unhandled exceptions * Make sure to do UI manipulation in the main thread * Print path of invalid files * Ac_k's requested changes * Return of the dark theme * move AboutInfo struct to another file * sort usings * changes - gdkchan's requested changes that have been marked resolved - made some structs internal as they aren't used outside of the GUI - renamed Ryujinx.UI to Ryujinx.Ui to fit naming convention and folder structure - fixed bug where controller type dropdown box is stretched
327 lines
No EOL
11 KiB
C#
327 lines
No EOL
11 KiB
C#
using JsonPrettyPrinterPlus;
|
|
using LibHac.FsSystem;
|
|
using OpenTK.Input;
|
|
using Ryujinx.Common;
|
|
using Ryujinx.Common.Logging;
|
|
using Ryujinx.HLE;
|
|
using Ryujinx.HLE.HOS.SystemState;
|
|
using Ryujinx.HLE.HOS.Services;
|
|
using Ryujinx.HLE.Input;
|
|
using Ryujinx.Ui;
|
|
using Ryujinx.Ui.Input;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Utf8Json;
|
|
using Utf8Json.Resolvers;
|
|
|
|
namespace Ryujinx
|
|
{
|
|
public class Configuration
|
|
{
|
|
/// <summary>
|
|
/// The default configuration instance
|
|
/// </summary>
|
|
public static Configuration Instance { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Dumps shaders in this local directory
|
|
/// </summary>
|
|
public string GraphicsShadersDumpPath { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing debug log messages
|
|
/// </summary>
|
|
public bool LoggingEnableDebug { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing stub log messages
|
|
/// </summary>
|
|
public bool LoggingEnableStub { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing info log messages
|
|
/// </summary>
|
|
public bool LoggingEnableInfo { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing warning log messages
|
|
/// </summary>
|
|
public bool LoggingEnableWarn { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing error log messages
|
|
/// </summary>
|
|
public bool LoggingEnableError { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing guest log messages
|
|
/// </summary>
|
|
public bool LoggingEnableGuest { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables printing FS access log messages
|
|
/// </summary>
|
|
public bool LoggingEnableFsAccessLog { get; set; }
|
|
|
|
/// <summary>
|
|
/// Controls which log messages are written to the log targets
|
|
/// </summary>
|
|
public LogClass[] LoggingFilteredClasses { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables or disables logging to a file on disk
|
|
/// </summary>
|
|
public bool EnableFileLog { get; set; }
|
|
|
|
/// <summary>
|
|
/// Change System Language
|
|
/// </summary>
|
|
public SystemLanguage SystemLanguage { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables or disables Docked Mode
|
|
/// </summary>
|
|
public bool DockedMode { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables or disables Discord Rich Presence
|
|
/// </summary>
|
|
public bool EnableDiscordIntegration { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables or disables Vertical Sync
|
|
/// </summary>
|
|
public bool EnableVsync { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables or disables multi-core scheduling of threads
|
|
/// </summary>
|
|
public bool EnableMulticoreScheduling { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables integrity checks on Game content files
|
|
/// </summary>
|
|
public bool EnableFsIntegrityChecks { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enables FS access log output to the console. Possible modes are 0-3
|
|
/// </summary>
|
|
public int FsGlobalAccessLogMode { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enable or disable ignoring missing services
|
|
/// </summary>
|
|
public bool IgnoreMissingServices { get; set; }
|
|
|
|
/// <summary>
|
|
/// The primary controller's type
|
|
/// </summary>
|
|
public ControllerStatus ControllerType { get; set; }
|
|
|
|
/// <summary>
|
|
/// Used to toggle columns in the GUI
|
|
/// </summary>
|
|
public GuiColumns GuiColumns { get; set; }
|
|
|
|
/// <summary>
|
|
/// A list of directories containing games to be used to load games into the games list
|
|
/// </summary>
|
|
public List<string> GameDirs { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enable or disable custom themes in the GUI
|
|
/// </summary>
|
|
public bool EnableCustomTheme { get; set; }
|
|
|
|
/// <summary>
|
|
/// Path to custom GUI theme
|
|
/// </summary>
|
|
public string CustomThemePath { get; set; }
|
|
|
|
/// <summary>
|
|
/// Enable or disable keyboard support (Independent from controllers binding)
|
|
/// </summary>
|
|
public bool EnableKeyboard { get; set; }
|
|
|
|
/// <summary>
|
|
/// Keyboard control bindings
|
|
/// </summary>
|
|
public NpadKeyboard KeyboardControls { get; set; }
|
|
|
|
/// <summary>
|
|
/// Controller control bindings
|
|
/// </summary>
|
|
public Ui.Input.NpadController JoystickControls { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Loads a configuration file from disk
|
|
/// </summary>
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
public static void Load(string path)
|
|
{
|
|
var resolver = CompositeResolver.Create(
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
);
|
|
|
|
using (Stream stream = File.OpenRead(path))
|
|
{
|
|
Instance = JsonSerializer.Deserialize<Configuration>(stream, resolver);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads a configuration file asynchronously from disk
|
|
/// </summary>
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
public static async Task LoadAsync(string path)
|
|
{
|
|
IJsonFormatterResolver resolver = CompositeResolver.Create(
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
);
|
|
|
|
using (Stream stream = File.OpenRead(path))
|
|
{
|
|
Instance = await JsonSerializer.DeserializeAsync<Configuration>(stream, resolver);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save a configuration file to disk
|
|
/// </summary>
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
public static void SaveConfig(Configuration config, string path)
|
|
{
|
|
IJsonFormatterResolver resolver = CompositeResolver.Create(
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
);
|
|
|
|
byte[] data = JsonSerializer.Serialize(config, resolver);
|
|
File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configures a <see cref="Switch"/> instance
|
|
/// </summary>
|
|
/// <param name="device">The instance to configure</param>
|
|
public static void InitialConfigure(Switch device)
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
throw new InvalidOperationException("Configuration has not been loaded yet.");
|
|
}
|
|
|
|
SwitchSettings.ConfigureSettings(Instance);
|
|
|
|
Logger.AddTarget(new AsyncLogTargetWrapper(
|
|
new ConsoleLogTarget(),
|
|
1000,
|
|
AsyncLogTargetOverflowAction.Block
|
|
));
|
|
|
|
if (Instance.EnableFileLog)
|
|
{
|
|
Logger.AddTarget(new AsyncLogTargetWrapper(
|
|
new FileLogTarget(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx.log")),
|
|
1000,
|
|
AsyncLogTargetOverflowAction.Block
|
|
));
|
|
}
|
|
|
|
Configure(device, Instance);
|
|
}
|
|
|
|
public static void Configure(Switch device, Configuration SwitchConfig)
|
|
{
|
|
GraphicsConfig.ShadersDumpPath = SwitchConfig.GraphicsShadersDumpPath;
|
|
|
|
Logger.SetEnable(LogLevel.Debug, SwitchConfig.LoggingEnableDebug );
|
|
Logger.SetEnable(LogLevel.Stub, SwitchConfig.LoggingEnableStub );
|
|
Logger.SetEnable(LogLevel.Info, SwitchConfig.LoggingEnableInfo );
|
|
Logger.SetEnable(LogLevel.Warning, SwitchConfig.LoggingEnableWarn );
|
|
Logger.SetEnable(LogLevel.Error, SwitchConfig.LoggingEnableError );
|
|
Logger.SetEnable(LogLevel.Guest, SwitchConfig.LoggingEnableGuest );
|
|
Logger.SetEnable(LogLevel.AccessLog, SwitchConfig.LoggingEnableFsAccessLog);
|
|
|
|
if (SwitchConfig.LoggingFilteredClasses.Length > 0)
|
|
{
|
|
foreach (var logClass in EnumExtensions.GetValues<LogClass>())
|
|
{
|
|
Logger.SetEnable(logClass, false);
|
|
}
|
|
|
|
foreach (var logClass in SwitchConfig.LoggingFilteredClasses)
|
|
{
|
|
Logger.SetEnable(logClass, true);
|
|
}
|
|
}
|
|
|
|
MainWindow.DiscordIntegrationEnabled = SwitchConfig.EnableDiscordIntegration;
|
|
|
|
device.EnableDeviceVsync = SwitchConfig.EnableVsync;
|
|
|
|
device.System.State.DockedMode = SwitchConfig.DockedMode;
|
|
|
|
device.System.State.SetLanguage(SwitchConfig.SystemLanguage);
|
|
|
|
if (SwitchConfig.EnableMulticoreScheduling)
|
|
{
|
|
device.System.EnableMultiCoreScheduling();
|
|
}
|
|
|
|
device.System.FsIntegrityCheckLevel = SwitchConfig.EnableFsIntegrityChecks
|
|
? IntegrityCheckLevel.ErrorOnInvalid
|
|
: IntegrityCheckLevel.None;
|
|
|
|
device.System.GlobalAccessLogMode = SwitchConfig.FsGlobalAccessLogMode;
|
|
|
|
ServiceConfiguration.IgnoreMissingServices = SwitchConfig.IgnoreMissingServices;
|
|
}
|
|
|
|
public static void ConfigureHid(Switch device, Configuration SwitchConfig)
|
|
{
|
|
if (SwitchConfig.JoystickControls.Enabled)
|
|
{
|
|
if (!Joystick.GetState(SwitchConfig.JoystickControls.Index).IsConnected)
|
|
{
|
|
SwitchConfig.JoystickControls.SetEnabled(false);
|
|
}
|
|
}
|
|
device.Hid.InitializePrimaryController(SwitchConfig.ControllerType);
|
|
device.Hid.InitializeKeyboard();
|
|
}
|
|
|
|
private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
|
|
where T : struct
|
|
{
|
|
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
|
|
{
|
|
formatterResolver.GetFormatterWithVerify<string>()
|
|
.Serialize(ref writer, value.ToString(), formatterResolver);
|
|
}
|
|
|
|
public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
|
|
{
|
|
if (reader.ReadIsNull())
|
|
{
|
|
return default(T);
|
|
}
|
|
|
|
string enumName = formatterResolver.GetFormatterWithVerify<string>()
|
|
.Deserialize(ref reader, formatterResolver);
|
|
|
|
if (Enum.TryParse<T>(enumName, out T result))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return default(T);
|
|
}
|
|
}
|
|
}
|
|
} |