Ejemplo n.º 1
0
        private string GetPath(WhichExe whichExe)
        {
            string result = default;

            string fileName = whichExe switch
            {
                WhichExe.WireGuardExe => "wireguard.exe",
                WhichExe.WGExe => "wg.exe",
                // This case should never be hit, since custom exes provide their own name via Args
                _ => default
            };

            // Must use EnvironmentVariableTarget.Machine so that we always get the latest variables, even if they change after our process starts.
            if (Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.Machine) is { } pathEnv)
            {
                foreach (string path in pathEnv.Split(';'))
                {
                    string wireGuardExePath = Path.Combine(path, fileName);
                    if (File.Exists(wireGuardExePath))
                    {
                        result = wireGuardExePath;
                        break;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 public WireGuardCommand(string @switch, WhichExe whichExe, params string[] args)
 {
     Switch   = @switch;
     WhichExe = whichExe;
     Args     = args;
 }