fix some minor issues

This commit is contained in:
Stanley Dimant
2024-08-19 20:02:12 +02:00
parent 71afa6374e
commit 6b04452774
3 changed files with 44 additions and 7 deletions

View File

@@ -48,7 +48,21 @@ public sealed class Plugin : IDalamudPlugin
.Select(f => new FileInfo(f)) .Select(f => new FileInfo(f))
.OrderByDescending(f => f.LastWriteTimeUtc).Skip(9)) .OrderByDescending(f => f.LastWriteTimeUtc).Skip(9))
{ {
file.Delete(); int attempts = 0;
bool deleted = false;
while (!deleted && attempts < 5)
{
try
{
file.Delete();
deleted = true;
}
catch
{
attempts++;
Thread.Sleep(500);
}
}
} }
_host = new HostBuilder() _host = new HostBuilder()

View File

@@ -173,6 +173,10 @@ public class ServerConfigurationManager
{ {
if (serverSelectionIndex == -1) serverSelectionIndex = CurrentServerIndex; if (serverSelectionIndex == -1) serverSelectionIndex = CurrentServerIndex;
var server = GetServerByIndex(serverSelectionIndex); var server = GetServerByIndex(serverSelectionIndex);
if (server.Authentications.Any(c => string.Equals(c.CharacterName, _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), StringComparison.Ordinal)
&& c.WorldId == _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult()))
return;
server.Authentications.Add(new Authentication() server.Authentications.Add(new Authentication()
{ {
CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(),

View File

@@ -11,10 +11,11 @@ using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration; using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Numerics; using System.Numerics;
using System.Text.RegularExpressions;
namespace MareSynchronos.UI; namespace MareSynchronos.UI;
public class IntroUi : WindowMediatorSubscriberBase public partial class IntroUi : WindowMediatorSubscriberBase
{ {
private readonly MareConfigService _configService; private readonly MareConfigService _configService;
private readonly CacheMonitor _cacheMonitor; private readonly CacheMonitor _cacheMonitor;
@@ -226,18 +227,33 @@ public class IntroUi : WindowMediatorSubscriberBase
{ {
UiSharedService.ColorTextWrapped("Your secret key must be exactly 64 characters long. Don't enter your Lodestone auth here.", ImGuiColors.DalamudRed); UiSharedService.ColorTextWrapped("Your secret key must be exactly 64 characters long. Don't enter your Lodestone auth here.", ImGuiColors.DalamudRed);
} }
else if (_secretKey.Length == 64 && !HexRegex().IsMatch(_secretKey))
{
UiSharedService.ColorTextWrapped("Your secret key can only contain ABCDEF and the numbers 0-9.", ImGuiColors.DalamudRed);
}
else if (_secretKey.Length == 64) else if (_secretKey.Length == 64)
{ {
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button(buttonText)) if (ImGui.Button(buttonText))
{ {
if (_serverConfigurationManager.CurrentServer == null) _serverConfigurationManager.SelectServer(0); if (_serverConfigurationManager.CurrentServer == null) _serverConfigurationManager.SelectServer(0);
_serverConfigurationManager.CurrentServer!.SecretKeys.Add(_serverConfigurationManager.CurrentServer.SecretKeys.Select(k => k.Key).LastOrDefault() + 1, new SecretKey() if (!_serverConfigurationManager.CurrentServer!.SecretKeys.Any())
{ {
FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})", _serverConfigurationManager.CurrentServer!.SecretKeys.Add(_serverConfigurationManager.CurrentServer.SecretKeys.Select(k => k.Key).LastOrDefault() + 1, new SecretKey()
Key = _secretKey, {
}); FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})",
_serverConfigurationManager.AddCurrentCharacterToServer(addLastSecretKey: true); Key = _secretKey,
});
_serverConfigurationManager.AddCurrentCharacterToServer(addLastSecretKey: true);
}
else
{
_serverConfigurationManager.CurrentServer!.SecretKeys[0] = new SecretKey()
{
FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})",
Key = _secretKey,
};
}
_secretKey = string.Empty; _secretKey = string.Empty;
_ = Task.Run(() => _uiShared.ApiController.CreateConnections()); _ = Task.Run(() => _uiShared.ApiController.CreateConnections());
} }
@@ -259,4 +275,7 @@ public class IntroUi : WindowMediatorSubscriberBase
_tosParagraphs = [Strings.ToS.Paragraph1, Strings.ToS.Paragraph2, Strings.ToS.Paragraph3, Strings.ToS.Paragraph4, Strings.ToS.Paragraph5, Strings.ToS.Paragraph6]; _tosParagraphs = [Strings.ToS.Paragraph1, Strings.ToS.Paragraph2, Strings.ToS.Paragraph3, Strings.ToS.Paragraph4, Strings.ToS.Paragraph5, Strings.ToS.Paragraph6];
} }
[GeneratedRegex("^([A-F0-9]{2}\\s+)+")]
private static partial Regex HexRegex();
} }