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

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

View file

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms.VisualStyles;
using Penumbra.Models;
using Swan.Logging;
namespace Penumbra.Mods
{
@ -11,6 +9,7 @@ namespace Penumbra.Mods
{
private readonly Plugin _plugin;
public readonly Dictionary< string, FileInfo > ResolvedFiles = new();
public readonly Dictionary< string, string > SwappedFiles = new();
public ModCollection Mods { get; set; }
@ -107,6 +106,7 @@ namespace Penumbra.Mods
public void CalculateEffectiveFileList()
{
ResolvedFiles.Clear();
SwappedFiles.Clear();
var registeredFiles = new Dictionary< string, string >();
@ -149,6 +149,20 @@ namespace Penumbra.Mods
}
}
}
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,13 +194,19 @@ namespace Penumbra.Mods
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();
return GetCandidateForGameFile( gameResourcePath )?.FullName;
return GetCandidateForGameFile( gameResourcePath )?.FullName ?? GetSwappedFilePath( gameResourcePath );
}
public void Dispose()
{
// _fileSystemWatcher?.Dispose();

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
@ -129,7 +129,7 @@ namespace Penumbra
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 :(
if( replacementPath == null || replacementPath.Length >= 260 )

View file

@ -683,6 +683,24 @@ namespace Penumbra.UI
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( ImGui.BeginTabItem( "File Conflicts" ) )