mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: save plugin configs with type, in external directory
This commit is contained in:
parent
dabe178fd5
commit
6529b3429f
8 changed files with 64 additions and 40 deletions
|
|
@ -14,10 +14,10 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Label="Feature">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AssemblyVersion>4.7.11.0</AssemblyVersion>
|
||||
<FileVersion>4.7.11.0</FileVersion>
|
||||
<AssemblyVersion>4.7.12.0</AssemblyVersion>
|
||||
<FileVersion>4.7.12.0</FileVersion>
|
||||
<Description>XIVLauncher addon injection</Description>
|
||||
<Version>4.7.11.0</Version>
|
||||
<Version>4.7.12.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DocumentationFile></DocumentationFile>
|
||||
|
|
|
|||
|
|
@ -83,9 +83,9 @@ namespace Dalamud.Injector {
|
|||
ConfigurationPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
|
||||
@"\XIVLauncher\dalamudConfig.json",
|
||||
PluginDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
|
||||
@"\XIVLauncher\installedPluginsI",
|
||||
@"\XIVLauncher\installedPlugins",
|
||||
DefaultPluginDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
|
||||
@"\XIVLauncher\devPluginsI",
|
||||
@"\XIVLauncher\devPlugins",
|
||||
|
||||
GameVersion = "2020.02.11.0000.0000",
|
||||
Language = ClientLanguage.English
|
||||
|
|
|
|||
|
|
@ -29,14 +29,12 @@ namespace Dalamud
|
|||
|
||||
public string LastVersion { get; set; }
|
||||
|
||||
public Dictionary<string, object> PluginConfigurations { get; set; }
|
||||
|
||||
public static DalamudConfiguration Load(string path) {
|
||||
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
public void Save(string path) {
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(this));
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
Dalamud/Configuration/PluginConfigurations.cs
Normal file
43
Dalamud/Configuration/PluginConfigurations.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Configuration
|
||||
{
|
||||
public class PluginConfigurations {
|
||||
private DirectoryInfo configDirectory;
|
||||
|
||||
public PluginConfigurations(string storageFolder) {
|
||||
this.configDirectory = new DirectoryInfo(storageFolder);
|
||||
this.configDirectory.Create();
|
||||
}
|
||||
|
||||
public void Save(IPluginConfiguration config, string pluginName) {
|
||||
File.WriteAllText(GetPath(pluginName).FullName, JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects
|
||||
}));
|
||||
}
|
||||
|
||||
public IPluginConfiguration Load(string pluginName) {
|
||||
var path = GetPath(pluginName);
|
||||
|
||||
if (!path.Exists)
|
||||
return null;
|
||||
|
||||
return JsonConvert.DeserializeObject<IPluginConfiguration>(File.ReadAllText(path.FullName),
|
||||
new JsonSerializerSettings {
|
||||
TypeNameAssemblyFormatHandling =
|
||||
TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects
|
||||
});
|
||||
}
|
||||
|
||||
private FileInfo GetPath(string pluginName) => new FileInfo(Path.Combine(this.configDirectory.FullName, $"{pluginName}.json"));
|
||||
}
|
||||
}
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Label="Feature">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AssemblyVersion>4.7.11.0</AssemblyVersion>
|
||||
<Version>4.7.11.0</Version>
|
||||
<FileVersion>4.7.11.0</FileVersion>
|
||||
<AssemblyVersion>4.7.12.0</AssemblyVersion>
|
||||
<Version>4.7.12.0</Version>
|
||||
<FileVersion>4.7.12.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="Resources">
|
||||
<None Include="$(SolutionDir)/Resources/**/*" CopyToOutputDirectory="PreserveNewest" Visible="false" />
|
||||
|
|
@ -65,9 +65,6 @@
|
|||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Configuration\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\lib\Discord.Net\src\Discord.Net.Rest\Discord.Net.Rest.csproj" />
|
||||
<ProjectReference Include="..\lib\Discord.Net\src\Discord.Net.WebSocket\Discord.Net.WebSocket.csproj" />
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Dalamud.Game.Internal
|
|||
}
|
||||
|
||||
public void Enable() {
|
||||
this.debuggerPresentHook.Enable();
|
||||
//this.debuggerPresentHook.Enable();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
|
|
|||
|
|
@ -52,12 +52,13 @@ namespace Dalamud.Plugin
|
|||
|
||||
private readonly Dalamud dalamud;
|
||||
private readonly string pluginName;
|
||||
private readonly PluginConfigurations configs;
|
||||
|
||||
/// <summary>
|
||||
/// Set up the interface and populate all fields needed.
|
||||
/// </summary>
|
||||
/// <param name="dalamud"></param>
|
||||
public DalamudPluginInterface(Dalamud dalamud, string pluginName) {
|
||||
public DalamudPluginInterface(Dalamud dalamud, string pluginName, PluginConfigurations configs) {
|
||||
this.CommandManager = dalamud.CommandManager;
|
||||
this.Framework = dalamud.Framework;
|
||||
this.ClientState = dalamud.ClientState;
|
||||
|
|
@ -67,6 +68,7 @@ namespace Dalamud.Plugin
|
|||
|
||||
this.dalamud = dalamud;
|
||||
this.pluginName = pluginName;
|
||||
this.configs = configs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -81,20 +83,10 @@ namespace Dalamud.Plugin
|
|||
/// </summary>
|
||||
/// <param name="currentConfig">The current configuration.</param>
|
||||
public void SavePluginConfig(IPluginConfiguration currentConfig) {
|
||||
if (this.dalamud.Configuration.PluginConfigurations == null)
|
||||
this.dalamud.Configuration.PluginConfigurations = new Dictionary<string, object>();
|
||||
|
||||
if (currentConfig == null)
|
||||
return;
|
||||
|
||||
if (this.dalamud.Configuration.PluginConfigurations.ContainsKey(this.pluginName)) {
|
||||
this.dalamud.Configuration.PluginConfigurations[this.pluginName] = currentConfig;
|
||||
this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath);
|
||||
return;
|
||||
}
|
||||
|
||||
this.dalamud.Configuration.PluginConfigurations.Add(this.pluginName, currentConfig);
|
||||
this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath);
|
||||
this.configs.Save(currentConfig, this.pluginName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -102,18 +94,7 @@ namespace Dalamud.Plugin
|
|||
/// </summary>
|
||||
/// <returns>A previously saved config or null if none was saved before.</returns>
|
||||
public IPluginConfiguration GetPluginConfig() {
|
||||
if (this.dalamud.Configuration.PluginConfigurations == null)
|
||||
this.dalamud.Configuration.PluginConfigurations = new Dictionary<string, object>();
|
||||
|
||||
if (!this.dalamud.Configuration.PluginConfigurations.ContainsKey(this.pluginName))
|
||||
return null;
|
||||
|
||||
if (!(this.dalamud.Configuration.PluginConfigurations[this.pluginName] is IPluginConfiguration config))
|
||||
return null;
|
||||
|
||||
Serilog.Log.Information("Found plugin config for {0} v{1}", this.pluginName, config.Version);
|
||||
|
||||
return config;
|
||||
return this.configs.Load(this.pluginName);
|
||||
}
|
||||
|
||||
#region Logging
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dalamud.Configuration;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Plugin.Features;
|
||||
using ImGuiNET;
|
||||
|
|
@ -18,6 +19,8 @@ namespace Dalamud.Plugin
|
|||
private readonly string pluginDirectory;
|
||||
private readonly string devPluginDirectory;
|
||||
|
||||
private readonly PluginConfigurations pluginConfigs;
|
||||
|
||||
private readonly Type interfaceType = typeof(IDalamudPlugin);
|
||||
|
||||
public readonly List<(IDalamudPlugin Plugin, PluginDefinition Definition, DalamudPluginInterface PluginInterface)> Plugins = new List<(IDalamudPlugin plugin, PluginDefinition def, DalamudPluginInterface PluginInterface)>();
|
||||
|
|
@ -27,6 +30,8 @@ namespace Dalamud.Plugin
|
|||
this.pluginDirectory = pluginDirectory;
|
||||
this.devPluginDirectory = devPluginDirectory;
|
||||
|
||||
this.pluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(dalamud.StartInfo.ConfigurationPath), "pluginConfigs"));
|
||||
|
||||
this.dalamud.InterfaceManager.OnDraw += InterfaceManagerOnOnDraw;
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +122,7 @@ namespace Dalamud.Plugin
|
|||
|
||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(type);
|
||||
|
||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name);
|
||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs);
|
||||
plugin.Initialize(dalamudInterface);
|
||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||
this.Plugins.Add((plugin, pluginDef, dalamudInterface));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue