From c2bc8252f1affa818c5b64eebcb1e06e42cb6b1e Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 21 Jul 2022 10:07:20 +0200 Subject: [PATCH] Allow only valid characters when creating collections. --- Penumbra/Collections/CollectionManager.cs | 4 ++-- Penumbra/Collections/ModCollection.cs | 8 +++++++- Penumbra/UI/ConfigWindow.CollectionsTab.cs | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Penumbra/Collections/CollectionManager.cs b/Penumbra/Collections/CollectionManager.cs index 05e221d3..9bc2138c 100644 --- a/Penumbra/Collections/CollectionManager.cs +++ b/Penumbra/Collections/CollectionManager.cs @@ -79,7 +79,7 @@ public partial class ModCollection // and no existing collection results in the same filename as name. public bool CanAddCollection( string name, out string fixedName ) { - if( name.Length == 0 ) + if( !IsValidName( name ) ) { fixedName = string.Empty; return false; @@ -156,7 +156,7 @@ public partial class ModCollection var collection = _collections[ idx ]; // Clear own inheritances. - foreach(var inheritance in collection.Inheritance) + foreach( var inheritance in collection.Inheritance ) { collection.ClearSubscriptions( inheritance ); } diff --git a/Penumbra/Collections/ModCollection.cs b/Penumbra/Collections/ModCollection.cs index c31a6fb6..5394efcc 100644 --- a/Penumbra/Collections/ModCollection.cs +++ b/Penumbra/Collections/ModCollection.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OtterGui.Filesystem; using Penumbra.Mods; namespace Penumbra.Collections; @@ -25,7 +26,7 @@ public partial class ModCollection // Get the first two letters of a collection name and its Index (or None if it is the empty collection). public string AnonymizedName - => this == Empty ? Empty.Name : Name.Length > 2 ? $"{Name[..2]}... ({Index})" : $"{Name} ({Index})"; + => this == Empty ? Empty.Name : Name.Length > 2 ? $"{Name[ ..2 ]}... ({Index})" : $"{Name} ({Index})"; public int Version { get; private set; } public int Index { get; private set; } = -1; @@ -94,6 +95,11 @@ public partial class ModCollection public ModCollection Duplicate( string name ) => new(name, this); + // Check if a name is valid to use for a collection. + // Does not check for uniqueness. + public static bool IsValidName( string name ) + => name.Length > 0 && name.All( c => !c.IsInvalidAscii() && c is not '|' && !c.IsInvalidInPath() ); + // Remove all settings for not currently-installed mods. public void CleanUnavailableSettings() { diff --git a/Penumbra/UI/ConfigWindow.CollectionsTab.cs b/Penumbra/UI/ConfigWindow.CollectionsTab.cs index dbf9b02b..09ad7796 100644 --- a/Penumbra/UI/ConfigWindow.CollectionsTab.cs +++ b/Penumbra/UI/ConfigWindow.CollectionsTab.cs @@ -85,7 +85,7 @@ public partial class ConfigWindow + "You can use multiple collections to quickly switch between sets of mods." ); // Creation buttons. - var tt = _canAddCollection ? string.Empty : "Please enter a unique name before creating a collection."; + var tt = _canAddCollection ? string.Empty : "Please enter a unique name only consisting of symbols valid in a path but no '|' before creating a collection."; if( ImGuiUtil.DrawDisabledButton( "Create New Empty Collection", Vector2.Zero, tt, !_canAddCollection ) ) { CreateNewCollection( false );