Reverted Removed SwapFiles.

This commit is contained in:
Ottermandias 2021-01-15 10:12:42 +01:00
parent 01215b5697
commit d24fed6eb9
4 changed files with 51 additions and 11 deletions

View file

@ -13,6 +13,8 @@ namespace Penumbra.Models
public string Website { get; set; } public string Website { get; set; }
public List<string> ChangedItems { get; set; } = new(); public List<string> ChangedItems { get; set; } = new();
public Dictionary< string, string > FileSwaps { get; } = new();
public GroupInformation Groups { get; set; } = new(); public GroupInformation Groups { get; set; } = new();
} }

View file

@ -1,16 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms.VisualStyles; using Penumbra.Models;
using Penumbra.Models;
using Swan.Logging;
namespace Penumbra.Mods namespace Penumbra.Mods
{ {
public class ModManager : IDisposable public class ModManager : IDisposable
{ {
private readonly Plugin _plugin; private readonly Plugin _plugin;
public readonly Dictionary< string, FileInfo > ResolvedFiles = new(); public readonly Dictionary< string, FileInfo > ResolvedFiles = new();
public readonly Dictionary< string, string > SwappedFiles = new();
public ModCollection Mods { get; set; } public ModCollection Mods { get; set; }
@ -106,7 +105,8 @@ namespace Penumbra.Mods
public void CalculateEffectiveFileList() public void CalculateEffectiveFileList()
{ {
ResolvedFiles.Clear(); ResolvedFiles.Clear();
SwappedFiles.Clear();
var registeredFiles = new Dictionary< string, string >(); var registeredFiles = new Dictionary< string, string >();
@ -148,6 +148,20 @@ namespace Penumbra.Mods
mod.AddConflict( modName, gamePath ); mod.AddConflict( modName, gamePath );
} }
} }
}
foreach( var swap in mod.Meta.FileSwaps )
{
// just assume people put not fucked paths in here lol
if( !SwappedFiles.ContainsKey( swap.Value ) )
{
SwappedFiles[ swap.Key.ToLowerInvariant() ] = swap.Value;
registeredFiles[ swap.Key ] = mod.Meta.Name;
}
else if( registeredFiles.TryGetValue( swap.Key, out var modName ) )
{
mod.AddConflict( modName, swap.Key );
}
} }
} }
} }
@ -180,12 +194,18 @@ namespace Penumbra.Mods
return candidate; return candidate;
} }
public string ResolveReplacementFilePath( string gameResourcePath ) public string GetSwappedFilePath( string gameResourcePath )
{
return SwappedFiles.TryGetValue( gameResourcePath, out var swappedPath ) ? swappedPath : null;
}
public string ResolveSwappedOrReplacementFilePath( string gameResourcePath )
{ {
gameResourcePath = gameResourcePath.ToLowerInvariant(); gameResourcePath = gameResourcePath.ToLowerInvariant();
return GetCandidateForGameFile( gameResourcePath )?.FullName; return GetCandidateForGameFile( gameResourcePath )?.FullName ?? GetSwappedFilePath( gameResourcePath );
} }
public void Dispose() public void Dispose()
{ {

View file

@ -1,4 +1,4 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
@ -129,7 +129,7 @@ namespace Penumbra
PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath ); PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath );
} }
var replacementPath = Plugin.ModManager.ResolveReplacementFilePath( gameFsPath ); var replacementPath = Plugin.ModManager.ResolveSwappedOrReplacementFilePath( gameFsPath );
// path must be < 260 because statically defined array length :( // path must be < 260 because statically defined array length :(
if( replacementPath == null || replacementPath.Length >= 260 ) if( replacementPath == null || replacementPath.Length >= 260 )

View file

@ -683,6 +683,24 @@ namespace Penumbra.UI
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
if( _selectedMod.Mod.Meta.FileSwaps.Any() )
{
if( ImGui.BeginTabItem( "File Swaps" ) )
{
ImGui.SetNextItemWidth( -1 );
if( ImGui.ListBoxHeader( "##", AutoFillSize ) )
{
foreach( var file in _selectedMod.Mod.Meta.FileSwaps )
{
// todo: fucking gross alloc every frame * items
ImGui.Selectable( $"{file.Key} -> {file.Value}" );
}
}
ImGui.ListBoxFooter();
ImGui.EndTabItem();
}
}
if( _selectedMod.Mod.FileConflicts.Any() ) if( _selectedMod.Mod.FileConflicts.Any() )
{ {
if( ImGui.BeginTabItem( "File Conflicts" ) ) if( ImGui.BeginTabItem( "File Conflicts" ) )