chore: convert Dalamud to file-scoped namespaces

This commit is contained in:
goat 2022-10-29 15:23:22 +02:00
parent b093323acc
commit 987ff8dc8f
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
368 changed files with 55081 additions and 55450 deletions

View file

@ -1,13 +1,12 @@
namespace Dalamud.Configuration
namespace Dalamud.Configuration;
/// <summary>
/// Configuration to store settings for a dalamud plugin.
/// </summary>
public interface IPluginConfiguration
{
/// <summary>
/// Configuration to store settings for a dalamud plugin.
/// Gets or sets configuration version.
/// </summary>
public interface IPluginConfiguration
{
/// <summary>
/// Gets or sets configuration version.
/// </summary>
int Version { get; set; }
}
int Version { get; set; }
}

View file

@ -10,368 +10,367 @@ using Newtonsoft.Json;
using Serilog;
using Serilog.Events;
namespace Dalamud.Configuration.Internal
namespace Dalamud.Configuration.Internal;
/// <summary>
/// Class containing Dalamud settings.
/// </summary>
[Serializable]
internal sealed class DalamudConfiguration : IServiceType
{
/// <summary>
/// Class containing Dalamud settings.
/// </summary>
[Serializable]
internal sealed class DalamudConfiguration : IServiceType
private static readonly JsonSerializerSettings SerializerSettings = new()
{
private static readonly JsonSerializerSettings SerializerSettings = new()
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
Formatting = Formatting.Indented,
};
[JsonIgnore]
private string configPath;
/// <summary>
/// Delegate for the <see cref="DalamudConfiguration.DalamudConfigurationSaved"/> event that occurs when the dalamud configuration is saved.
/// </summary>
/// <param name="dalamudConfiguration">The current dalamud configuration.</param>
public delegate void DalamudConfigurationSavedDelegate(DalamudConfiguration dalamudConfiguration);
/// <summary>
/// Event that occurs when dalamud configuration is saved.
/// </summary>
public event DalamudConfigurationSavedDelegate DalamudConfigurationSaved;
/// <summary>
/// Gets or sets a list of muted works.
/// </summary>
public List<string> BadWords { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the taskbar should flash once a duty is found.
/// </summary>
public bool DutyFinderTaskbarFlash { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not a message should be sent in chat once a duty is found.
/// </summary>
public bool DutyFinderChatMessage { get; set; } = true;
/// <summary>
/// Gets or sets the language code to load Dalamud localization with.
/// </summary>
public string LanguageOverride { get; set; } = null;
/// <summary>
/// Gets or sets the last loaded Dalamud version.
/// </summary>
public string LastVersion { get; set; } = null;
/// <summary>
/// Gets or sets the last loaded Dalamud version.
/// </summary>
public string LastChangelogMajorMinor { get; set; } = null;
/// <summary>
/// Gets or sets the chat type used by default for plugin messages.
/// </summary>
public XivChatType GeneralChatType { get; set; } = XivChatType.Debug;
/// <summary>
/// Gets or sets a value indicating whether or not plugin testing builds should be shown.
/// </summary>
public bool DoPluginTest { get; set; } = false;
/// <summary>
/// Gets or sets a key to opt into Dalamud staging builds.
/// </summary>
public string? DalamudBetaKey { get; set; } = null;
/// <summary>
/// Gets or sets a list of custom repos.
/// </summary>
public List<ThirdPartyRepoSettings> ThirdRepoList { get; set; } = new();
/// <summary>
/// Gets or sets a list of hidden plugins.
/// </summary>
public List<string> HiddenPluginInternalName { get; set; } = new();
/// <summary>
/// Gets or sets a list of seen plugins.
/// </summary>
public List<string> SeenPluginInternalName { get; set; } = new();
/// <summary>
/// Gets or sets a list of additional settings for devPlugins. The key is the absolute path
/// to the plugin DLL. This is automatically generated for any plugins in the devPlugins folder.
/// However by specifiying this value manually, you can add arbitrary files outside the normal
/// file paths.
/// </summary>
public Dictionary<string, DevPluginSettings> DevPluginSettings { get; set; } = new();
/// <summary>
/// Gets or sets a list of additional locations that dev plugins should be loaded from. This can
/// be either a DLL or folder, but should be the absolute path, or a path relative to the currently
/// injected Dalamud instance.
/// </summary>
public List<DevPluginLocationSettings> DevPluginLoadLocations { get; set; } = new();
/// <summary>
/// Gets or sets the global UI scale.
/// </summary>
public float GlobalUiScale { get; set; } = 1.0f;
/// <summary>
/// Gets or sets a value indicating whether to use AXIS fonts from the game.
/// </summary>
public bool UseAxisFontsFromGame { get; set; } = false;
/// <summary>
/// Gets or sets the gamma value to apply for Dalamud fonts. Effects text thickness.
///
/// Before gamma is applied...
/// * ...TTF fonts loaded with stb or FreeType are in linear space.
/// * ...the game's prebaked AXIS fonts are in gamma space with gamma value of 1.4.
/// </summary>
public float FontGammaLevel { get; set; } = 1.4f;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden.
/// </summary>
public bool ToggleUiHide { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden during cutscenes.
/// </summary>
public bool ToggleUiHideDuringCutscenes { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden during GPose.
/// </summary>
public bool ToggleUiHideDuringGpose { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not a message containing detailed plugin information should be sent at login.
/// </summary>
public bool PrintPluginsWelcomeMsg { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugins should be auto-updated.
/// </summary>
public bool AutoUpdatePlugins { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not Dalamud should add buttons to the system menu.
/// </summary>
public bool DoButtonsSystemMenu { get; set; } = true;
/// <summary>
/// Gets or sets the default Dalamud debug log level on startup.
/// </summary>
public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information;
/// <summary>
/// Gets or sets a value indicating whether to write to log files synchronously.
/// </summary>
public bool LogSynchronously { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether or not the debug log should scroll automatically.
/// </summary>
public bool LogAutoScroll { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not the debug log should open at startup.
/// </summary>
public bool LogOpenAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the dev bar should open at startup.
/// </summary>
public bool DevBarOpenAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not ImGui asserts should be enabled at startup.
/// </summary>
public bool AssertsEnabledAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not docking should be globally enabled in ImGui.
/// </summary>
public bool IsDocking { get; set; }
/// <summary>
/// Gets or sets a value indicating whether viewports should always be disabled.
/// </summary>
public bool IsDisableViewport { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not navigation via a gamepad should be globally enabled in ImGui.
/// </summary>
public bool IsGamepadNavigationEnabled { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not focus management is enabled.
/// </summary>
public bool IsFocusManagementEnabled { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup.
/// </summary>
public bool IsAntiAntiDebugEnabled { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether to resume game main thread after plugins load.
/// </summary>
public bool IsResumeGameAfterPluginLoad { get; set; } = false;
/// <summary>
/// Gets or sets the kind of beta to download when <see cref="DalamudBetaKey"/> matches the server value.
/// </summary>
public string DalamudBetaKind { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not any plugin should be loaded when the game is started.
/// It is reset immediately when read.
/// </summary>
public bool PluginSafeMode { get; set; }
/// <summary>
/// Gets or sets a value indicating the wait time between plugin unload and plugin assembly unload.
/// Uses default value that may change between versions if set to null.
/// </summary>
public int? PluginWaitBeforeFree { get; set; }
/// <summary>
/// Gets or sets a list of saved styles.
/// </summary>
[JsonProperty("SavedStyles")]
public List<StyleModelV1>? SavedStylesOld { get; set; }
/// <summary>
/// Gets or sets a list of saved styles.
/// </summary>
[JsonProperty("SavedStylesVersioned")]
public List<StyleModel>? SavedStyles { get; set; }
/// <summary>
/// Gets or sets the name of the currently chosen style.
/// </summary>
public string ChosenStyle { get; set; } = "Dalamud Standard";
/// <summary>
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
/// </summary>
public bool DisableRmtFiltering { get; set; }
/// <summary>
/// Gets or sets the order of DTR elements, by title.
/// </summary>
public List<string>? DtrOrder { get; set; }
/// <summary>
/// Gets or sets the list of ignored DTR elements, by title.
/// </summary>
public List<string>? DtrIgnore { get; set; }
/// <summary>
/// Gets or sets the spacing used for DTR entries.
/// </summary>
public int DtrSpacing { get; set; } = 10;
/// <summary>
/// Gets or sets a value indicating whether to swap the
/// direction in which elements are drawn in the DTR.
/// False indicates that elements will be drawn from the end of
/// the left side of the Server Info bar, and continue leftwards.
/// True indicates the opposite.
/// </summary>
public bool DtrSwapDirection { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the title screen menu is shown.
/// </summary>
public bool ShowTsm { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not market board data should be uploaded.
/// </summary>
public bool IsMbCollect { get; set; } = true;
/// <summary>
/// Gets the ISO 639-1 two-letter code for the language of the effective Dalamud display language.
/// </summary>
public string EffectiveLanguage
{
get
{
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
Formatting = Formatting.Indented,
};
[JsonIgnore]
private string configPath;
/// <summary>
/// Delegate for the <see cref="DalamudConfiguration.DalamudConfigurationSaved"/> event that occurs when the dalamud configuration is saved.
/// </summary>
/// <param name="dalamudConfiguration">The current dalamud configuration.</param>
public delegate void DalamudConfigurationSavedDelegate(DalamudConfiguration dalamudConfiguration);
/// <summary>
/// Event that occurs when dalamud configuration is saved.
/// </summary>
public event DalamudConfigurationSavedDelegate DalamudConfigurationSaved;
/// <summary>
/// Gets or sets a list of muted works.
/// </summary>
public List<string> BadWords { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the taskbar should flash once a duty is found.
/// </summary>
public bool DutyFinderTaskbarFlash { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not a message should be sent in chat once a duty is found.
/// </summary>
public bool DutyFinderChatMessage { get; set; } = true;
/// <summary>
/// Gets or sets the language code to load Dalamud localization with.
/// </summary>
public string LanguageOverride { get; set; } = null;
/// <summary>
/// Gets or sets the last loaded Dalamud version.
/// </summary>
public string LastVersion { get; set; } = null;
/// <summary>
/// Gets or sets the last loaded Dalamud version.
/// </summary>
public string LastChangelogMajorMinor { get; set; } = null;
/// <summary>
/// Gets or sets the chat type used by default for plugin messages.
/// </summary>
public XivChatType GeneralChatType { get; set; } = XivChatType.Debug;
/// <summary>
/// Gets or sets a value indicating whether or not plugin testing builds should be shown.
/// </summary>
public bool DoPluginTest { get; set; } = false;
/// <summary>
/// Gets or sets a key to opt into Dalamud staging builds.
/// </summary>
public string? DalamudBetaKey { get; set; } = null;
/// <summary>
/// Gets or sets a list of custom repos.
/// </summary>
public List<ThirdPartyRepoSettings> ThirdRepoList { get; set; } = new();
/// <summary>
/// Gets or sets a list of hidden plugins.
/// </summary>
public List<string> HiddenPluginInternalName { get; set; } = new();
/// <summary>
/// Gets or sets a list of seen plugins.
/// </summary>
public List<string> SeenPluginInternalName { get; set; } = new();
/// <summary>
/// Gets or sets a list of additional settings for devPlugins. The key is the absolute path
/// to the plugin DLL. This is automatically generated for any plugins in the devPlugins folder.
/// However by specifiying this value manually, you can add arbitrary files outside the normal
/// file paths.
/// </summary>
public Dictionary<string, DevPluginSettings> DevPluginSettings { get; set; } = new();
/// <summary>
/// Gets or sets a list of additional locations that dev plugins should be loaded from. This can
/// be either a DLL or folder, but should be the absolute path, or a path relative to the currently
/// injected Dalamud instance.
/// </summary>
public List<DevPluginLocationSettings> DevPluginLoadLocations { get; set; } = new();
/// <summary>
/// Gets or sets the global UI scale.
/// </summary>
public float GlobalUiScale { get; set; } = 1.0f;
/// <summary>
/// Gets or sets a value indicating whether to use AXIS fonts from the game.
/// </summary>
public bool UseAxisFontsFromGame { get; set; } = false;
/// <summary>
/// Gets or sets the gamma value to apply for Dalamud fonts. Effects text thickness.
///
/// Before gamma is applied...
/// * ...TTF fonts loaded with stb or FreeType are in linear space.
/// * ...the game's prebaked AXIS fonts are in gamma space with gamma value of 1.4.
/// </summary>
public float FontGammaLevel { get; set; } = 1.4f;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden.
/// </summary>
public bool ToggleUiHide { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden during cutscenes.
/// </summary>
public bool ToggleUiHideDuringCutscenes { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugin UI should be hidden during GPose.
/// </summary>
public bool ToggleUiHideDuringGpose { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not a message containing detailed plugin information should be sent at login.
/// </summary>
public bool PrintPluginsWelcomeMsg { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not plugins should be auto-updated.
/// </summary>
public bool AutoUpdatePlugins { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not Dalamud should add buttons to the system menu.
/// </summary>
public bool DoButtonsSystemMenu { get; set; } = true;
/// <summary>
/// Gets or sets the default Dalamud debug log level on startup.
/// </summary>
public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information;
/// <summary>
/// Gets or sets a value indicating whether to write to log files synchronously.
/// </summary>
public bool LogSynchronously { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether or not the debug log should scroll automatically.
/// </summary>
public bool LogAutoScroll { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not the debug log should open at startup.
/// </summary>
public bool LogOpenAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the dev bar should open at startup.
/// </summary>
public bool DevBarOpenAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not ImGui asserts should be enabled at startup.
/// </summary>
public bool AssertsEnabledAtStartup { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not docking should be globally enabled in ImGui.
/// </summary>
public bool IsDocking { get; set; }
/// <summary>
/// Gets or sets a value indicating whether viewports should always be disabled.
/// </summary>
public bool IsDisableViewport { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not navigation via a gamepad should be globally enabled in ImGui.
/// </summary>
public bool IsGamepadNavigationEnabled { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not focus management is enabled.
/// </summary>
public bool IsFocusManagementEnabled { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup.
/// </summary>
public bool IsAntiAntiDebugEnabled { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether to resume game main thread after plugins load.
/// </summary>
public bool IsResumeGameAfterPluginLoad { get; set; } = false;
/// <summary>
/// Gets or sets the kind of beta to download when <see cref="DalamudBetaKey"/> matches the server value.
/// </summary>
public string DalamudBetaKind { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not any plugin should be loaded when the game is started.
/// It is reset immediately when read.
/// </summary>
public bool PluginSafeMode { get; set; }
/// <summary>
/// Gets or sets a value indicating the wait time between plugin unload and plugin assembly unload.
/// Uses default value that may change between versions if set to null.
/// </summary>
public int? PluginWaitBeforeFree { get; set; }
/// <summary>
/// Gets or sets a list of saved styles.
/// </summary>
[JsonProperty("SavedStyles")]
public List<StyleModelV1>? SavedStylesOld { get; set; }
/// <summary>
/// Gets or sets a list of saved styles.
/// </summary>
[JsonProperty("SavedStylesVersioned")]
public List<StyleModel>? SavedStyles { get; set; }
/// <summary>
/// Gets or sets the name of the currently chosen style.
/// </summary>
public string ChosenStyle { get; set; } = "Dalamud Standard";
/// <summary>
/// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled.
/// </summary>
public bool DisableRmtFiltering { get; set; }
/// <summary>
/// Gets or sets the order of DTR elements, by title.
/// </summary>
public List<string>? DtrOrder { get; set; }
/// <summary>
/// Gets or sets the list of ignored DTR elements, by title.
/// </summary>
public List<string>? DtrIgnore { get; set; }
/// <summary>
/// Gets or sets the spacing used for DTR entries.
/// </summary>
public int DtrSpacing { get; set; } = 10;
/// <summary>
/// Gets or sets a value indicating whether to swap the
/// direction in which elements are drawn in the DTR.
/// False indicates that elements will be drawn from the end of
/// the left side of the Server Info bar, and continue leftwards.
/// True indicates the opposite.
/// </summary>
public bool DtrSwapDirection { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the title screen menu is shown.
/// </summary>
public bool ShowTsm { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not market board data should be uploaded.
/// </summary>
public bool IsMbCollect { get; set; } = true;
/// <summary>
/// Gets the ISO 639-1 two-letter code for the language of the effective Dalamud display language.
/// </summary>
public string EffectiveLanguage
{
get
{
var languages = Localization.ApplicableLangCodes.Prepend("en").ToArray();
try
{
if (string.IsNullOrEmpty(this.LanguageOverride))
{
var currentUiLang = CultureInfo.CurrentUICulture;
if (Localization.ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x))
return currentUiLang.TwoLetterISOLanguageName;
else
return languages[0];
}
else
{
return this.LanguageOverride;
}
}
catch (Exception)
{
return languages[0];
}
}
}
/// <summary>
/// Gets or sets a value indicating whether or not to show info on dev bar.
/// </summary>
public bool ShowDevBarInfo { get; set; } = true;
/// <summary>
/// Gets or sets the last-used contact details for the plugin feedback form.
/// </summary>
public string LastFeedbackContactDetails { get; set; } = string.Empty;
/// <summary>
/// Gets or sets a list of plugins that testing builds should be downloaded for.
/// </summary>
public List<PluginTestingOptIn>? PluginTestingOptIns { get; set; }
/// <summary>
/// Load a configuration from the provided path.
/// </summary>
/// <param name="path">The path to load the configuration file from.</param>
/// <returns>The deserialized configuration file.</returns>
public static DalamudConfiguration Load(string path)
{
DalamudConfiguration deserialized = null;
var languages = Localization.ApplicableLangCodes.Prepend("en").ToArray();
try
{
deserialized = JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path), SerializerSettings);
if (string.IsNullOrEmpty(this.LanguageOverride))
{
var currentUiLang = CultureInfo.CurrentUICulture;
if (Localization.ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x))
return currentUiLang.TwoLetterISOLanguageName;
else
return languages[0];
}
else
{
return this.LanguageOverride;
}
}
catch (Exception ex)
catch (Exception)
{
Log.Warning(ex, "Failed to load DalamudConfiguration at {0}", path);
return languages[0];
}
deserialized ??= new DalamudConfiguration();
deserialized.configPath = path;
return deserialized;
}
/// <summary>
/// Save the configuration at the path it was loaded from.
/// </summary>
public void Save()
{
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
this.DalamudConfigurationSaved?.Invoke(this);
}
}
/// <summary>
/// Gets or sets a value indicating whether or not to show info on dev bar.
/// </summary>
public bool ShowDevBarInfo { get; set; } = true;
/// <summary>
/// Gets or sets the last-used contact details for the plugin feedback form.
/// </summary>
public string LastFeedbackContactDetails { get; set; } = string.Empty;
/// <summary>
/// Gets or sets a list of plugins that testing builds should be downloaded for.
/// </summary>
public List<PluginTestingOptIn>? PluginTestingOptIns { get; set; }
/// <summary>
/// Load a configuration from the provided path.
/// </summary>
/// <param name="path">The path to load the configuration file from.</param>
/// <returns>The deserialized configuration file.</returns>
public static DalamudConfiguration Load(string path)
{
DalamudConfiguration deserialized = null;
try
{
deserialized = JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path), SerializerSettings);
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to load DalamudConfiguration at {0}", path);
}
deserialized ??= new DalamudConfiguration();
deserialized.configPath = path;
return deserialized;
}
/// <summary>
/// Save the configuration at the path it was loaded from.
/// </summary>
public void Save()
{
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
this.DalamudConfigurationSaved?.Invoke(this);
}
}

View file

@ -1,24 +1,23 @@
namespace Dalamud.Configuration
namespace Dalamud.Configuration;
/// <summary>
/// Additional locations to load dev plugins from.
/// </summary>
internal sealed class DevPluginLocationSettings
{
/// <summary>
/// Additional locations to load dev plugins from.
/// Gets or sets the dev pluign path.
/// </summary>
internal sealed class DevPluginLocationSettings
{
/// <summary>
/// Gets or sets the dev pluign path.
/// </summary>
public string Path { get; set; }
public string Path { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the third party repo is enabled.
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the third party repo is enabled.
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// Clone this object.
/// </summary>
/// <returns>A shallow copy of this object.</returns>
public DevPluginLocationSettings Clone() => this.MemberwiseClone() as DevPluginLocationSettings;
}
/// <summary>
/// Clone this object.
/// </summary>
/// <returns>A shallow copy of this object.</returns>
public DevPluginLocationSettings Clone() => this.MemberwiseClone() as DevPluginLocationSettings;
}

View file

@ -1,18 +1,17 @@
namespace Dalamud.Configuration.Internal
namespace Dalamud.Configuration.Internal;
/// <summary>
/// Settings for DevPlugins.
/// </summary>
internal sealed class DevPluginSettings
{
/// <summary>
/// Settings for DevPlugins.
/// Gets or sets a value indicating whether this plugin should automatically start when Dalamud boots up.
/// </summary>
internal sealed class DevPluginSettings
{
/// <summary>
/// Gets or sets a value indicating whether this plugin should automatically start when Dalamud boots up.
/// </summary>
public bool StartOnBoot { get; set; } = true;
public bool StartOnBoot { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this plugin should automatically reload on file change.
/// </summary>
public bool AutomaticReloading { get; set; } = false;
}
/// <summary>
/// Gets or sets a value indicating whether this plugin should automatically reload on file change.
/// </summary>
public bool AutomaticReloading { get; set; } = false;
}

View file

@ -1,38 +1,37 @@
using System;
namespace Dalamud.Configuration.Internal
namespace Dalamud.Configuration.Internal;
/// <summary>
/// Environmental configuration settings.
/// </summary>
internal class EnvironmentConfiguration
{
/// <summary>
/// Environmental configuration settings.
/// Gets a value indicating whether the XL_WINEONLINUX setting has been enabled.
/// </summary>
internal class EnvironmentConfiguration
{
/// <summary>
/// Gets a value indicating whether the XL_WINEONLINUX setting has been enabled.
/// </summary>
public static bool XlWineOnLinux { get; } = GetEnvironmentVariable("XL_WINEONLINUX");
public static bool XlWineOnLinux { get; } = GetEnvironmentVariable("XL_WINEONLINUX");
/// <summary>
/// Gets a value indicating whether the DALAMUD_NOT_HAVE_PLUGINS setting has been enabled.
/// </summary>
public static bool DalamudNoPlugins { get; } = GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS");
/// <summary>
/// Gets a value indicating whether the DALAMUD_NOT_HAVE_PLUGINS setting has been enabled.
/// </summary>
public static bool DalamudNoPlugins { get; } = GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS");
/// <summary>
/// Gets a value indicating whether the DalamudForceReloaded setting has been enabled.
/// </summary>
public static bool DalamudForceReloaded { get; } = GetEnvironmentVariable("DALAMUD_FORCE_RELOADED");
/// <summary>
/// Gets a value indicating whether the DalamudForceReloaded setting has been enabled.
/// </summary>
public static bool DalamudForceReloaded { get; } = GetEnvironmentVariable("DALAMUD_FORCE_RELOADED");
/// <summary>
/// Gets a value indicating whether the DalamudForceMinHook setting has been enabled.
/// </summary>
public static bool DalamudForceMinHook { get; } = GetEnvironmentVariable("DALAMUD_FORCE_MINHOOK");
/// <summary>
/// Gets a value indicating whether the DalamudForceMinHook setting has been enabled.
/// </summary>
public static bool DalamudForceMinHook { get; } = GetEnvironmentVariable("DALAMUD_FORCE_MINHOOK");
/// <summary>
/// Gets a value indicating whether or not Dalamud context menus should be disabled.
/// </summary>
public static bool DalamudDoContextMenu { get; } = GetEnvironmentVariable("DALAMUD_ENABLE_CONTEXTMENU");
/// <summary>
/// Gets a value indicating whether or not Dalamud context menus should be disabled.
/// </summary>
public static bool DalamudDoContextMenu { get; } = GetEnvironmentVariable("DALAMUD_ENABLE_CONTEXTMENU");
private static bool GetEnvironmentVariable(string name)
=> bool.Parse(Environment.GetEnvironmentVariable(name) ?? "false");
}
private static bool GetEnvironmentVariable(string name)
=> bool.Parse(Environment.GetEnvironmentVariable(name) ?? "false");
}

View file

@ -1,29 +1,28 @@
namespace Dalamud.Configuration
namespace Dalamud.Configuration;
/// <summary>
/// Third party repository for dalamud plugins.
/// </summary>
internal sealed class ThirdPartyRepoSettings
{
/// <summary>
/// Third party repository for dalamud plugins.
/// Gets or sets the third party repo url.
/// </summary>
internal sealed class ThirdPartyRepoSettings
{
/// <summary>
/// Gets or sets the third party repo url.
/// </summary>
public string Url { get; set; }
public string Url { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the third party repo is enabled.
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the third party repo is enabled.
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// Gets or sets a short name for the repo url.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets a short name for the repo url.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Clone this object.
/// </summary>
/// <returns>A shallow copy of this object.</returns>
public ThirdPartyRepoSettings Clone() => this.MemberwiseClone() as ThirdPartyRepoSettings;
}
/// <summary>
/// Clone this object.
/// </summary>
/// <returns>A shallow copy of this object.</returns>
public ThirdPartyRepoSettings Clone() => this.MemberwiseClone() as ThirdPartyRepoSettings;
}

View file

@ -2,149 +2,148 @@ using System.IO;
using Newtonsoft.Json;
namespace Dalamud.Configuration
namespace Dalamud.Configuration;
/// <summary>
/// Configuration to store settings for a dalamud plugin.
/// </summary>
public sealed class PluginConfigurations
{
private readonly DirectoryInfo configDirectory;
/// <summary>
/// Configuration to store settings for a dalamud plugin.
/// Initializes a new instance of the <see cref="PluginConfigurations"/> class.
/// </summary>
public sealed class PluginConfigurations
/// <param name="storageFolder">Directory for storage of plugin configuration files.</param>
public PluginConfigurations(string storageFolder)
{
private readonly DirectoryInfo configDirectory;
this.configDirectory = new DirectoryInfo(storageFolder);
this.configDirectory.Create();
}
/// <summary>
/// Initializes a new instance of the <see cref="PluginConfigurations"/> class.
/// </summary>
/// <param name="storageFolder">Directory for storage of plugin configuration files.</param>
public PluginConfigurations(string storageFolder)
/// <summary>
/// Save/Load plugin configuration.
/// NOTE: Save/Load are still using Type information for now,
/// despite LoadForType superseding Load and not requiring or using it.
/// It might be worth removing the Type info from Save, to strip it from all future saved configs,
/// and then Load() can probably be removed entirely.
/// </summary>
/// <param name="config">Plugin configuration.</param>
/// <param name="pluginName">Plugin name.</param>
public void Save(IPluginConfiguration config, string pluginName)
{
File.WriteAllText(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
}
/// <summary>
/// Load plugin configuration.
/// </summary>
/// <param name="pluginName">Plugin name.</param>
/// <returns>Plugin configuration.</returns>
public IPluginConfiguration? Load(string pluginName)
{
var path = this.GetConfigFile(pluginName);
if (!path.Exists)
return null;
return DeserializeConfig(File.ReadAllText(path.FullName));
}
/// <summary>
/// Delete the configuration file and folder for the specified plugin.
/// This will throw an <see cref="IOException"/> if the plugin did not correctly close its handles.
/// </summary>
/// <param name="pluginName">The name of the plugin.</param>
public void Delete(string pluginName)
{
var directory = this.GetDirectoryPath(pluginName);
if (directory.Exists)
directory.Delete(true);
var file = this.GetConfigFile(pluginName);
if (file.Exists)
file.Delete();
}
/// <summary>
/// Get plugin directory.
/// </summary>
/// <param name="pluginName">Plugin name.</param>
/// <returns>Plugin directory path.</returns>
public string GetDirectory(string pluginName)
{
try
{
this.configDirectory = new DirectoryInfo(storageFolder);
this.configDirectory.Create();
}
/// <summary>
/// Save/Load plugin configuration.
/// NOTE: Save/Load are still using Type information for now,
/// despite LoadForType superseding Load and not requiring or using it.
/// It might be worth removing the Type info from Save, to strip it from all future saved configs,
/// and then Load() can probably be removed entirely.
/// </summary>
/// <param name="config">Plugin configuration.</param>
/// <param name="pluginName">Plugin name.</param>
public void Save(IPluginConfiguration config, string pluginName)
{
File.WriteAllText(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
}
/// <summary>
/// Load plugin configuration.
/// </summary>
/// <param name="pluginName">Plugin name.</param>
/// <returns>Plugin configuration.</returns>
public IPluginConfiguration? Load(string pluginName)
{
var path = this.GetConfigFile(pluginName);
var path = this.GetDirectoryPath(pluginName);
if (!path.Exists)
return null;
return DeserializeConfig(File.ReadAllText(path.FullName));
}
/// <summary>
/// Delete the configuration file and folder for the specified plugin.
/// This will throw an <see cref="IOException"/> if the plugin did not correctly close its handles.
/// </summary>
/// <param name="pluginName">The name of the plugin.</param>
public void Delete(string pluginName)
{
var directory = this.GetDirectoryPath(pluginName);
if (directory.Exists)
directory.Delete(true);
var file = this.GetConfigFile(pluginName);
if (file.Exists)
file.Delete();
}
/// <summary>
/// Get plugin directory.
/// </summary>
/// <param name="pluginName">Plugin name.</param>
/// <returns>Plugin directory path.</returns>
public string GetDirectory(string pluginName)
{
try
{
var path = this.GetDirectoryPath(pluginName);
if (!path.Exists)
{
path.Create();
}
return path.FullName;
}
catch
{
return string.Empty;
path.Create();
}
return path.FullName;
}
/// <summary>
/// Load Plugin configuration. Parameterized deserialization.
/// Currently this is called via reflection from DalamudPluginInterface.GetPluginConfig().
/// Eventually there may be an additional pluginInterface method that can call this directly
/// without reflection - for now this is in support of the existing plugin api.
/// </summary>
/// <param name="pluginName">Plugin Name.</param>
/// <typeparam name="T">Configuration Type.</typeparam>
/// <returns>Plugin Configuration.</returns>
public T LoadForType<T>(string pluginName) where T : IPluginConfiguration
catch
{
var path = this.GetConfigFile(pluginName);
return !path.Exists ? default : JsonConvert.DeserializeObject<T>(File.ReadAllText(path.FullName));
// intentionally no type handling - it will break when updating a plugin at runtime
// and turns out to be unnecessary when we fully qualify the object type
return string.Empty;
}
}
/// <summary>
/// Get FileInfo to plugin config file.
/// </summary>
/// <param name="pluginName">InternalName of the plugin.</param>
/// <returns>FileInfo of the config file.</returns>
public FileInfo GetConfigFile(string pluginName) => new(Path.Combine(this.configDirectory.FullName, $"{pluginName}.json"));
/// <summary>
/// Load Plugin configuration. Parameterized deserialization.
/// Currently this is called via reflection from DalamudPluginInterface.GetPluginConfig().
/// Eventually there may be an additional pluginInterface method that can call this directly
/// without reflection - for now this is in support of the existing plugin api.
/// </summary>
/// <param name="pluginName">Plugin Name.</param>
/// <typeparam name="T">Configuration Type.</typeparam>
/// <returns>Plugin Configuration.</returns>
public T LoadForType<T>(string pluginName) where T : IPluginConfiguration
{
var path = this.GetConfigFile(pluginName);
/// <summary>
/// Serializes a plugin configuration object.
/// </summary>
/// <param name="config">The configuration object.</param>
/// <returns>A string representing the serialized configuration object.</returns>
internal static string SerializeConfig(object? config)
return !path.Exists ? default : JsonConvert.DeserializeObject<T>(File.ReadAllText(path.FullName));
// intentionally no type handling - it will break when updating a plugin at runtime
// and turns out to be unnecessary when we fully qualify the object type
}
/// <summary>
/// Get FileInfo to plugin config file.
/// </summary>
/// <param name="pluginName">InternalName of the plugin.</param>
/// <returns>FileInfo of the config file.</returns>
public FileInfo GetConfigFile(string pluginName) => new(Path.Combine(this.configDirectory.FullName, $"{pluginName}.json"));
/// <summary>
/// Serializes a plugin configuration object.
/// </summary>
/// <param name="config">The configuration object.</param>
/// <returns>A string representing the serialized configuration object.</returns>
internal static string SerializeConfig(object? config)
{
return JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
{
return JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
TypeNameHandling = TypeNameHandling.Objects,
});
}
/// <summary>
/// Deserializes a plugin configuration from a string.
/// </summary>
/// <param name="data">The serialized configuration.</param>
/// <returns>The configuration object, or null.</returns>
internal static IPluginConfiguration? DeserializeConfig(string data)
{
return JsonConvert.DeserializeObject<IPluginConfiguration>(
data,
new JsonSerializerSettings
{
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
TypeNameHandling = TypeNameHandling.Objects,
});
}
/// <summary>
/// Deserializes a plugin configuration from a string.
/// </summary>
/// <param name="data">The serialized configuration.</param>
/// <returns>The configuration object, or null.</returns>
internal static IPluginConfiguration? DeserializeConfig(string data)
{
return JsonConvert.DeserializeObject<IPluginConfiguration>(
data,
new JsonSerializerSettings
{
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
TypeNameHandling = TypeNameHandling.Objects,
});
}
private DirectoryInfo GetDirectoryPath(string pluginName) => new(Path.Combine(this.configDirectory.FullName, pluginName));
}
private DirectoryInfo GetDirectoryPath(string pluginName) => new(Path.Combine(this.configDirectory.FullName, pluginName));
}