migrate server config from v0 to v1, add more transfer bar settings
This commit is contained in:
@@ -47,6 +47,23 @@ public class ConfigurationMigrator : IHostedService
|
||||
_logger.LogWarning("Failed to migrate, skipping", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(ConfigurationPath(ServerConfigService.ConfigName)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var serverConfig = JsonConvert.DeserializeObject<ServerConfigV0>(File.ReadAllText(ConfigurationPath(ServerConfigService.ConfigName)))!;
|
||||
|
||||
if (serverConfig.Version == 0)
|
||||
{
|
||||
MigrateServerConfigV0toV1(serverConfig);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Failed to migrate ServerConfig", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
@@ -75,11 +92,12 @@ public class ConfigurationMigrator : IHostedService
|
||||
|
||||
MareConfig mareConfigV1 = mareConfigV0.ToV1();
|
||||
|
||||
int i = 0;
|
||||
var serverConfig = new ServerConfig()
|
||||
{
|
||||
CurrentServer = mareConfigV0.CurrentServer,
|
||||
ServerStorage = mareConfigV0.ServerStorage.ToDictionary(p => p.Key, p => p.Value.ToV1(), StringComparer.Ordinal)
|
||||
ServerStorage = mareConfigV0.ServerStorage.Select(p => p.Value.ToV1()).ToList()
|
||||
};
|
||||
serverConfig.CurrentServer = Array.IndexOf(serverConfig.ServerStorage.Select(s => s.ServerUri).ToArray(), mareConfigV0.CurrentServer);
|
||||
var transientConfig = new TransientConfig()
|
||||
{
|
||||
PlayerPersistentTransientCache = mareConfigV0.PlayerPersistentTransientCache
|
||||
@@ -108,6 +126,28 @@ public class ConfigurationMigrator : IHostedService
|
||||
SaveConfig(tagConfig, ConfigurationPath(ServerTagConfigService.ConfigName));
|
||||
SaveConfig(notesConfig, ConfigurationPath(NotesConfigService.ConfigName));
|
||||
}
|
||||
|
||||
private void MigrateServerConfigV0toV1(ServerConfigV0 serverConfigV0)
|
||||
{
|
||||
_logger.LogInformation("Migration Server Configuration from version 0 to 1");
|
||||
if (File.Exists(ConfigurationPath(ServerConfigService.ConfigName)))
|
||||
File.Copy(ConfigurationPath(ServerConfigService.ConfigName), ConfigurationPath(ServerConfigService.ConfigName) + ".migrated." + serverConfigV0.Version + ".bak", overwrite: true);
|
||||
|
||||
ServerConfig migrated = new();
|
||||
|
||||
var currentServer = serverConfigV0.CurrentServer;
|
||||
var currentServerIdx = Array.IndexOf(serverConfigV0.ServerStorage.Keys.ToArray(), currentServer);
|
||||
|
||||
migrated.CurrentServer = currentServerIdx;
|
||||
migrated.ServerStorage = new();
|
||||
|
||||
foreach (var server in serverConfigV0.ServerStorage)
|
||||
{
|
||||
migrated.ServerStorage.Add(server.Value);
|
||||
}
|
||||
|
||||
SaveConfig(migrated, ConfigurationPath(ServerConfigService.ConfigName));
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CS0618 // ignore Obsolete tag, the point of this migrator is to migrate obsolete configs to new ones
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IMareConfiguration
|
||||
{
|
||||
int Version { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@ public class MareConfig : IMareConfiguration
|
||||
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 int Version { get; set; } = 1;
|
||||
public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using MareSynchronos.MareConfiguration.Models;
|
||||
using MareSynchronos.WebAPI;
|
||||
|
||||
namespace MareSynchronos.MareConfiguration.Configurations.Obsolete;
|
||||
|
||||
[Serializable]
|
||||
[Obsolete]
|
||||
public class ServerConfigV0 : IMareConfiguration
|
||||
{
|
||||
public string CurrentServer { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
};
|
||||
|
||||
public int Version { get; set; } = 0;
|
||||
}
|
||||
@@ -6,11 +6,12 @@ namespace MareSynchronos.MareConfiguration.Configurations;
|
||||
[Serializable]
|
||||
public class ServerConfig : IMareConfiguration
|
||||
{
|
||||
public int Version { get; set; } = 0;
|
||||
public int CurrentServer { get; set; } = 0;
|
||||
|
||||
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
|
||||
public List<ServerStorage> ServerStorage { get; set; } = new()
|
||||
{
|
||||
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
{ new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
|
||||
};
|
||||
public string CurrentServer { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
||||
@@ -77,6 +77,7 @@ public class MarePlugin : MediatorSubscriberBase, IHostedService
|
||||
public MarePlugin(ILogger<MarePlugin> logger, MareConfigService mareConfigService,
|
||||
ServerConfigurationManager serverConfigurationManager,
|
||||
DalamudUtilService dalamudUtil,
|
||||
ConfigurationMigrator configurationMigrator,
|
||||
IServiceScopeFactory serviceScopeFactory, MareMediator mediator) : base(logger, mediator)
|
||||
{
|
||||
_mareConfigService = mareConfigService;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Authors></Authors>
|
||||
<Company></Company>
|
||||
<Version>0.8.6</Version>
|
||||
<Version>0.8.7</Version>
|
||||
<Description></Description>
|
||||
<Copyright></Copyright>
|
||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||
|
||||
@@ -158,7 +158,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
|
||||
_charaHandler?.Dispose();
|
||||
_charaHandler = null;
|
||||
|
||||
if (!_lifetime.ApplicationStopping.IsCancellationRequested && !_dalamudUtil.IsZoning)
|
||||
if (!_lifetime.ApplicationStopping.IsCancellationRequested && !_dalamudUtil.IsZoning && !_dalamudUtil.IsInCutscene)
|
||||
{
|
||||
Logger.LogTrace("[{applicationId}] Restoring state for {name} ({OnlineUser})", applicationId, name, OnlineUser);
|
||||
_ipcManager.PenumbraRemoveTemporaryCollection(Logger, applicationId, name);
|
||||
@@ -258,6 +258,14 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForNameAndThrow(GameObjectHandler handler, string name)
|
||||
{
|
||||
if (!string.Equals(handler.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException("Player name not equal to requested name, pointer invalid");
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<ObjectKind, HashSet<PlayerChanges>> CheckUpdatedData(CharacterData oldData, CharacterData newData, bool forced)
|
||||
{
|
||||
var charaDataToUpdate = new Dictionary<ObjectKind, HashSet<PlayerChanges>>();
|
||||
@@ -480,14 +488,6 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForNameAndThrow(GameObjectHandler handler, string name)
|
||||
{
|
||||
if (!string.Equals(handler.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException("Player name not equal to requested name, pointer invalid");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RevertCustomizationData(ObjectKind objectKind, string name, Guid applicationId)
|
||||
{
|
||||
nint address = _dalamudUtil.GetPlayerCharacterFromObjectTableByName(name)?.Address ?? IntPtr.Zero;
|
||||
|
||||
@@ -131,8 +131,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
s.GetRequiredService<PeriodicFileScanner>(), s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareConfigService>(), s.GetRequiredService<DalamudUtilService>(),
|
||||
pluginInterface, s.GetRequiredService<Dalamud.Localization>(), s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<MareMediator>()));
|
||||
|
||||
collection.AddHostedService(p => p.GetRequiredService<DalamudUtilService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<ConfigurationMigrator>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<DalamudUtilService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<PerformanceCollectorService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
||||
})
|
||||
|
||||
@@ -25,13 +25,9 @@ public class ServerConfigurationManager
|
||||
_dalamudUtil = dalamudUtil;
|
||||
}
|
||||
|
||||
public string CurrentApiUrl => string.IsNullOrEmpty(_configService.Current.CurrentServer) ? ApiController.MainServiceUri : _configService.Current.CurrentServer;
|
||||
public ServerStorage? CurrentServer => _configService.Current.ServerStorage.TryGetValue(CurrentApiUrl, out ServerStorage? value) ? value : null;
|
||||
|
||||
public int GetCurrentServerIndex()
|
||||
{
|
||||
return Array.IndexOf(_configService.Current.ServerStorage.Keys.ToArray(), CurrentApiUrl);
|
||||
}
|
||||
public string CurrentApiUrl => CurrentServer.ServerUri;
|
||||
public ServerStorage CurrentServer => _configService.Current.ServerStorage[CurrentServerIndex];
|
||||
public int CurrentServerIndex => _configService.Current.CurrentServer;
|
||||
|
||||
public string? GetSecretKey(int serverIdx = -1)
|
||||
{
|
||||
@@ -70,21 +66,21 @@ public class ServerConfigurationManager
|
||||
|
||||
public string[] GetServerApiUrls()
|
||||
{
|
||||
return _configService.Current.ServerStorage.Keys.ToArray();
|
||||
return _configService.Current.ServerStorage.Select(v => v.ServerUri).ToArray();
|
||||
}
|
||||
|
||||
public ServerStorage GetServerByIndex(int idx)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _configService.Current.ServerStorage.ElementAt(idx).Value;
|
||||
return _configService.Current.ServerStorage.ElementAt(idx);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_configService.Current.CurrentServer = ApiController.MainServiceUri;
|
||||
if (!_configService.Current.ServerStorage.ContainsKey(ApiController.MainServer))
|
||||
_configService.Current.CurrentServer = 0;
|
||||
if (!string.Equals(_configService.Current.ServerStorage[0].ServerUri, ApiController.MainServer, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_configService.Current.ServerStorage.Add(_configService.Current.CurrentServer, new ServerStorage() { ServerUri = ApiController.MainServiceUri, ServerName = ApiController.MainServer });
|
||||
_configService.Current.ServerStorage.Insert(0, new ServerStorage() { ServerUri = ApiController.MainServiceUri, ServerName = ApiController.MainServer });
|
||||
}
|
||||
Save();
|
||||
return CurrentServer!;
|
||||
@@ -93,7 +89,7 @@ public class ServerConfigurationManager
|
||||
|
||||
public string[] GetServerNames()
|
||||
{
|
||||
return _configService.Current.ServerStorage.Values.Select(v => v.ServerName).ToArray();
|
||||
return _configService.Current.ServerStorage.Select(v => v.ServerName).ToArray();
|
||||
}
|
||||
|
||||
public string? GetToken()
|
||||
@@ -133,14 +129,14 @@ public class ServerConfigurationManager
|
||||
|
||||
public void SelectServer(int idx)
|
||||
{
|
||||
_configService.Current.CurrentServer = GetServerByIndex(idx).ServerUri;
|
||||
_configService.Current.CurrentServer = idx;
|
||||
CurrentServer!.FullPause = false;
|
||||
Save();
|
||||
}
|
||||
|
||||
internal void AddCurrentCharacterToServer(int serverSelectionIndex = -1, bool addLastSecretKey = false)
|
||||
{
|
||||
if (serverSelectionIndex == -1) serverSelectionIndex = GetCurrentServerIndex();
|
||||
if (serverSelectionIndex == -1) serverSelectionIndex = CurrentServerIndex;
|
||||
var server = GetServerByIndex(serverSelectionIndex);
|
||||
server.Authentications.Add(new Authentication()
|
||||
{
|
||||
@@ -166,7 +162,7 @@ public class ServerConfigurationManager
|
||||
|
||||
internal void AddServer(ServerStorage serverStorage)
|
||||
{
|
||||
_configService.Current.ServerStorage[serverStorage.ServerUri] = serverStorage;
|
||||
_configService.Current.ServerStorage.Add(serverStorage);
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -207,7 +203,7 @@ public class ServerConfigurationManager
|
||||
|
||||
internal void DeleteServer(ServerStorage selectedServer)
|
||||
{
|
||||
_configService.Current.ServerStorage.Remove(selectedServer.ServerUri);
|
||||
_configService.Current.ServerStorage.Remove(selectedServer);
|
||||
Save();
|
||||
}
|
||||
|
||||
|
||||
@@ -148,13 +148,11 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
var totalBytes = transfer.Value.Sum(c => c.Value.TotalBytes);
|
||||
var transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
|
||||
|
||||
var downloadText =
|
||||
$"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
|
||||
var maxDlText = $"{UiSharedService.ByteToString(totalBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
|
||||
var textSize = ImGui.CalcTextSize(maxDlText);
|
||||
var textSize = _configService.Current.TransferBarsShowText ? ImGui.CalcTextSize(maxDlText) : new Vector2(10, 10);
|
||||
|
||||
int dlBarHeight = (int)textSize.Y + 8;
|
||||
int dlBarWidth = (int)textSize.X + 150;
|
||||
int dlBarHeight = _configService.Current.TransferBarsHeight > ((int)textSize.Y + 5) ? _configService.Current.TransferBarsHeight : (int)textSize.Y + 5;
|
||||
int dlBarWidth = _configService.Current.TransferBarsWidth > ((int)textSize.X + 10) ? _configService.Current.TransferBarsWidth : (int)textSize.X + 10;
|
||||
|
||||
var dlBarStart = new Vector2(screenPos.X - dlBarWidth / 2f, screenPos.Y - dlBarHeight / 2f);
|
||||
var dlBarEnd = new Vector2(screenPos.X + dlBarWidth / 2f, screenPos.Y + dlBarHeight / 2f);
|
||||
@@ -172,10 +170,15 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
||||
drawList.AddRectFilled(dlBarStart,
|
||||
dlBarEnd with { X = dlBarStart.X + (float)(dlProgressPercent * dlBarWidth) },
|
||||
UiSharedService.Color(50, 205, 50, transparency), 1);
|
||||
UiSharedService.DrawOutlinedFont(drawList, downloadText,
|
||||
screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
|
||||
UiSharedService.Color(255, 255, 255, transparency),
|
||||
UiSharedService.Color(0, 0, 0, transparency), 1);
|
||||
|
||||
if (_configService.Current.TransferBarsShowText)
|
||||
{
|
||||
var downloadText = $"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
|
||||
UiSharedService.DrawOutlinedFont(drawList, downloadText,
|
||||
screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
|
||||
UiSharedService.Color(255, 255, 255, transparency),
|
||||
UiSharedService.Color(0, 0, 0, transparency), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (_configService.Current.ShowUploading)
|
||||
|
||||
@@ -172,6 +172,27 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
|
||||
if (!showTransferBars) ImGui.BeginDisabled();
|
||||
ImGui.Indent();
|
||||
bool transferBarShowText = _configService.Current.TransferBarsShowText;
|
||||
if (ImGui.Checkbox("Show Download Text", ref transferBarShowText))
|
||||
{
|
||||
_configService.Current.TransferBarsShowText = transferBarShowText;
|
||||
_configService.Save();
|
||||
}
|
||||
UiSharedService.DrawHelpText("Shows download text (amount of MiB downloaded) in the transfer bars");
|
||||
int transferBarWidth = _configService.Current.TransferBarsWidth;
|
||||
if (ImGui.SliderInt("Transfer Bar Width", ref transferBarWidth, 10, 500))
|
||||
{
|
||||
_configService.Current.TransferBarsWidth = transferBarWidth;
|
||||
_configService.Save();
|
||||
}
|
||||
UiSharedService.DrawHelpText("Width of the displayed transfer bars (will never be less wide than the displayed text)");
|
||||
int transferBarHeight = _configService.Current.TransferBarsHeight;
|
||||
if (ImGui.SliderInt("Transfer Bar Height", ref transferBarHeight, 2, 50))
|
||||
{
|
||||
_configService.Current.TransferBarsHeight = transferBarHeight;
|
||||
_configService.Save();
|
||||
}
|
||||
UiSharedService.DrawHelpText("Height of the displayed transfer bars (will never be less tall than the displayed text)");
|
||||
bool showUploading = _configService.Current.ShowUploading;
|
||||
if (ImGui.Checkbox("Show 'Uploading' text below players that are currently uploading", ref showUploading))
|
||||
{
|
||||
@@ -793,12 +814,20 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
|
||||
if (ImGui.BeginTabItem("Service Settings"))
|
||||
{
|
||||
var serverUri = selectedServer.ServerUri;
|
||||
ImGui.InputText("Service URI", ref serverUri, 255, ImGuiInputTextFlags.ReadOnly);
|
||||
UiSharedService.DrawHelpText("You cannot edit the service URI. Add a new service if you need to edit the URI.");
|
||||
var serverName = selectedServer.ServerName;
|
||||
var serverUri = selectedServer.ServerUri;
|
||||
var isMain = string.Equals(serverName, ApiController.MainServer, StringComparison.OrdinalIgnoreCase);
|
||||
var flags = isMain ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None;
|
||||
|
||||
if (ImGui.InputText("Service URI", ref serverUri, 255, flags))
|
||||
{
|
||||
selectedServer.ServerUri = serverUri;
|
||||
}
|
||||
if (isMain)
|
||||
{
|
||||
UiSharedService.DrawHelpText("You cannot edit the URI of the main service.");
|
||||
}
|
||||
|
||||
if (ImGui.InputText("Service Name", ref serverName, 255, flags))
|
||||
{
|
||||
selectedServer.ServerName = serverName;
|
||||
@@ -808,6 +837,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
UiSharedService.DrawHelpText("You cannot edit the name of the main service.");
|
||||
}
|
||||
|
||||
if (!isMain && selectedServer != _serverConfigurationManager.CurrentServer)
|
||||
{
|
||||
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Service") && UiSharedService.CtrlPressed())
|
||||
|
||||
@@ -632,8 +632,10 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
string[] comboEntries = _serverConfigurationManager.GetServerNames();
|
||||
|
||||
if (_serverSelectionIndex == -1)
|
||||
{
|
||||
_serverSelectionIndex = Array.IndexOf(_serverConfigurationManager.GetServerApiUrls(), _serverConfigurationManager.CurrentApiUrl);
|
||||
if (_serverSelectionIndex == -1)
|
||||
}
|
||||
if (_serverSelectionIndex == -1 || _serverSelectionIndex >= comboEntries.Length)
|
||||
{
|
||||
_serverSelectionIndex = 0;
|
||||
}
|
||||
@@ -669,7 +671,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
ImGui.SameLine();
|
||||
var text = "Connect";
|
||||
if (_serverSelectionIndex == _serverConfigurationManager.GetCurrentServerIndex()) text = "Reconnect";
|
||||
if (_serverSelectionIndex == _serverConfigurationManager.CurrentServerIndex) text = "Reconnect";
|
||||
if (IconTextButton(FontAwesomeIcon.Link, text))
|
||||
{
|
||||
_serverConfigurationManager.SelectServer(_serverSelectionIndex);
|
||||
|
||||
Reference in New Issue
Block a user