Merge branch 'develop' into MetaData

This commit is contained in:
Ottermandias 2021-03-28 19:25:52 +02:00
commit f74dc7f326
4 changed files with 45 additions and 6 deletions

View file

@ -190,7 +190,7 @@ namespace Penumbra.Mods
=> SwappedFiles.TryGetValue( gameResourcePath, out var swappedPath ) ? swappedPath : null; => SwappedFiles.TryGetValue( gameResourcePath, out var swappedPath ) ? swappedPath : null;
public string? ResolveSwappedOrReplacementFilePath( GamePath gameResourcePath ) public string? ResolveSwappedOrReplacementFilePath( GamePath gameResourcePath )
=> GetCandidateForGameFile( gameResourcePath )?.FullName ?? GetSwappedFilePath( gameResourcePath ) ?? null; => GetCandidateForGameFile( gameResourcePath )?.FullName.Replace( '\\', '/' ) ?? GetSwappedFilePath( gameResourcePath ) ?? null;
public void Dispose() public void Dispose()

View file

@ -373,6 +373,30 @@ namespace Penumbra.UI
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
private int HandleDefaultString( GamePath[] gamePaths, out int removeFolders )
{
removeFolders = 0;
var defaultIndex = gamePaths.IndexOf( p => ( ( string )p ).StartsWith( TextDefaultGamePath ) );
if( defaultIndex < 0 )
{
return defaultIndex;
}
string path = gamePaths[ defaultIndex ];
if( path.Length == TextDefaultGamePath.Length )
{
return defaultIndex;
}
if( path[ TextDefaultGamePath.Length ] != '-'
|| !int.TryParse( path.Substring( TextDefaultGamePath.Length + 1 ), out removeFolders ) )
{
return -1;
}
return defaultIndex;
}
private void HandleSelectedFilesButton( bool remove ) private void HandleSelectedFilesButton( bool remove )
{ {
if( _selectedOption == null ) if( _selectedOption == null )
@ -388,7 +412,7 @@ namespace Penumbra.UI
return; return;
} }
var defaultIndex = gamePaths.IndexOf( p => p == TextDefaultGamePath ); var defaultIndex = HandleDefaultString( gamePaths, out var removeFolders );
var changed = false; var changed = false;
for( var i = 0; i < Mod.Mod.ModFiles.Count; ++i ) for( var i = 0; i < Mod.Mod.ModFiles.Count; ++i )
{ {
@ -400,7 +424,7 @@ namespace Penumbra.UI
var relName = _fullFilenameList[ i ].relName; var relName = _fullFilenameList[ i ].relName;
if( defaultIndex >= 0 ) if( defaultIndex >= 0 )
{ {
gamePaths[ defaultIndex ] = new GamePath( relName ); gamePaths[ defaultIndex ] = new GamePath( relName, removeFolders );
} }
if( remove && option.OptionFiles.TryGetValue( relName, out var setPaths ) ) if( remove && option.OptionFiles.TryGetValue( relName, out var setPaths ) )

View file

@ -30,7 +30,8 @@ namespace Penumbra.UI
private static readonly string TooltipGamePathsEdit = private static readonly string TooltipGamePathsEdit =
$"Enter all game paths to add or remove, separated by '{GamePathsSeparator}'.\n" + $"Enter all game paths to add or remove, separated by '{GamePathsSeparator}'.\n" +
$"Use '{TextDefaultGamePath}' to add the original file path."; $"Use '{TextDefaultGamePath}' to add the original file path." +
$"Use '{TextDefaultGamePath}-#' to skip the first # relative directories.";
private const float MultiEditBoxWidth = 300f; private const float MultiEditBoxWidth = 300f;

View file

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
namespace Penumbra.Util namespace Penumbra.Util
{ {
@ -89,8 +90,16 @@ namespace Penumbra.Util
public GamePath( FileInfo file, DirectoryInfo baseDir ) public GamePath( FileInfo file, DirectoryInfo baseDir )
=> _path = CheckPre( file, baseDir ) ? Lower( Trim( ReplaceSlash( Substring( file, baseDir ) ) ) ) : ""; => _path = CheckPre( file, baseDir ) ? Lower( Trim( ReplaceSlash( Substring( file, baseDir ) ) ) ) : "";
public GamePath( RelPath relPath ) public GamePath( RelPath relPath, int skipFolders )
=> _path = relPath ? Lower( ReplaceSlash( relPath ) ) : ""; {
string p = relPath;
if( skipFolders > 0 )
{
p = string.Join( "/", p.Split( '\\' ).Skip( skipFolders ) );
}
_path = Lower( ReplaceSlash( p ) );
}
private static bool CheckPre( FileInfo file, DirectoryInfo baseDir ) private static bool CheckPre( FileInfo file, DirectoryInfo baseDir )
=> file.FullName.StartsWith( baseDir.FullName ) && file.FullName.Length < MaxGamePathLength; => file.FullName.StartsWith( baseDir.FullName ) && file.FullName.Length < MaxGamePathLength;
@ -122,6 +131,11 @@ namespace Penumbra.Util
public static explicit operator GamePath( string gamePath ) public static explicit operator GamePath( string gamePath )
=> new( gamePath ); => new( gamePath );
public string Filename()
{
var idx = _path.LastIndexOf( "/", StringComparison.Ordinal );
return idx == -1 ? _path : idx == _path.Length - 1 ? "" : _path.Substring( idx + 1 );
}
public int CompareTo( object rhs ) public int CompareTo( object rhs )
{ {