Added validation on saving/creation of folders on name check.

This commit is contained in:
CakeAndBanana
2025-09-10 05:18:19 +02:00
parent 2361b30e9f
commit e07863ddd4
5 changed files with 38 additions and 18 deletions

View File

@@ -3,7 +3,6 @@ using LightlessSync.API.Routes;
using LightlessSync.LightlessConfiguration;
using LightlessSync.LightlessConfiguration.Models;
using LightlessSync.Services.Mediator;
using LightlessSync.UI.Components;
using LightlessSync.WebAPI;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.Extensions.Logging;
@@ -26,6 +25,7 @@ public class ServerConfigurationManager
private readonly NotesConfigService _notesConfig;
private readonly PairTagConfigService _pairTagConfig;
private readonly SyncshellTagConfigService _syncshellTagConfig;
private readonly int _maxCharactersFolder = 20;
public ServerConfigurationManager(ILogger<ServerConfigurationManager> logger, ServerConfigService configService,
PairTagConfigService pairTagConfig, SyncshellTagConfigService syncshellTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
@@ -299,16 +299,30 @@ public class ServerConfigurationManager
internal void AddPairTag(string tag)
{
CurrentPairTagStorage().ServerAvailablePairTags.Add(tag);
_pairTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
if (tag.Length > _maxCharactersFolder)
{
CurrentPairTagStorage().ServerAvailablePairTags.Add(tag);
_pairTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
}
}
internal void AddSyncshellTag(string tag)
{
CurrentSyncshellTagStorage().ServerAvailableSyncshellTags.Add(tag);
_syncshellTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
if (tag.Length > _maxCharactersFolder)
{
CurrentSyncshellTagStorage().ServerAvailableSyncshellTags.Add(tag);
_syncshellTagConfig.Save();
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", tag);
}
}
internal void AddTagForUid(string uid, string tagName)
@@ -454,7 +468,6 @@ public class ServerConfigurationManager
RemoveTagForUid(uid, tag, save: false);
}
}
}
internal void RemoveTagForUid(string uid, string tagName, bool save = true)
@@ -491,14 +504,21 @@ public class ServerConfigurationManager
internal void RenameTag(Dictionary<string, List<string>> tags, HashSet<string> storage, string oldName, string newName)
{
storage.Remove(oldName);
storage.Add(newName);
foreach (var existingTags in tags.Select(k => k.Value))
if (newName.Length > _maxCharactersFolder)
{
if (existingTags.Remove(oldName))
existingTags.Add(newName);
storage.Remove(oldName);
storage.Add(newName);
foreach (var existingTags in tags.Select(k => k.Value))
{
if (existingTags.Remove(oldName))
existingTags.Add(newName);
}
_lightlessMediator.Publish(new RefreshUiMessage());
}
else
{
_logger.LogInformation("Couldn't save/add {tag}. Name too long to be saved", newName);
}
_lightlessMediator.Publish(new RefreshUiMessage());
}
internal void SaveNotes() => _notesConfig.Save();