[Draft] Update 0.8 (#46)
* move stuff out into file transfer manager * obnoxious unsupported version text, adjustments to filetransfermanager * add back file upload transfer progress * restructure code * cleanup some more stuff I guess * downloadids by playername * individual anim/sound bs * fix migration stuff, finalize impl of individual sound/anim pause * fixes with logging stuff * move download manager to transient * rework dl ui first iteration * some refactoring and cleanup * more code cleanup * refactoring * switch to hostbuilder * some more rework I guess * more refactoring * clean up mediator calls and disposal * fun code cleanup * push error message when log level is set to anything but information in non-debug builds * remove notificationservice * move message to after login * add download bars to gameworld * fixes download progress bar * set gpose ui min and max size * remove unnecessary usings * adjustments to reconnection logic * add options to set visible/offline groups visibility * add impl of uploading display, transfer list in settings ui * attempt to fix issues with server selection * add back download status to compact ui * make dl bar fixed size based * some fixes for upload/download handling * adjust text from Syncing back to Uploading --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com> Co-authored-by: Stanley Dimant <stanley.dimant@varian.com>
This commit is contained in:
@@ -1,26 +1,18 @@
|
||||
using Dalamud.Plugin;
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public abstract class ConfigurationServiceBase<T> : IDisposable where T : IMareConfiguration
|
||||
{
|
||||
protected abstract string ConfigurationName { get; }
|
||||
public string ConfigurationDirectory => _pluginInterface.ConfigDirectory.FullName;
|
||||
public T Current => _currentConfigInternal.Value;
|
||||
|
||||
protected readonly DalamudPluginInterface _pluginInterface;
|
||||
private readonly CancellationTokenSource _periodicCheckCts = new();
|
||||
private DateTime _configLastWriteTime;
|
||||
private bool _configIsDirty = false;
|
||||
private DateTime _configLastWriteTime;
|
||||
private Lazy<T> _currentConfigInternal;
|
||||
|
||||
protected string ConfigurationPath => Path.Combine(ConfigurationDirectory, ConfigurationName);
|
||||
protected ConfigurationServiceBase(DalamudPluginInterface pluginInterface)
|
||||
protected ConfigurationServiceBase(string configurationDirectory)
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
ConfigurationDirectory = configurationDirectory;
|
||||
|
||||
Task.Run(CheckForConfigUpdatesInternal, _periodicCheckCts.Token);
|
||||
Task.Run(CheckForDirtyConfigInternal, _periodicCheckCts.Token);
|
||||
@@ -28,39 +20,26 @@ public abstract class ConfigurationServiceBase<T> : IDisposable where T : IMareC
|
||||
_currentConfigInternal = LazyConfig();
|
||||
}
|
||||
|
||||
private Lazy<T> LazyConfig()
|
||||
{
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
return new Lazy<T>(() => LoadConfig());
|
||||
}
|
||||
private DateTime GetConfigLastWriteTime() => new FileInfo(ConfigurationPath).LastWriteTimeUtc;
|
||||
public string ConfigurationDirectory { get; init; }
|
||||
public T Current => _currentConfigInternal.Value;
|
||||
protected abstract string ConfigurationName { get; }
|
||||
protected string ConfigurationPath => Path.Combine(ConfigurationDirectory, ConfigurationName);
|
||||
|
||||
private async Task CheckForConfigUpdatesInternal()
|
||||
public void Dispose()
|
||||
{
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
|
||||
var lastWriteTime = GetConfigLastWriteTime();
|
||||
if (lastWriteTime != _configLastWriteTime)
|
||||
{
|
||||
//_logger.LogDebug($"Config {ConfigurationName} changed, reloading config");
|
||||
_currentConfigInternal = LazyConfig();
|
||||
}
|
||||
}
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private async Task CheckForDirtyConfigInternal()
|
||||
public void Save()
|
||||
{
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
if (_configIsDirty)
|
||||
{
|
||||
SaveDirtyConfig();
|
||||
}
|
||||
_configIsDirty = true;
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
}
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
_periodicCheckCts.Cancel();
|
||||
_periodicCheckCts.Dispose();
|
||||
}
|
||||
|
||||
protected T LoadConfig()
|
||||
@@ -73,7 +52,7 @@ public abstract class ConfigurationServiceBase<T> : IDisposable where T : IMareC
|
||||
}
|
||||
else
|
||||
{
|
||||
config = JsonConvert.DeserializeObject<T>(File.ReadAllText(ConfigurationPath));
|
||||
config = JsonSerializer.Deserialize<T>(File.ReadAllText(ConfigurationPath));
|
||||
if (config == null)
|
||||
{
|
||||
config = (T)Activator.CreateInstance(typeof(T))!;
|
||||
@@ -98,26 +77,54 @@ public abstract class ConfigurationServiceBase<T> : IDisposable where T : IMareC
|
||||
}
|
||||
}
|
||||
|
||||
//_logger.LogDebug("Saving dirty config " + ConfigurationName);
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(ConfigurationPath, ConfigurationPath + ".bak." + DateTime.Now.ToString("yyyyMMddHHmmss"), overwrite: true);
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
// ignore if file cannot be backupped once
|
||||
}
|
||||
|
||||
File.WriteAllText(ConfigurationPath, JsonConvert.SerializeObject(Current, Formatting.Indented));
|
||||
File.WriteAllText(ConfigurationPath, JsonSerializer.Serialize(Current, new JsonSerializerOptions()
|
||||
{
|
||||
WriteIndented = true
|
||||
}));
|
||||
_configLastWriteTime = new FileInfo(ConfigurationPath).LastWriteTimeUtc;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
private async Task CheckForConfigUpdatesInternal()
|
||||
{
|
||||
_configIsDirty = true;
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
|
||||
var lastWriteTime = GetConfigLastWriteTime();
|
||||
if (lastWriteTime != _configLastWriteTime)
|
||||
{
|
||||
_currentConfigInternal = LazyConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
private async Task CheckForDirtyConfigInternal()
|
||||
{
|
||||
//_logger.LogTrace($"Disposing {GetType()}");
|
||||
_periodicCheckCts.Cancel();
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
if (_configIsDirty)
|
||||
{
|
||||
SaveDirtyConfig();
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime GetConfigLastWriteTime() => new FileInfo(ConfigurationPath).LastWriteTimeUtc;
|
||||
|
||||
private Lazy<T> LazyConfig()
|
||||
{
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
return new Lazy<T>(LoadConfig);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user