Add signal that a game path can not be added to file redirections, maybe fix some UsedGamePath bugs.

This commit is contained in:
Ottermandias 2022-09-22 14:25:19 +02:00
parent 1c97b52179
commit 819264045b
3 changed files with 27 additions and 11 deletions

View file

@ -37,14 +37,7 @@ public partial class Mod
} }
Penumbra.ModManager.OptionSetFiles( _mod, _subMod.GroupIdx, _subMod.OptionIdx, dict ); Penumbra.ModManager.OptionSetFiles( _mod, _subMod.GroupIdx, _subMod.OptionIdx, dict );
if( num > 0 ) UpdateFiles();
{
RevertFiles();
}
else
{
FileChanges = false;
}
return num; return num;
} }

View file

@ -94,7 +94,7 @@ public partial class Mod
{ {
void HandleSubMod( ISubMod mod, int groupIdx, int optionIdx ) void HandleSubMod( ISubMod mod, int groupIdx, int optionIdx )
{ {
var newDict = mod.Files.Where( kvp => CheckAgainstMissing( kvp.Value, kvp.Key ) ) var newDict = mod.Files.Where( kvp => CheckAgainstMissing( kvp.Value, kvp.Key, mod == _subMod ) )
.ToDictionary( kvp => kvp.Key, kvp => kvp.Value ); .ToDictionary( kvp => kvp.Key, kvp => kvp.Value );
if( newDict.Count != mod.Files.Count ) if( newDict.Count != mod.Files.Count )
{ {
@ -106,13 +106,18 @@ public partial class Mod
_missingFiles.Clear(); _missingFiles.Clear();
} }
private bool CheckAgainstMissing( FullPath file, Utf8GamePath key ) private bool CheckAgainstMissing( FullPath file, Utf8GamePath key, bool removeUsed )
{ {
if( !_missingFiles.Contains( file ) ) if( !_missingFiles.Contains( file ) )
{ {
return true; return true;
} }
if( removeUsed )
{
_usedPaths.Remove( key );
}
Penumbra.Log.Debug( $"[RemoveMissingPaths] Removing {key} -> {file} from {_mod.Name}." ); Penumbra.Log.Debug( $"[RemoveMissingPaths] Removing {key} -> {file} from {_mod.Name}." );
return false; return false;
} }

View file

@ -8,6 +8,7 @@ using OtterGui;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui.Raii; using OtterGui.Raii;
using Penumbra.GameData.ByteString; using Penumbra.GameData.ByteString;
using Penumbra.GameData.Util;
using Penumbra.Mods; using Penumbra.Mods;
namespace Penumbra.UI.Classes; namespace Penumbra.UI.Classes;
@ -230,7 +231,7 @@ public partial class ModEditWindow
using var id = ImRaii.PushId( j ); using var id = ImRaii.PushId( j );
ImGui.TableNextColumn(); ImGui.TableNextColumn();
var tmp = _fileIdx == i && _pathIdx == j ? _gamePathEdit : gamePath.ToString(); var tmp = _fileIdx == i && _pathIdx == j ? _gamePathEdit : gamePath.ToString();
var pos = ImGui.GetCursorPosX() - ImGui.GetFrameHeight();
ImGui.SetNextItemWidth( -1 ); ImGui.SetNextItemWidth( -1 );
if( ImGui.InputText( string.Empty, ref tmp, Utf8GamePath.MaxGamePathLength ) ) if( ImGui.InputText( string.Empty, ref tmp, Utf8GamePath.MaxGamePathLength ) )
{ {
@ -251,11 +252,20 @@ public partial class ModEditWindow
_fileIdx = -1; _fileIdx = -1;
_pathIdx = -1; _pathIdx = -1;
} }
else if( _fileIdx == i && _pathIdx == j && ( !Utf8GamePath.FromString( _gamePathEdit, out var path, false )
|| !path.IsEmpty && !path.Equals( gamePath ) && !_editor!.CanAddGamePath( path )) )
{
ImGui.SameLine();
ImGui.SetCursorPosX( pos );
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGuiUtil.TextColored( 0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString() );
}
} }
private void PrintNewGamePath( int i, Mod.Editor.FileRegistry registry, ISubMod subMod ) private void PrintNewGamePath( int i, Mod.Editor.FileRegistry registry, ISubMod subMod )
{ {
var tmp = _fileIdx == i && _pathIdx == -1 ? _gamePathEdit : string.Empty; var tmp = _fileIdx == i && _pathIdx == -1 ? _gamePathEdit : string.Empty;
var pos = ImGui.GetCursorPosX() - ImGui.GetFrameHeight();
ImGui.SetNextItemWidth( -1 ); ImGui.SetNextItemWidth( -1 );
if( ImGui.InputTextWithHint( "##new", "Add New Path...", ref tmp, Utf8GamePath.MaxGamePathLength ) ) if( ImGui.InputTextWithHint( "##new", "Add New Path...", ref tmp, Utf8GamePath.MaxGamePathLength ) )
{ {
@ -274,6 +284,14 @@ public partial class ModEditWindow
_fileIdx = -1; _fileIdx = -1;
_pathIdx = -1; _pathIdx = -1;
} }
else if( _fileIdx == i && _pathIdx == -1 && (!Utf8GamePath.FromString( _gamePathEdit, out var path, false )
|| !path.IsEmpty && !_editor!.CanAddGamePath( path )) )
{
ImGui.SameLine();
ImGui.SetCursorPosX( pos );
using var font = ImRaii.PushFont( UiBuilder.IconFont );
ImGuiUtil.TextColored( 0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString() );
}
} }
private void DrawButtonHeader() private void DrawButtonHeader()