mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 20:24:17 +01:00
Fix for importing mods containing dots, stop overwriting existing mods on import, fix identically named option groups on different pages crashing.
This commit is contained in:
parent
80d5da3c05
commit
b22ca96bbd
1 changed files with 61 additions and 37 deletions
|
|
@ -72,8 +72,10 @@ namespace Penumbra.Importer
|
||||||
var entry = file[ i ];
|
var entry = file[ i ];
|
||||||
|
|
||||||
if( entry.Name.Contains( fileName ) )
|
if( entry.Name.Contains( fileName ) )
|
||||||
|
{
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -147,18 +149,13 @@ namespace Penumbra.Importer
|
||||||
{
|
{
|
||||||
Author = "Unknown",
|
Author = "Unknown",
|
||||||
Name = modPackFile.Name,
|
Name = modPackFile.Name,
|
||||||
Description = "Mod imported from TexTools mod pack"
|
Description = "Mod imported from TexTools mod pack",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Open the mod data file from the modpack as a SqPackStream
|
// Open the mod data file from the modpack as a SqPackStream
|
||||||
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
||||||
|
|
||||||
var newModFolder = new DirectoryInfo(
|
var newModFolder = CreateModFolder( Path.GetFileNameWithoutExtension( modPackFile.Name ) );
|
||||||
Path.Combine( _outDirectory.FullName,
|
|
||||||
Path.GetFileNameWithoutExtension( modPackFile.Name )
|
|
||||||
)
|
|
||||||
);
|
|
||||||
newModFolder.Create();
|
|
||||||
|
|
||||||
File.WriteAllText(
|
File.WriteAllText(
|
||||||
Path.Combine( newModFolder.FullName, "meta.json" ),
|
Path.Combine( newModFolder.FullName, "meta.json" ),
|
||||||
|
|
@ -190,6 +187,26 @@ namespace Penumbra.Importer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DirectoryInfo CreateModFolder( string modListName )
|
||||||
|
{
|
||||||
|
var correctedPath = Path.Combine( _outDirectory.FullName,
|
||||||
|
Path.GetFileName( modListName ).RemoveInvalidPathSymbols() );
|
||||||
|
var newModFolder = new DirectoryInfo( correctedPath );
|
||||||
|
var i = 2;
|
||||||
|
while( newModFolder.Exists && i < 12 )
|
||||||
|
{
|
||||||
|
newModFolder = new DirectoryInfo( correctedPath + $" ({i++})" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( newModFolder.Exists )
|
||||||
|
{
|
||||||
|
throw new IOException( "Could not create mod folder: too many folders of the same name exist." );
|
||||||
|
}
|
||||||
|
|
||||||
|
newModFolder.Create();
|
||||||
|
return newModFolder;
|
||||||
|
}
|
||||||
|
|
||||||
private void ImportSimpleV2ModPack( ZipFile extractedModPack, SimpleModPack modList )
|
private void ImportSimpleV2ModPack( ZipFile extractedModPack, SimpleModPack modList )
|
||||||
{
|
{
|
||||||
PluginLog.Log( " -> Importing Simple V2 ModPack" );
|
PluginLog.Log( " -> Importing Simple V2 ModPack" );
|
||||||
|
|
@ -201,15 +218,13 @@ namespace Penumbra.Importer
|
||||||
Name = modList.Name ?? "New Mod",
|
Name = modList.Name ?? "New Mod",
|
||||||
Description = string.IsNullOrEmpty( modList.Description )
|
Description = string.IsNullOrEmpty( modList.Description )
|
||||||
? "Mod imported from TexTools mod pack"
|
? "Mod imported from TexTools mod pack"
|
||||||
: modList.Description!
|
: modList.Description!,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Open the mod data file from the modpack as a SqPackStream
|
// Open the mod data file from the modpack as a SqPackStream
|
||||||
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
||||||
|
|
||||||
var newModFolder = new DirectoryInfo( Path.Combine( _outDirectory.FullName,
|
var newModFolder = CreateModFolder( modList.Name ?? "New Mod" );
|
||||||
Path.GetFileNameWithoutExtension( modList.Name ) ) );
|
|
||||||
newModFolder.Create();
|
|
||||||
|
|
||||||
File.WriteAllText( Path.Combine( newModFolder.FullName, "meta.json" ),
|
File.WriteAllText( Path.Combine( newModFolder.FullName, "meta.json" ),
|
||||||
JsonConvert.SerializeObject( modMeta ) );
|
JsonConvert.SerializeObject( modMeta ) );
|
||||||
|
|
@ -231,18 +246,13 @@ namespace Penumbra.Importer
|
||||||
Description = string.IsNullOrEmpty( modList.Description )
|
Description = string.IsNullOrEmpty( modList.Description )
|
||||||
? "Mod imported from TexTools mod pack"
|
? "Mod imported from TexTools mod pack"
|
||||||
: modList.Description ?? "",
|
: modList.Description ?? "",
|
||||||
Version = modList.Version ?? ""
|
Version = modList.Version ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Open the mod data file from the modpack as a SqPackStream
|
// Open the mod data file from the modpack as a SqPackStream
|
||||||
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
using var modData = GetMagicSqPackDeleterStream( extractedModPack, "TTMPD.mpd" );
|
||||||
|
|
||||||
var newModFolder = new DirectoryInfo(
|
var newModFolder = CreateModFolder( modList.Name ?? "New Mod" );
|
||||||
Path.Combine( _outDirectory.FullName,
|
|
||||||
Path.GetFileNameWithoutExtension( modList.Name ).ReplaceInvalidPathSymbols()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
newModFolder.Create();
|
|
||||||
|
|
||||||
if( modList.SimpleModsList != null )
|
if( modList.SimpleModsList != null )
|
||||||
{
|
{
|
||||||
|
|
@ -255,10 +265,22 @@ namespace Penumbra.Importer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through all pages
|
// Iterate through all pages
|
||||||
foreach( var group in modList.ModPackPages.SelectMany( page => page.ModGroups )
|
foreach( var page in modList.ModPackPages )
|
||||||
.Where( group => group.GroupName != null && group.OptionList != null ) )
|
{
|
||||||
|
if( page.ModGroups == null )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach( var group in page.ModGroups.Where( group => group.GroupName != null && group.OptionList != null ) )
|
||||||
{
|
{
|
||||||
var groupFolder = new DirectoryInfo( Path.Combine( newModFolder.FullName, group.GroupName!.ReplaceInvalidPathSymbols() ) );
|
var groupFolder = new DirectoryInfo( Path.Combine( newModFolder.FullName, group.GroupName!.ReplaceInvalidPathSymbols() ) );
|
||||||
|
if( groupFolder.Exists )
|
||||||
|
{
|
||||||
|
groupFolder = new DirectoryInfo( groupFolder.FullName + $" ({page.PageIndex})" );
|
||||||
|
group.GroupName += $" ({page.PageIndex})";
|
||||||
|
}
|
||||||
|
|
||||||
foreach( var option in group.OptionList!.Where( option => option.Name != null && option.ModsJsons != null ) )
|
foreach( var option in group.OptionList!.Where( option => option.Name != null && option.ModsJsons != null ) )
|
||||||
{
|
{
|
||||||
var optionFolder = new DirectoryInfo( Path.Combine( groupFolder.FullName, option.Name!.ReplaceInvalidPathSymbols() ) );
|
var optionFolder = new DirectoryInfo( Path.Combine( groupFolder.FullName, option.Name!.ReplaceInvalidPathSymbols() ) );
|
||||||
|
|
@ -267,6 +289,7 @@ namespace Penumbra.Importer
|
||||||
|
|
||||||
AddMeta( newModFolder, groupFolder, group, modMeta );
|
AddMeta( newModFolder, groupFolder, group, modMeta );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File.WriteAllText(
|
File.WriteAllText(
|
||||||
Path.Combine( newModFolder.FullName, "meta.json" ),
|
Path.Combine( newModFolder.FullName, "meta.json" ),
|
||||||
|
|
@ -280,7 +303,7 @@ namespace Penumbra.Importer
|
||||||
{
|
{
|
||||||
SelectionType = group.SelectionType,
|
SelectionType = group.SelectionType,
|
||||||
GroupName = group.GroupName!,
|
GroupName = group.GroupName!,
|
||||||
Options = new List< Option >()
|
Options = new List< Option >(),
|
||||||
};
|
};
|
||||||
foreach( var opt in group.OptionList! )
|
foreach( var opt in group.OptionList! )
|
||||||
{
|
{
|
||||||
|
|
@ -288,7 +311,7 @@ namespace Penumbra.Importer
|
||||||
{
|
{
|
||||||
OptionName = opt.Name!,
|
OptionName = opt.Name!,
|
||||||
OptionDesc = string.IsNullOrEmpty( opt.Description ) ? "" : opt.Description!,
|
OptionDesc = string.IsNullOrEmpty( opt.Description ) ? "" : opt.Description!,
|
||||||
OptionFiles = new Dictionary< RelPath, HashSet< GamePath > >()
|
OptionFiles = new Dictionary< RelPath, HashSet< GamePath > >(),
|
||||||
};
|
};
|
||||||
var optDir = new DirectoryInfo( Path.Combine( groupFolder.FullName, opt.Name!.ReplaceInvalidPathSymbols() ) );
|
var optDir = new DirectoryInfo( Path.Combine( groupFolder.FullName, opt.Name!.ReplaceInvalidPathSymbols() ) );
|
||||||
if( optDir.Exists )
|
if( optDir.Exists )
|
||||||
|
|
@ -302,7 +325,7 @@ namespace Penumbra.Importer
|
||||||
inf.Options.Add( option );
|
inf.Options.Add( option );
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.Groups.Add( group.GroupName!, inf );
|
meta.Groups.Add( inf.GroupName, inf );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImportMetaModPack( FileInfo file )
|
private void ImportMetaModPack( FileInfo file )
|
||||||
|
|
@ -335,7 +358,7 @@ namespace Penumbra.Importer
|
||||||
{
|
{
|
||||||
var data = dataStream.ReadFile< PenumbraSqPackStream.PenumbraFileResource >( mod.ModOffset );
|
var data = dataStream.ReadFile< PenumbraSqPackStream.PenumbraFileResource >( mod.ModOffset );
|
||||||
|
|
||||||
var extractedFile = new FileInfo( Path.Combine( outDirectory.FullName, mod.FullPath ) );
|
var extractedFile = new FileInfo( Path.Combine( outDirectory.FullName, mod.FullPath! ) );
|
||||||
extractedFile.Directory?.Create();
|
extractedFile.Directory?.Create();
|
||||||
|
|
||||||
if( extractedFile.FullName.EndsWith( "mdl" ) )
|
if( extractedFile.FullName.EndsWith( "mdl" ) )
|
||||||
|
|
@ -366,7 +389,8 @@ namespace Penumbra.Importer
|
||||||
mdl[ modelHeaderStart + modelHeaderLodOffset ] = 1;
|
mdl[ modelHeaderStart + modelHeaderLodOffset ] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream GetStreamFromZipEntry( ZipFile file, ZipEntry entry ) => file.GetInputStream( entry );
|
private static Stream GetStreamFromZipEntry( ZipFile file, ZipEntry entry )
|
||||||
|
=> file.GetInputStream( entry );
|
||||||
|
|
||||||
private static string GetStringFromZipEntry( ZipFile file, ZipEntry entry, Encoding encoding )
|
private static string GetStringFromZipEntry( ZipFile file, ZipEntry entry, Encoding encoding )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue