Initial
This commit is contained in:
11
MareSynchronos/MareConfiguration/CharaDataConfigService.cs
Normal file
11
MareSynchronos/MareConfiguration/CharaDataConfigService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class CharaDataConfigService : ConfigurationServiceBase<CharaDataConfig>
|
||||
{
|
||||
public const string ConfigName = "charadata.json";
|
||||
|
||||
public CharaDataConfigService(string configDir) : base(configDir) { }
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
13
MareSynchronos/MareConfiguration/ConfigurationExtensions.cs
Normal file
13
MareSynchronos/MareConfiguration/ConfigurationExtensions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
public static bool HasValidSetup(this MareConfig configuration)
|
||||
{
|
||||
return configuration.AcceptedAgreement && configuration.InitialScanComplete
|
||||
&& !string.IsNullOrEmpty(configuration.CacheFolder)
|
||||
&& Directory.Exists(configuration.CacheFolder);
|
||||
}
|
||||
}
|
25
MareSynchronos/MareConfiguration/ConfigurationMigrator.cs
Normal file
25
MareSynchronos/MareConfiguration/ConfigurationMigrator.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using MareSynchronos.WebAPI;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ConfigurationMigrator(ILogger<ConfigurationMigrator> logger) : IHostedService
|
||||
{
|
||||
private readonly ILogger<ConfigurationMigrator> _logger = logger;
|
||||
|
||||
public void Migrate()
|
||||
{
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Migrate();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
137
MareSynchronos/MareConfiguration/ConfigurationSaveService.cs
Normal file
137
MareSynchronos/MareConfiguration/ConfigurationSaveService.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ConfigurationSaveService : IHostedService
|
||||
{
|
||||
private readonly HashSet<object> _configsToSave = [];
|
||||
private readonly ILogger<ConfigurationSaveService> _logger;
|
||||
private readonly SemaphoreSlim _configSaveSemaphore = new(1, 1);
|
||||
private readonly CancellationTokenSource _configSaveCheckCts = new();
|
||||
public const string BackupFolder = "config_backup";
|
||||
private readonly MethodInfo _saveMethod;
|
||||
|
||||
public ConfigurationSaveService(ILogger<ConfigurationSaveService> logger, IEnumerable<IConfigService<IMareConfiguration>> configs)
|
||||
{
|
||||
foreach (var config in configs)
|
||||
{
|
||||
config.ConfigSave += OnConfigurationSave;
|
||||
}
|
||||
_logger = logger;
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
_saveMethod = GetType().GetMethod(nameof(SaveConfig), BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
}
|
||||
|
||||
private void OnConfigurationSave(object? sender, EventArgs e)
|
||||
{
|
||||
_configSaveSemaphore.Wait();
|
||||
_configsToSave.Add(sender!);
|
||||
_configSaveSemaphore.Release();
|
||||
}
|
||||
|
||||
private async Task PeriodicSaveCheck(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await SaveConfigs().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during SaveConfigs");
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), ct).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveConfigs()
|
||||
{
|
||||
if (_configsToSave.Count == 0) return;
|
||||
|
||||
await _configSaveSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
var configList = _configsToSave.ToList();
|
||||
_configsToSave.Clear();
|
||||
_configSaveSemaphore.Release();
|
||||
|
||||
foreach (var config in configList)
|
||||
{
|
||||
var expectedType = config.GetType().BaseType!.GetGenericArguments()[0];
|
||||
var save = _saveMethod.MakeGenericMethod(expectedType);
|
||||
await ((Task)save.Invoke(this, [config])!).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveConfig<T>(IConfigService<T> config) where T : IMareConfiguration
|
||||
{
|
||||
_logger.LogTrace("Saving {configName}", config.ConfigurationName);
|
||||
var configDir = config.ConfigurationPath.Replace(config.ConfigurationName, string.Empty);
|
||||
|
||||
try
|
||||
{
|
||||
var configBackupFolder = Path.Join(configDir, BackupFolder);
|
||||
if (!Directory.Exists(configBackupFolder))
|
||||
Directory.CreateDirectory(configBackupFolder);
|
||||
|
||||
var configNameSplit = config.ConfigurationName.Split(".");
|
||||
var existingConfigs = Directory.EnumerateFiles(
|
||||
configBackupFolder,
|
||||
configNameSplit[0] + "*")
|
||||
.Select(c => new FileInfo(c))
|
||||
.OrderByDescending(c => c.LastWriteTime).ToList();
|
||||
if (existingConfigs.Skip(10).Any())
|
||||
{
|
||||
foreach (var oldBak in existingConfigs.Skip(10).ToList())
|
||||
{
|
||||
oldBak.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
string backupPath = Path.Combine(configBackupFolder, configNameSplit[0] + "." + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + configNameSplit[1]);
|
||||
_logger.LogTrace("Backing up current config to {backupPath}", backupPath);
|
||||
File.Copy(config.ConfigurationPath, backupPath, overwrite: true);
|
||||
FileInfo fi = new(backupPath);
|
||||
fi.LastWriteTimeUtc = DateTime.UtcNow;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignore if file cannot be backupped
|
||||
_logger.LogWarning(ex, "Could not create backup for {config}", config.ConfigurationPath);
|
||||
}
|
||||
|
||||
var temp = config.ConfigurationPath + ".tmp";
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(temp, JsonSerializer.Serialize(config.Current, typeof(T), new JsonSerializerOptions()
|
||||
{
|
||||
WriteIndented = true
|
||||
})).ConfigureAwait(false);
|
||||
File.Move(temp, config.ConfigurationPath, true);
|
||||
config.UpdateLastWriteTime();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during config save of {config}", config.ConfigurationName);
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = Task.Run(() => PeriodicSaveCheck(_configSaveCheckCts.Token));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _configSaveCheckCts.CancelAsync().ConfigureAwait(false);
|
||||
_configSaveCheckCts.Dispose();
|
||||
|
||||
await SaveConfigs().ConfigureAwait(false);
|
||||
}
|
||||
}
|
141
MareSynchronos/MareConfiguration/ConfigurationServiceBase.cs
Normal file
141
MareSynchronos/MareConfiguration/ConfigurationServiceBase.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public abstract class ConfigurationServiceBase<T> : IConfigService<T> where T : IMareConfiguration
|
||||
{
|
||||
private readonly CancellationTokenSource _periodicCheckCts = new();
|
||||
private DateTime _configLastWriteTime;
|
||||
private Lazy<T> _currentConfigInternal;
|
||||
private bool _disposed = false;
|
||||
|
||||
public event EventHandler? ConfigSave;
|
||||
|
||||
protected ConfigurationServiceBase(string configDirectory)
|
||||
{
|
||||
ConfigurationDirectory = configDirectory;
|
||||
|
||||
_ = Task.Run(CheckForConfigUpdatesInternal, _periodicCheckCts.Token);
|
||||
|
||||
_currentConfigInternal = LazyConfig();
|
||||
}
|
||||
|
||||
public string ConfigurationDirectory { get; init; }
|
||||
public T Current => _currentConfigInternal.Value;
|
||||
public abstract string ConfigurationName { get; }
|
||||
public string ConfigurationPath => Path.Combine(ConfigurationDirectory, ConfigurationName);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
ConfigSave?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void UpdateLastWriteTime()
|
||||
{
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing || _disposed) return;
|
||||
_disposed = true;
|
||||
_periodicCheckCts.Cancel();
|
||||
_periodicCheckCts.Dispose();
|
||||
}
|
||||
|
||||
protected T LoadConfig()
|
||||
{
|
||||
T? config;
|
||||
if (!File.Exists(ConfigurationPath))
|
||||
{
|
||||
config = AttemptToLoadBackup();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
config = JsonSerializer.Deserialize<T>(File.ReadAllText(ConfigurationPath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// config failed to load for some reason
|
||||
config = AttemptToLoadBackup();
|
||||
}
|
||||
}
|
||||
|
||||
if (config == null || Equals(config, default(T)))
|
||||
{
|
||||
config = Activator.CreateInstance<T>();
|
||||
Save();
|
||||
}
|
||||
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
return config;
|
||||
}
|
||||
|
||||
private T? AttemptToLoadBackup()
|
||||
{
|
||||
var configBackupFolder = Path.Join(ConfigurationDirectory, ConfigurationSaveService.BackupFolder);
|
||||
var configNameSplit = ConfigurationName.Split(".");
|
||||
if (!Directory.Exists(configBackupFolder))
|
||||
return default;
|
||||
|
||||
var existingBackups = Directory.EnumerateFiles(configBackupFolder, configNameSplit[0] + "*").OrderByDescending(f => new FileInfo(f).LastWriteTimeUtc);
|
||||
foreach (var file in existingBackups)
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = JsonSerializer.Deserialize<T>(File.ReadAllText(file));
|
||||
if (Equals(config, default(T)))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
File.Copy(file, ConfigurationPath, true);
|
||||
return config;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// couldn't load backup, might as well delete it
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
private async Task CheckForConfigUpdatesInternal()
|
||||
{
|
||||
while (!_periodicCheckCts.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), _periodicCheckCts.Token).ConfigureAwait(false);
|
||||
|
||||
var lastWriteTime = GetConfigLastWriteTime();
|
||||
if (lastWriteTime != _configLastWriteTime)
|
||||
{
|
||||
_currentConfigInternal = LazyConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime GetConfigLastWriteTime()
|
||||
{
|
||||
try { return new FileInfo(ConfigurationPath).LastWriteTimeUtc; }
|
||||
catch { return DateTime.MinValue; }
|
||||
}
|
||||
|
||||
|
||||
private Lazy<T> LazyConfig()
|
||||
{
|
||||
_configLastWriteTime = GetConfigLastWriteTime();
|
||||
return new Lazy<T>(LoadConfig);
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public class CharaDataConfig : IMareConfiguration
|
||||
{
|
||||
public bool OpenMareHubOnGposeStart { get; set; } = false;
|
||||
public string LastSavedCharaDataLocation { get; set; } = string.Empty;
|
||||
public Dictionary<string, CharaDataFavorite> FavoriteCodes { get; set; } = [];
|
||||
public bool DownloadMcdDataOnConnection { get; set; } = true;
|
||||
public int Version { get; set; } = 0;
|
||||
public bool NearbyOwnServerOnly { get; set; } = false;
|
||||
public bool NearbyIgnoreHousingLimitations { get; set; } = false;
|
||||
public bool NearbyDrawWisps { get; set; } = true;
|
||||
public int NearbyDistanceFilter { get; set; } = 100;
|
||||
public bool NearbyShowOwnData { get; set; } = false;
|
||||
public bool ShowHelpTexts { get; set; } = true;
|
||||
public bool NearbyShowAlways { get; set; } = false;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public interface IMareConfiguration
|
||||
{
|
||||
int Version { get; set; }
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
using MareSynchronos.UI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class MareConfig : IMareConfiguration
|
||||
{
|
||||
public bool AcceptedAgreement { get; set; } = false;
|
||||
public string CacheFolder { get; set; } = string.Empty;
|
||||
public bool DisableOptionalPluginWarnings { get; set; } = false;
|
||||
public bool EnableDtrEntry { get; set; } = true;
|
||||
public int DtrStyle { get; set; } = 0;
|
||||
public bool ShowUidInDtrTooltip { get; set; } = true;
|
||||
public bool PreferNoteInDtrTooltip { get; set; } = false;
|
||||
public bool UseColorsInDtr { get; set; } = true;
|
||||
public DtrEntry.Colors DtrColorsDefault { get; set; } = default;
|
||||
public DtrEntry.Colors DtrColorsNotConnected { get; set; } = new(Glow: 0x0428FFu);
|
||||
public DtrEntry.Colors DtrColorsPairsInRange { get; set; } = new(Glow: 0xFFBA47u);
|
||||
public bool UseNameColors { get; set; } = false;
|
||||
public DtrEntry.Colors NameColors { get; set; } = new(Foreground: 0x67EBF5u, Glow: 0x00303Cu);
|
||||
public DtrEntry.Colors BlockedNameColors { get; set; } = new(Foreground: 0x8AADC7, Glow: 0x000080u);
|
||||
public bool EnableRightClickMenus { get; set; } = true;
|
||||
public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both;
|
||||
public string ExportFolder { get; set; } = string.Empty;
|
||||
public bool FileScanPaused { get; set; } = false;
|
||||
public NotificationLocation InfoNotification { get; set; } = NotificationLocation.Toast;
|
||||
public bool InitialScanComplete { get; set; } = false;
|
||||
public LogLevel LogLevel { get; set; } = LogLevel.Information;
|
||||
public bool LogPerformance { get; set; } = false;
|
||||
public bool LogEvents { get; set; } = true;
|
||||
public bool HoldCombatApplication { get; set; } = false;
|
||||
public double MaxLocalCacheInGiB { get; set; } = 20;
|
||||
public bool OpenGposeImportOnGposeStart { get; set; } = false;
|
||||
public bool OpenPopupOnAdd { get; set; } = true;
|
||||
public int ParallelDownloads { get; set; } = 10;
|
||||
public int DownloadSpeedLimitInBytes { get; set; } = 0;
|
||||
public DownloadSpeeds DownloadSpeedType { get; set; } = DownloadSpeeds.MBps;
|
||||
[Obsolete] public bool PreferNotesOverNamesForVisible { get; set; } = false;
|
||||
public float ProfileDelay { get; set; } = 1.5f;
|
||||
public bool ProfilePopoutRight { get; set; } = false;
|
||||
public bool ProfilesAllowNsfw { get; set; } = false;
|
||||
public bool ProfilesShow { get; set; } = false;
|
||||
public bool ShowSyncshellUsersInVisible { get; set; } = true;
|
||||
[Obsolete] public bool ShowCharacterNameInsteadOfNotesForVisible { get; set; } = false;
|
||||
public bool ShowCharacterNames { get; set; } = true;
|
||||
public bool ShowOfflineUsersSeparately { get; set; } = true;
|
||||
public bool ShowSyncshellOfflineUsersSeparately { get; set; } = true;
|
||||
public bool GroupUpSyncshells { get; set; } = true;
|
||||
public bool SerialApplication { get; set; } = false;
|
||||
public bool ShowOnlineNotifications { get; set; } = false;
|
||||
public bool ShowOnlineNotificationsOnlyForIndividualPairs { get; set; } = true;
|
||||
public bool ShowOnlineNotificationsOnlyForNamedPairs { get; set; } = false;
|
||||
public bool ShowTransferBars { get; set; } = true;
|
||||
public bool ShowTransferWindow { get; set; } = false;
|
||||
public bool ShowUploading { get; set; } = true;
|
||||
public bool ShowUploadingBigText { get; set; } = true;
|
||||
public bool ShowVisibleUsersSeparately { get; set; } = true;
|
||||
public int TimeSpanBetweenScansInSeconds { get; set; } = 30;
|
||||
public int TransferBarsHeight { get; set; } = 12;
|
||||
public bool TransferBarsShowText { get; set; } = true;
|
||||
public int TransferBarsWidth { get; set; } = 250;
|
||||
public bool UseAlternativeFileUpload { get; set; } = false;
|
||||
public bool UseCompactor { get; set; } = false;
|
||||
public int Version { get; set; } = 1;
|
||||
public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both;
|
||||
|
||||
public bool DisableSyncshellChat { get; set; } = false;
|
||||
public int ChatColor { get; set; } = 0; // 0 means "use plugin default"
|
||||
public int ChatLogKind { get; set; } = 1; // XivChatType.Debug
|
||||
public bool ExtraChatAPI { get; set; } = false;
|
||||
public bool ExtraChatTags { get; set; } = false;
|
||||
|
||||
public bool MareAPI { get; set; } = true;
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public class PlayerPerformanceConfig : IMareConfiguration
|
||||
{
|
||||
public int Version { get; set; } = 1;
|
||||
public bool AutoPausePlayersExceedingThresholds { get; set; } = false;
|
||||
public bool NotifyAutoPauseDirectPairs { get; set; } = true;
|
||||
public bool NotifyAutoPauseGroupPairs { get; set; } = false;
|
||||
public int VRAMSizeAutoPauseThresholdMiB { get; set; } = 550;
|
||||
public int TrisAutoPauseThresholdThousands { get; set; } = 375;
|
||||
public bool IgnoreDirectPairs { get; set; } = true;
|
||||
public TextureShrinkMode TextureShrinkMode { get; set; } = TextureShrinkMode.Default;
|
||||
public bool TextureShrinkDeleteOriginal { get; set; } = false;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public class RemoteConfigCache : IMareConfiguration
|
||||
{
|
||||
public int Version { get; set; } = 0;
|
||||
public ulong Timestamp { get; set; } = 0;
|
||||
public string Origin { get; set; } = string.Empty;
|
||||
public DateTimeOffset? LastModified { get; set; } = null;
|
||||
public string ETag { get; set; } = string.Empty;
|
||||
public JsonObject Configuration { get; set; } = new();
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class ServerBlockConfig : IMareConfiguration
|
||||
{
|
||||
public Dictionary<string, ServerBlockStorage> ServerBlocks { get; set; } = new(StringComparer.Ordinal);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
using MareSynchronos.WebAPI;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class ServerConfig : IMareConfiguration
|
||||
{
|
||||
public int CurrentServer { get; set; } = 0;
|
||||
|
||||
public List<ServerStorage> ServerStorage { get; set; } = new()
|
||||
{
|
||||
{ new ServerStorage() { ServerName = ApiController.ElezenServer, ServerUri = ApiController.ElezenServiceUri } },
|
||||
};
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class ServerTagConfig : IMareConfiguration
|
||||
{
|
||||
public Dictionary<string, ServerTagStorage> ServerTagStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class SyncshellConfig : IMareConfiguration
|
||||
{
|
||||
public Dictionary<string, ServerShellStorage> ServerShellStorage { get; set; } = new(StringComparer.Ordinal);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public class TransientConfig : IMareConfiguration
|
||||
{
|
||||
public Dictionary<string, HashSet<string>> PlayerPersistentTransientCache { get; set; } = new(StringComparer.Ordinal);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
[Serializable]
|
||||
public class UidNotesConfig : IMareConfiguration
|
||||
{
|
||||
public Dictionary<string, ServerNotesStorage> ServerNotes { get; set; } = new(StringComparer.Ordinal);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
public class XivDataStorageConfig : IMareConfiguration
|
||||
{
|
||||
public ConcurrentDictionary<string, long> TriangleDictionary { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public ConcurrentDictionary<string, (uint Mip0Size, int MipCount, ushort Width, ushort Height)> TexDictionary { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public ConcurrentDictionary<string, Dictionary<string, List<ushort>>> BonesDictionary { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
12
MareSynchronos/MareConfiguration/IConfigService.cs
Normal file
12
MareSynchronos/MareConfiguration/IConfigService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public interface IConfigService<out T> : IDisposable where T : IMareConfiguration
|
||||
{
|
||||
T Current { get; }
|
||||
string ConfigurationName { get; }
|
||||
string ConfigurationPath { get; }
|
||||
public event EventHandler? ConfigSave;
|
||||
void UpdateLastWriteTime();
|
||||
}
|
14
MareSynchronos/MareConfiguration/MareConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/MareConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class MareConfigService : ConfigurationServiceBase<MareConfig>
|
||||
{
|
||||
public const string ConfigName = "config.json";
|
||||
|
||||
public MareConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public record Authentication
|
||||
{
|
||||
public string CharacterName { get; set; } = string.Empty;
|
||||
public uint WorldId { get; set; } = 0;
|
||||
public int SecretKeyIdx { get; set; } = -1;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class CharaDataFavorite
|
||||
{
|
||||
public DateTime LastDownloaded { get; set; } = DateTime.MaxValue;
|
||||
public string CustomDescription { get; set; } = string.Empty;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
public enum DownloadSpeeds
|
||||
{
|
||||
Bps,
|
||||
KBps,
|
||||
MBps
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
public enum NotificationLocation
|
||||
{
|
||||
Nowhere,
|
||||
Chat,
|
||||
Toast,
|
||||
Both
|
||||
}
|
||||
|
||||
public enum NotificationType
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models.Obsolete;
|
||||
|
||||
[Serializable]
|
||||
[Obsolete("Deprecated, use ServerStorage")]
|
||||
public class ServerStorageV0
|
||||
{
|
||||
public List<Authentication> Authentications { get; set; } = [];
|
||||
public bool FullPause { get; set; } = false;
|
||||
public Dictionary<string, string> GidServerComments { get; set; } = new(StringComparer.Ordinal);
|
||||
public HashSet<string> OpenPairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<int, SecretKey> SecretKeys { get; set; } = [];
|
||||
public HashSet<string> ServerAvailablePairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public string ServerName { get; set; } = string.Empty;
|
||||
public string ServerUri { get; set; } = string.Empty;
|
||||
public Dictionary<string, string> UidServerComments { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, List<string>> UidServerPairedUserTags { get; set; } = new(StringComparer.Ordinal);
|
||||
|
||||
public ServerStorage ToV1()
|
||||
{
|
||||
return new ServerStorage()
|
||||
{
|
||||
ServerUri = ServerUri,
|
||||
ServerName = ServerName,
|
||||
Authentications = [.. Authentications],
|
||||
FullPause = FullPause,
|
||||
SecretKeys = SecretKeys.ToDictionary(p => p.Key, p => p.Value)
|
||||
};
|
||||
}
|
||||
}
|
8
MareSynchronos/MareConfiguration/Models/SecretKey.cs
Normal file
8
MareSynchronos/MareConfiguration/Models/SecretKey.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class SecretKey
|
||||
{
|
||||
public string FriendlyName { get; set; } = string.Empty;
|
||||
public string Key { get; set; } = string.Empty;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerBlockStorage
|
||||
{
|
||||
public List<string> Whitelist { get; set; } = new();
|
||||
public List<string> Blacklist { get; set; } = new();
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerNotesStorage
|
||||
{
|
||||
public Dictionary<string, string> GidServerComments { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, string> UidServerComments { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, string> UidLastSeenNames { get; set; } = new(StringComparer.Ordinal);
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerShellStorage
|
||||
{
|
||||
public Dictionary<string, ShellConfig> GidShellConfig { get; set; } = new(StringComparer.Ordinal);
|
||||
}
|
11
MareSynchronos/MareConfiguration/Models/ServerStorage.cs
Normal file
11
MareSynchronos/MareConfiguration/Models/ServerStorage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerStorage
|
||||
{
|
||||
public List<Authentication> Authentications { get; set; } = [];
|
||||
public bool FullPause { get; set; } = false;
|
||||
public Dictionary<int, SecretKey> SecretKeys { get; set; } = [];
|
||||
public string ServerName { get; set; } = string.Empty;
|
||||
public string ServerUri { get; set; } = string.Empty;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ServerTagStorage
|
||||
{
|
||||
public HashSet<string> OpenPairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public HashSet<string> ServerAvailablePairTags { get; set; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, List<string>> UidServerPairedUserTags { get; set; } = new(StringComparer.Ordinal);
|
||||
}
|
10
MareSynchronos/MareConfiguration/Models/ShellConfig.cs
Normal file
10
MareSynchronos/MareConfiguration/Models/ShellConfig.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
[Serializable]
|
||||
public class ShellConfig
|
||||
{
|
||||
public bool Enabled { get; set; } = true;
|
||||
public int ShellNumber { get; set; }
|
||||
public int Color { get; set; } = 0; // 0 means "default to the global setting"
|
||||
public int LogKind { get; set; } = 0; // 0 means "default to the global setting"
|
||||
}
|
10
MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs
Normal file
10
MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MareSynchronos.MareConfiguration.Models;
|
||||
|
||||
public enum TextureShrinkMode
|
||||
{
|
||||
Never,
|
||||
Default,
|
||||
DefaultHiRes,
|
||||
Always,
|
||||
AlwaysHiRes
|
||||
}
|
14
MareSynchronos/MareConfiguration/NotesConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/NotesConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class NotesConfigService : ConfigurationServiceBase<UidNotesConfig>
|
||||
{
|
||||
public const string ConfigName = "notes.json";
|
||||
|
||||
public NotesConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class PlayerPerformanceConfigService : ConfigurationServiceBase<PlayerPerformanceConfig>
|
||||
{
|
||||
public const string ConfigName = "playerperformance.json";
|
||||
public PlayerPerformanceConfigService(string configDir) : base(configDir) { }
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
11
MareSynchronos/MareConfiguration/RemoteConfigCacheService.cs
Normal file
11
MareSynchronos/MareConfiguration/RemoteConfigCacheService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class RemoteConfigCacheService : ConfigurationServiceBase<RemoteConfigCache>
|
||||
{
|
||||
public const string ConfigName = "remotecache.json";
|
||||
|
||||
public RemoteConfigCacheService(string configDir) : base(configDir) { }
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
14
MareSynchronos/MareConfiguration/ServerBlockConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/ServerBlockConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ServerBlockConfigService : ConfigurationServiceBase<ServerBlockConfig>
|
||||
{
|
||||
public const string ConfigName = "blocks.json";
|
||||
|
||||
public ServerBlockConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
14
MareSynchronos/MareConfiguration/ServerConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/ServerConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ServerConfigService : ConfigurationServiceBase<ServerConfig>
|
||||
{
|
||||
public const string ConfigName = "server.json";
|
||||
|
||||
public ServerConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
14
MareSynchronos/MareConfiguration/ServerTagConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/ServerTagConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class ServerTagConfigService : ConfigurationServiceBase<ServerTagConfig>
|
||||
{
|
||||
public const string ConfigName = "servertags.json";
|
||||
|
||||
public ServerTagConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
14
MareSynchronos/MareConfiguration/SyncshellConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/SyncshellConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class SyncshellConfigService : ConfigurationServiceBase<SyncshellConfig>
|
||||
{
|
||||
public const string ConfigName = "syncshells.json";
|
||||
|
||||
public SyncshellConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
14
MareSynchronos/MareConfiguration/TransientConfigService.cs
Normal file
14
MareSynchronos/MareConfiguration/TransientConfigService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class TransientConfigService : ConfigurationServiceBase<TransientConfig>
|
||||
{
|
||||
public const string ConfigName = "transient.json";
|
||||
|
||||
public TransientConfigService(string configDir) : base(configDir)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
12
MareSynchronos/MareConfiguration/XivDataStorageService.cs
Normal file
12
MareSynchronos/MareConfiguration/XivDataStorageService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration;
|
||||
|
||||
public class XivDataStorageService : ConfigurationServiceBase<XivDataStorageConfig>
|
||||
{
|
||||
public const string ConfigName = "xivdatastorage.json";
|
||||
|
||||
public XivDataStorageService(string configDir) : base(configDir) { }
|
||||
|
||||
public override string ConfigurationName => ConfigName;
|
||||
}
|
Reference in New Issue
Block a user