Skip to content

Commit

Permalink
add - doc - Added PATH tools
Browse files Browse the repository at this point in the history
---

We've added PATH tools for cross-platform programming.

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Nov 30, 2024
1 parent 1ebee9e commit da171cf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions SpecProbe.Software/Platform/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using SpecProbe.Software.Kernel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -277,6 +278,36 @@ public static bool IsOnWayland() =>
public static bool IsOnGui() =>
!IsOnUnix() || IsOnX11() || IsOnWayland();

/// <summary>
/// Gets a list of PATH directories
/// </summary>
/// <returns>A list of directories specified by the PATH environment variable</returns>
public static string[] GetPaths()
{
char separator = IsOnWindows() ? ';' : ':';
return (Environment.GetEnvironmentVariable("PATH") ?? "").Split([separator], StringSplitOptions.RemoveEmptyEntries);
}

/// <summary>
/// Gets the possible paths that this file is found on
/// </summary>
/// <param name="file">Target file name with extension</param>
/// <returns>Possible list of paths</returns>
public static string[] GetPossiblePaths(string file)
{
if (Path.IsPathRooted(file))
file = Path.GetFileName(file);
var paths = GetPaths();
List<string> finalPaths = [];
foreach (string path in paths)
{
string finalPath = Path.Combine(path, file);
if (File.Exists(finalPath))
finalPaths.Add(finalPath);
}
return [.. finalPaths];
}

/// <summary>
/// Executes a file with specified arguments and puts the output to the string
/// </summary>
Expand Down

0 comments on commit da171cf

Please sign in to comment.