diff --git a/Penumbra/Import/TexToolsImporter.ModPack.cs b/Penumbra/Import/TexToolsImporter.ModPack.cs index 65b757c2..a6339f5c 100644 --- a/Penumbra/Import/TexToolsImporter.ModPack.cs +++ b/Penumbra/Import/TexToolsImporter.ModPack.cs @@ -112,6 +112,17 @@ public partial class TexToolsImporter .Count( o => o.Name.Length > 0 && o.ModsJsons.Length > 0 ) + ( group.OptionList.Any( o => o.Name.Length > 0 && o.ModsJsons.Length == 0 ) ? 1 : 0 ) ) ); + private static string GetGroupName( string groupName, ISet< string > names ) + { + var baseName = groupName; + var i = 2; + while( !names.Add( groupName ) ) + { + groupName = $"{baseName} ({i++})"; + } + return groupName; + } + // Extended V2 mod packs contain multiple options that need to be handled separately. private DirectoryInfo ImportExtendedV2ModPack( ZipFile extractedModPack, string modRaw ) { @@ -144,14 +155,15 @@ public partial class TexToolsImporter // Iterate through all pages var options = new List< ISubMod >(); var groupPriority = 0; + var groupNames = new HashSet< string >(); foreach( var page in modList.ModPackPages ) { foreach( var group in page.ModGroups.Where( group => group.GroupName.Length > 0 && group.OptionList.Length > 0 ) ) { - _currentGroupName = group.GroupName; + _currentGroupName = GetGroupName( group.GroupName, groupNames ); options.Clear(); var description = new StringBuilder(); - var groupFolder = Mod.NewSubFolderName( _currentModDirectory, group.GroupName ) + var groupFolder = Mod.NewSubFolderName( _currentModDirectory, _currentGroupName ) ?? new DirectoryInfo( Path.Combine( _currentModDirectory.FullName, $"Group {groupPriority + 1}" ) ); var optionIdx = 1; @@ -186,7 +198,7 @@ public partial class TexToolsImporter } } - Mod.CreateOptionGroup( _currentModDirectory, group, groupPriority, groupPriority, description.ToString(), options ); + Mod.CreateOptionGroup( _currentModDirectory, group.SelectionType, _currentGroupName, groupPriority, groupPriority, description.ToString(), options ); ++groupPriority; } } diff --git a/Penumbra/Mods/Mod.Creation.cs b/Penumbra/Mods/Mod.Creation.cs index c6387fc6..3c845490 100644 --- a/Penumbra/Mods/Mod.Creation.cs +++ b/Penumbra/Mods/Mod.Creation.cs @@ -58,16 +58,16 @@ public partial class Mod } // Create a file for an option group from given data. - internal static void CreateOptionGroup( DirectoryInfo baseFolder, ModGroup groupData, + internal static void CreateOptionGroup( DirectoryInfo baseFolder, SelectType type, string name, int priority, int index, string desc, IEnumerable< ISubMod > subMods ) { - switch( groupData.SelectionType ) + switch( type ) { case SelectType.Multi: { var group = new MultiModGroup() { - Name = groupData.GroupName, + Name = name, Description = desc, Priority = priority, }; @@ -79,7 +79,7 @@ public partial class Mod { var group = new SingleModGroup() { - Name = groupData.GroupName, + Name = name, Description = desc, Priority = priority, }; diff --git a/Penumbra/Mods/Mod.Files.cs b/Penumbra/Mods/Mod.Files.cs index c66ab9a4..c4a1257a 100644 --- a/Penumbra/Mods/Mod.Files.cs +++ b/Penumbra/Mods/Mod.Files.cs @@ -105,13 +105,24 @@ public partial class Mod private void LoadAllGroups() { _groups.Clear(); + var changes = false; foreach( var file in GroupFiles ) { var group = LoadModGroup( file, ModPath ); - if( group != null ) + if( group != null && _groups.All( g => g.Name != group.Name ) ) { + changes = changes || group.FileName( ModPath, _groups.Count ) != file.FullName; _groups.Add( group ); } + else + { + changes = true; + } + } + + if( changes ) + { + SaveAllGroups(); } }