Code reuse and better naming
This commit is contained in:
parent
af38750e29
commit
7e00162ef2
@ -15,7 +15,11 @@ namespace FileManager
|
|||||||
/// <summary>Generate a valid path for this file or directory</summary>
|
/// <summary>Generate a valid path for this file or directory</summary>
|
||||||
public LongPath GetFilePath(ReplacementCharacters replacements, bool returnFirstExisting = false)
|
public LongPath GetFilePath(ReplacementCharacters replacements, bool returnFirstExisting = false)
|
||||||
{
|
{
|
||||||
string fileName = Template.EndsWith(Path.DirectorySeparatorChar) ? Template[..^1] : Template;
|
string fileName =
|
||||||
|
Template.EndsWith(Path.DirectorySeparatorChar) || Template.EndsWith(Path.AltDirectorySeparatorChar) ?
|
||||||
|
FileUtility.RemoveLastCharacter(Template) :
|
||||||
|
Template;
|
||||||
|
|
||||||
List<string> pathParts = new();
|
List<string> pathParts = new();
|
||||||
|
|
||||||
var paramReplacements = ParameterReplacements.ToDictionary(r => $"<{formatKey(r.Key)}>", r => formatValue(r.Value, replacements));
|
var paramReplacements = ParameterReplacements.ToDictionary(r => $"<{formatKey(r.Key)}>", r => formatValue(r.Value, replacements));
|
||||||
|
|||||||
@ -84,7 +84,7 @@ namespace FileManager
|
|||||||
|
|
||||||
var pathNoPrefix = path.PathWithoutPrefix;
|
var pathNoPrefix = path.PathWithoutPrefix;
|
||||||
|
|
||||||
pathNoPrefix = replacements.ReplaceInvalidChars(pathNoPrefix);
|
pathNoPrefix = replacements.ReplaceInvalidPathChars(pathNoPrefix);
|
||||||
pathNoPrefix = removeDoubleSlashes(pathNoPrefix);
|
pathNoPrefix = removeDoubleSlashes(pathNoPrefix);
|
||||||
|
|
||||||
return pathNoPrefix;
|
return pathNoPrefix;
|
||||||
|
|||||||
@ -185,7 +185,7 @@ namespace FileManager
|
|||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ReplaceInvalidChars(string pathStr)
|
public string ReplaceInvalidPathChars(string pathStr)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(pathStr)) return string.Empty;
|
if (string.IsNullOrEmpty(pathStr)) return string.Empty;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user