Allow extracting identically named options again.

This commit is contained in:
Ottermandias 2022-05-11 21:02:18 +02:00
parent f0af9f1274
commit e85d57b094
3 changed files with 31 additions and 8 deletions

View file

@ -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;
}
}

View file

@ -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,
};

View file

@ -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();
}
}