Skip to content

Commit da39cb9

Browse files
committed
code_style: remove DirectoryInfoExtension.GetRelativePath since it is not safe while being used out of DirectoryInfoExtension.WalkFiles
Signed-off-by: leo <longshuang@msn.cn>
1 parent 30d5700 commit da39cb9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/App.Extensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,5 @@ public static void WalkFiles(this DirectoryInfo dir, Action<string> onFile, int
5757
// Ignore exceptions.
5858
}
5959
}
60-
61-
public static string GetRelativePath(this DirectoryInfo dir, string fullpath)
62-
{
63-
return fullpath.Substring(dir.FullName.Length).TrimStart(Path.DirectorySeparatorChar);
64-
}
6560
}
6661
}

src/Models/ExternalTool.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,14 @@ public void FindJetBrainsFromToolbox(Func<string> platformFinder)
230230
return null;
231231

232232
var options = new List<ExternalTool.LaunchOption>();
233+
var prefixLen = root.FullName.Length;
233234
root.WalkFiles(f =>
234235
{
235236
if (f.EndsWith(".code-workspace", StringComparison.OrdinalIgnoreCase))
236-
options.Add(new(root.GetRelativePath(f), f.Quoted()));
237+
{
238+
var display = f.Substring(prefixLen).TrimStart(Path.DirectorySeparatorChar);
239+
options.Add(new(display, f.Quoted()));
240+
}
237241
}, 2);
238242
return options;
239243
}

src/Native/Windows.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,15 @@ private void FixWindowFrameOnWin10(Window w)
234234
return null;
235235

236236
var options = new List<Models.ExternalTool.LaunchOption>();
237+
var prefixLen = root.FullName.Length;
237238
root.WalkFiles(f =>
238239
{
239240
if (f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
240241
f.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase))
241-
options.Add(new(root.GetRelativePath(f), f.Quoted()));
242+
{
243+
var display = f.Substring(prefixLen).TrimStart(Path.DirectorySeparatorChar);
244+
options.Add(new(display, f.Quoted()));
245+
}
242246
});
243247
return options;
244248
}

0 commit comments

Comments
 (0)