Client rework for API change and paradigm shift (#39)
* most of the groups refactoring on client * register OnMethods for group stuff * start implementing client (still pretty broken) * finish implementing new api first iteration * idk rework everything for pair shit (still WIP); goal is to remove PairedClients and GroupPairClients from ApiController * move everything to PairManager, remove dictionaries from APiController * remove admin stuff from client, cleanup * adjust reconnection handling, add new settings, todo still to remove access from old stuff that's marked obsolete from config * add back adding servers, fix intro ui * fix obsolete calls * adjust config namespace * add UI for setting animation/sound permissions to syncshells * add ConfigurationService to hot reload config on change from external * move transient data cache to configuration * add deleting service to ui * fix saving of transient resources * fix group pair user assignments * halt scanner when penumbra inactive, add visible/online/offline split to individual pairs and tags * add presence to syncshell ui * move fullpause from config to server config * fixes in code style * more codestyle * show info icon on player in shells, don't show icon when no changes from default state are made, add online notifs * fixes to intro UI --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
81
MareSynchronos/MareConfiguration/ConfigurationService.cs
Normal file
81
MareSynchronos/MareConfiguration/ConfigurationService.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Dalamud.Plugin;
|
||||
using MareSynchronos.Utils;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ConfigurationService : IDisposable
|
||||
{
|
||||
private const string _configurationName = "Config.json";
|
||||
private string ConfigurationPath => Path.Combine(_pluginInterface.ConfigDirectory.FullName, _configurationName);
|
||||
public string ConfigurationDirectory => _pluginInterface.ConfigDirectory.FullName;
|
||||
private readonly DalamudPluginInterface _pluginInterface;
|
||||
private readonly CancellationTokenSource _periodicCheckCts = new();
|
||||
private DateTime _configLastWriteTime;
|
||||
|
||||
public MareConfig Current { get; private set; }
|
||||
|
||||
public ConfigurationService(DalamudPluginInterface pluginInterface)
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
|
||||
if (pluginInterface.GetPluginConfig() is Configuration oldConfig)
|
||||
{
|
||||
Current = oldConfig.ToMareConfig();
|
||||
File.Move(pluginInterface.ConfigFile.FullName, pluginInterface.ConfigFile.FullName + ".old", overwrite: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Current = LoadConfig();
|
||||
}
|
||||
|
||||
Save();
|
||||
|
||||
Task.Run(CheckForConfigUpdatesInternal, _periodicCheckCts.Token);
|
||||
}
|
||||
|
||||
private async Task CheckForConfigUpdatesInternal()
|
||||
{
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
var lastWriteTime = GetConfigLastWriteTime();
|
||||
if (lastWriteTime != _configLastWriteTime)
|
||||
{
|
||||
Logger.Debug("Config changed, reloading config");
|
||||
Current = LoadConfig();
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private MareConfig LoadConfig()
|
||||
{
|
||||
MareConfig config;
|
||||
if (!File.Exists(ConfigurationPath))
|
||||
{
|
||||
config = new();
|
||||
}
|
||||
else
|
||||
{
|
||||
config = JsonConvert.DeserializeObject<MareConfig>(File.ReadAllText(ConfigurationPath)) ?? new MareConfig();
|
||||
}
|
||||
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
return config;
|
||||
}
|
||||
|
||||
private DateTime GetConfigLastWriteTime() => new FileInfo(ConfigurationPath).LastWriteTimeUtc;
|
||||
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(ConfigurationPath, JsonConvert.SerializeObject(Current, Formatting.Indented));
|
||||
_configLastWriteTime = new FileInfo(ConfigurationPath).LastWriteTimeUtc;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Save();
|
||||
_periodicCheckCts.Cancel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user