From 5b5a1e2fd866c772dee5395191c4eb61ff9c47de Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 15 Aug 2022 13:15:26 +0200 Subject: [PATCH] Check path length on adding them to the cache and log error if a path is too long. --- .../ByteString/ByteStringFunctions.Construction.cs | 2 +- Penumbra.GameData/ByteString/Utf8RelPath.cs | 2 +- Penumbra/Collections/ModCollection.Cache.Access.cs | 2 +- Penumbra/Collections/ModCollection.Cache.cs | 4 +++- Penumbra/UI/Classes/ModEditWindow.Files.cs | 5 ++++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Penumbra.GameData/ByteString/ByteStringFunctions.Construction.cs b/Penumbra.GameData/ByteString/ByteStringFunctions.Construction.cs index ca4cadd0..18cc3a81 100644 --- a/Penumbra.GameData/ByteString/ByteStringFunctions.Construction.cs +++ b/Penumbra.GameData/ByteString/ByteStringFunctions.Construction.cs @@ -35,7 +35,7 @@ public static unsafe partial class ByteStringFunctions var path = ( byte* )Marshal.AllocHGlobal( length + 1 ); fixed( char* ptr = s ) { - Encoding.UTF8.GetBytes( ptr, length, path, length + 1 ); + Encoding.UTF8.GetBytes( ptr, s.Length, path, length + 1 ); } path[ length ] = 0; diff --git a/Penumbra.GameData/ByteString/Utf8RelPath.cs b/Penumbra.GameData/ByteString/Utf8RelPath.cs index da7e9332..cef27b6f 100644 --- a/Penumbra.GameData/ByteString/Utf8RelPath.cs +++ b/Penumbra.GameData/ByteString/Utf8RelPath.cs @@ -36,7 +36,7 @@ public readonly struct Utf8RelPath : IEquatable< Utf8RelPath >, IComparable< Utf return true; } - var substring = s!.Replace( '/', '\\' ).TrimStart('\\'); + var substring = s.Replace( '/', '\\' ).TrimStart('\\'); if( substring.Length > MaxRelPathLength ) { return false; diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index 332c7f81..fdc65e4b 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -87,7 +87,7 @@ public partial class ModCollection return true; } - PluginLog.Error( $"Could not add the redirection {path} to {fullPath}, the redirected path is too long." ); + PluginLog.Error( $"The redirected path is too long to add the redirection\n\t{path}\n\t--> {fullPath}" ); return false; } diff --git a/Penumbra/Collections/ModCollection.Cache.cs b/Penumbra/Collections/ModCollection.Cache.cs index c525edd1..dbb07b95 100644 --- a/Penumbra/Collections/ModCollection.Cache.cs +++ b/Penumbra/Collections/ModCollection.Cache.cs @@ -326,8 +326,10 @@ public partial class ModCollection // Inside the same mod, conflicts are not recorded. private void AddFile( Utf8GamePath path, FullPath file, IMod mod ) { - if (!CheckFullPath( path, file )) + if( !CheckFullPath( path, file ) ) + { return; + } if( ResolvedFiles.TryAdd( path, new ModPath( mod, file ) ) ) { diff --git a/Penumbra/UI/Classes/ModEditWindow.Files.cs b/Penumbra/UI/Classes/ModEditWindow.Files.cs index fd46e0ae..8390850b 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Files.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Files.cs @@ -319,7 +319,10 @@ public partial class ModEditWindow if( ImGuiUtil.DrawDisabledButton( "Apply Changes", Vector2.Zero, tt, !changes ) ) { var failedFiles = _editor!.ApplyFiles(); - PluginLog.Information( $"Failed to apply {failedFiles} file redirections to {_editor.CurrentOption.Name}." ); + if( failedFiles > 0 ) + { + PluginLog.Information( $"Failed to apply {failedFiles} file redirections to {_editor.CurrentOption.FullName}." ); + } }