Files
ytdlp-gui/Program.cs
2025-05-20 02:11:57 +02:00

50 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ytdlp_gui
{
public class Program
{
public Program(string name)
{
// Check for extension
if (Path.GetExtension(name) == "")
// If missing, add .exe as default
name += ".exe";
// Is the program next to us?
string exe_path = System.Reflection.Assembly.GetEntryAssembly().Location;
string exe_directory = Path.GetDirectoryName(exe_path);
program = Path.Combine(exe_directory, name);
// Did we find it?
if (File.Exists(program))
// Finish if we did
return;
// Otherwise...
// Get list of PATHs on Windows
string[] paths = System.Environment.GetEnvironmentVariable("PATH").Split(';');
// Check for program on every path
foreach (string path in paths)
{
program = Path.Combine(path, name);
if (File.Exists(program))
// Finish if we found it
return;
}
// We could not find the program
throw new Exception("Could not find "+name);
}
public readonly string program;
}
}