From e07863ddd4a23e148d6dd4c85d91364b912b83e2 Mon Sep 17 00:00:00 2001 From: CakeAndBanana Date: Wed, 10 Sep 2025 05:18:19 +0200 Subject: [PATCH] Added validation on saving/creation of folders on name check. --- .../ServerConfigurationManager.cs | 48 +++++++++++++------ .../UI/Components/RenamePairTagUi.cs | 2 +- .../UI/Components/RenameSyncshellTagUi.cs | 2 +- .../UI/Components/SelectTagForPairUi.cs | 2 +- .../UI/Components/SelectTagForSyncshellUi.cs | 2 +- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs b/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs index 6b2ac42..67c16e5 100644 --- a/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/LightlessSync/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -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 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> tags, HashSet 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(); diff --git a/LightlessSync/UI/Components/RenamePairTagUi.cs b/LightlessSync/UI/Components/RenamePairTagUi.cs index aa77783..bac0e15 100644 --- a/LightlessSync/UI/Components/RenamePairTagUi.cs +++ b/LightlessSync/UI/Components/RenamePairTagUi.cs @@ -48,7 +48,7 @@ public class RenamePairTagUi { ImGui.TextUnformatted($"Renaming {_tag}"); - ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 255, ImGuiInputTextFlags.None); + ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None); using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName))) { if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group")) diff --git a/LightlessSync/UI/Components/RenameSyncshellTagUi.cs b/LightlessSync/UI/Components/RenameSyncshellTagUi.cs index b92870c..310fed8 100644 --- a/LightlessSync/UI/Components/RenameSyncshellTagUi.cs +++ b/LightlessSync/UI/Components/RenameSyncshellTagUi.cs @@ -48,7 +48,7 @@ public class RenameSyncshellTagUi { ImGui.TextUnformatted($"Renaming {_tag}"); - ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 255, ImGuiInputTextFlags.None); + ImGui.InputTextWithHint("##desiredname", "Enter new group name", ref _desiredName, 20, ImGuiInputTextFlags.None); using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredName))) { if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Rename Group")) diff --git a/LightlessSync/UI/Components/SelectTagForPairUi.cs b/LightlessSync/UI/Components/SelectTagForPairUi.cs index 4c840fb..fbc0751 100644 --- a/LightlessSync/UI/Components/SelectTagForPairUi.cs +++ b/LightlessSync/UI/Components/SelectTagForPairUi.cs @@ -80,7 +80,7 @@ public class SelectTagForPairUi HandleAddTag(); } ImGui.SameLine(); - ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40); + ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20); if (ImGui.IsKeyDown(ImGuiKey.Enter)) { HandleAddTag(); diff --git a/LightlessSync/UI/Components/SelectTagForSyncshellUi.cs b/LightlessSync/UI/Components/SelectTagForSyncshellUi.cs index f9947e9..b0c83db 100644 --- a/LightlessSync/UI/Components/SelectTagForSyncshellUi.cs +++ b/LightlessSync/UI/Components/SelectTagForSyncshellUi.cs @@ -78,7 +78,7 @@ public class SelectTagForSyncshellUi HandleAddTag(); } ImGui.SameLine(); - ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40); + ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 20); if (ImGui.IsKeyDown(ImGuiKey.Enter)) { HandleAddTag();