C#: Address review comments

This commit is contained in:
Tom Hvitved
2019-01-02 10:42:08 +01:00
parent 9f375de716
commit 412248c77f
2 changed files with 13 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Standalone
{
get
{
var dotnetPath = FileUtils.FindExecutableOnPath("dotnet");
var dotnetPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
var dotnetDirs = dotnetPath != null
? new[] { dotnetPath }
: new[] { "/usr/share/dotnet", @"C:\Program Files\dotnet" };
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Standalone
{
get
{
var monoPath = FileUtils.FindExecutableOnPath("mono");
var monoPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
var monoDirs = monoPath != null
? new[] { monoPath }
: new[] { "/usr/lib/mono", @"C:\Program Files\Mono\lib\mono" };

View File

@@ -62,11 +62,17 @@ namespace Semmle.Util
/// </summary>
public static string FindExecutableOnPath(string exe)
{
var isWindows = Win32.IsWindows();
var paths = Environment.GetEnvironmentVariable("PATH").Split(isWindows ? ';' : ':');
var exes = isWindows
? Environment.GetEnvironmentVariable("PATHEXT").Split(';').Select(ext => exe + ext)
: new[] { exe };
var paths = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
string[] exes;
if (Win32.IsWindows())
{
var extensions = Environment.GetEnvironmentVariable("PATHEXT").Split(';').ToArray();
exes = extensions.Any(exe.EndsWith) ? new[] { exe } : extensions.Select(ext => exe + ext).ToArray();
}
else
{
exes = new[] { exe };
}
var candidates = paths.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
return candidates.FirstOrDefault();
}