code_style: remove DirectoryInfoExtension.GetRelativePath since it is not safe while being used out of DirectoryInfoExtension.WalkFiles

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-03-05 16:02:24 +08:00
parent 30d5700f88
commit da39cb949f
3 changed files with 10 additions and 7 deletions

View File

@@ -57,10 +57,5 @@ namespace SourceGit
// Ignore exceptions.
}
}
public static string GetRelativePath(this DirectoryInfo dir, string fullpath)
{
return fullpath.Substring(dir.FullName.Length).TrimStart(Path.DirectorySeparatorChar);
}
}
}

View File

@@ -230,10 +230,14 @@ namespace SourceGit.Models
return null;
var options = new List<ExternalTool.LaunchOption>();
var prefixLen = root.FullName.Length;
root.WalkFiles(f =>
{
if (f.EndsWith(".code-workspace", StringComparison.OrdinalIgnoreCase))
options.Add(new(root.GetRelativePath(f), f.Quoted()));
{
var display = f.Substring(prefixLen).TrimStart(Path.DirectorySeparatorChar);
options.Add(new(display, f.Quoted()));
}
}, 2);
return options;
}

View File

@@ -234,11 +234,15 @@ namespace SourceGit.Native
return null;
var options = new List<Models.ExternalTool.LaunchOption>();
var prefixLen = root.FullName.Length;
root.WalkFiles(f =>
{
if (f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
f.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase))
options.Add(new(root.GetRelativePath(f), f.Quoted()));
{
var display = f.Substring(prefixLen).TrimStart(Path.DirectorySeparatorChar);
options.Add(new(display, f.Quoted()));
}
});
return options;
}