using System.Diagnostics;
using System.IO;
using System.Linq;

namespace VMwareLauncher
{
    public class ProcessControl
    {
        public readonly static string DefaultVmwareExe = "vmware";
        public readonly static string DefaultVmwarePath = (string) Microsoft.Win32.Registry.GetValue(
            @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation",
            "InstallPath", null) +
            $"{DefaultVmwareExe}.exe";
        public readonly static string DefaultVmLauncherPath = "vmwarelauncher";
        public string ProcessName { get; set; }

        public void StartProcess()
        {
            ProcessStartInfo pInf = new ProcessStartInfo(ProcessName);
            FileInfo fInf = new FileInfo(ProcessName);

            pInf.WorkingDirectory = fInf.DirectoryName;
            Process proc = Process.Start(pInf);
        }

        public bool IsProcessRunning()
        {
            Process[] proc = Process.GetProcessesByName(ProcessName);
            return proc.Count() != 1;
        }
    }
}
