using JsonPrettyPrinterPlus;
using Ryujinx.Common.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Utf8Json;
using Utf8Json.Resolvers;
using Ryujinx.Configuration.System;
using Ryujinx.Configuration.Hid;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.UI.Input;
using Ryujinx.Configuration.Ui;
namespace Ryujinx.Configuration
{
public class ConfigurationFileFormat
{
///
/// The current version of the file format
///
public const int CurrentVersion = 5;
public int Version { get; set; }
///
/// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
///
public float MaxAnisotropy { get; set; }
///
/// Dumps shaders in this local directory
///
public string GraphicsShadersDumpPath { get; set; }
///
/// Enables printing debug log messages
///
public bool LoggingEnableDebug { get; set; }
///
/// Enables printing stub log messages
///
public bool LoggingEnableStub { get; set; }
///
/// Enables printing info log messages
///
public bool LoggingEnableInfo { get; set; }
///
/// Enables printing warning log messages
///
public bool LoggingEnableWarn { get; set; }
///
/// Enables printing error log messages
///
public bool LoggingEnableError { get; set; }
///
/// Enables printing guest log messages
///
public bool LoggingEnableGuest { get; set; }
///
/// Enables printing FS access log messages
///
public bool LoggingEnableFsAccessLog { get; set; }
///
/// Controls which log messages are written to the log targets
///
public LogClass[] LoggingFilteredClasses { get; set; }
///
/// Enables or disables logging to a file on disk
///
public bool EnableFileLog { get; set; }
///
/// Change System Language
///
public Language SystemLanguage { get; set; }
///
/// Change System Region
///
public Region SystemRegion { get; set; }
///
/// Change System TimeZone
///
public string SystemTimeZone { get; set; }
///
/// Change System Time Offset in seconds
///
public long SystemTimeOffset { get; set; }
///
/// Enables or disables Docked Mode
///
public bool DockedMode { get; set; }
///
/// Enables or disables Discord Rich Presence
///
public bool EnableDiscordIntegration { get; set; }
///
/// Enables or disables Vertical Sync
///
public bool EnableVsync { get; set; }
///
/// Enables or disables multi-core scheduling of threads
///
public bool EnableMulticoreScheduling { get; set; }
///
/// Enables integrity checks on Game content files
///
public bool EnableFsIntegrityChecks { get; set; }
///
/// Enables FS access log output to the console. Possible modes are 0-3
///
public int FsGlobalAccessLogMode { get; set; }
///
/// Enable or disable ignoring missing services
///
public bool IgnoreMissingServices { get; set; }
///
/// The primary controller's type
///
public ControllerType ControllerType { get; set; }
///
/// Used to toggle columns in the GUI
///
public GuiColumns GuiColumns { get; set; }
///
/// A list of directories containing games to be used to load games into the games list
///
public List GameDirs { get; set; }
///
/// Enable or disable custom themes in the GUI
///
public bool EnableCustomTheme { get; set; }
///
/// Path to custom GUI theme
///
public string CustomThemePath { get; set; }
///
/// Enable or disable keyboard support (Independent from controllers binding)
///
public bool EnableKeyboard { get; set; }
///
/// Keyboard control bindings
///
public NpadKeyboard KeyboardControls { get; set; }
///
/// Controller control bindings
///
public NpadController JoystickControls { get; set; }
///
/// Loads a configuration file from disk
///
/// The path to the JSON configuration file
public static ConfigurationFileFormat Load(string path)
{
var resolver = CompositeResolver.Create(
new[] { new ConfigurationEnumFormatter() },
new[] { StandardResolver.AllowPrivateSnakeCase }
);
using (Stream stream = File.OpenRead(path))
{
return JsonSerializer.Deserialize(stream, resolver);
}
}
///
/// Save a configuration file to disk
///
/// The path to the JSON configuration file
public void SaveConfig(string path)
{
IJsonFormatterResolver resolver = CompositeResolver.Create(
new[] { new ConfigurationEnumFormatter() },
new[] { StandardResolver.AllowPrivateSnakeCase }
);
byte[] data = JsonSerializer.Serialize(this, resolver);
File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
}
public class ConfigurationEnumFormatter : IJsonFormatter
where T : struct
{
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
{
formatterResolver.GetFormatterWithVerify()
.Serialize(ref writer, value.ToString(), formatterResolver);
}
public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
if (reader.ReadIsNull())
{
return default(T);
}
string enumName = formatterResolver.GetFormatterWithVerify()
.Deserialize(ref reader, formatterResolver);
if (Enum.TryParse(enumName, out T result))
{
return result;
}
return default(T);
}
}
}
}