private static bool TryGetScheduledTaskXDocument(FileInfo file, out XDocument xDocument)
        {
            xDocument = null;

            if (file == null || !file.Exists)
            {
                return(false);
            }

            try
            {
                xDocument = XDocument.Load(file.FullName);
            }
            catch (XmlException)
            {
                //Some files have incorrect encoding :(
                //https://stackoverflow.com/questions/29915467/there-is-no-unicode-byte-order-mark-cannot-switch-to-unicode
                StaticViewModel.AddDebugMessage($"Wrong encoding for {file.FullName}");
                xDocument = XDocument.Parse(File.ReadAllText(file.FullName));
            }

            if (!xDocument.Root.Name.LocalName.Equals("Task", StringComparison.CurrentCulture))
            {
                return(false);
            }

            return(true);
        }
        public void WaitForProcessToEnd(int maxWaitSeconds)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (IsProcessRunning())
            {
                if (sw.ElapsedMilliseconds >= maxWaitSeconds * 1000)
                {
                    foreach (Process process in Process.GetProcessesByName(_fileNameWithoutExtension))
                    {
                        try
                        {
                            process.Kill();
                        }
                        catch (Exception ex)
                        {
                            StaticViewModel.AddDebugMessage(ex, $"Unable to stop process [{process.Id}] {process.ProcessName}");
                        }
                    }
                }

                Thread.Sleep(1000);
            }
        }
Example #3
0
        public void StopRadeonSoftware()
        {
            try
            {
                StaticViewModel.AddLogMessage("Stopping Radeon Software Host Services");
                StaticViewModel.IsLoading = true;

                RadeonSoftwareCli(CNCMD_EXIT);

                //The command to stop the services does not wait for them to fully end
                ProcessHandler hostProcess = new ProcessHandler(_cnDir.FullName + "AMDRSServ.exe");
                hostProcess.WaitForProcessToEnd(30);
                ProcessHandler radeonSoftwareProcess = new ProcessHandler(_cnDir.FullName + "RadeonSoftware.exe");
                radeonSoftwareProcess.WaitForProcessToEnd(30);

                StaticViewModel.AddLogMessage("Stopped Radeon Software Host Services");
            }
            catch (Exception ex)
            {
                StaticViewModel.AddLogMessage(ex, "Failed to stop Radeon Software Host Services");
            }
            finally
            {
                LoadOrRefresh();
                StaticViewModel.IsLoading = false;
            }
        }
        public void Remove()
        {
            if (Keep || !_componentDirectory.Exists)
            {
                return;
            }

            try
            {
                StaticViewModel.AddDebugMessage($"Removing {_componentDirectory.FullName}");

                foreach (IFileInfo file in _componentDirectory.EnumerateFiles("*", SearchOption.AllDirectories))
                {
                    if (file.IsReadOnly)
                    {
                        file.IsReadOnly = false;
                    }
                }

                _componentDirectory.Delete(true);
            }
            catch (Exception ex)
            {
                StaticViewModel.AddDebugMessage(ex, $"Unable to delete {_componentDirectory.FullName}");
            }
        }
Example #5
0
        public void RestartRadeonSoftware()
        {
            try
            {
                StaticViewModel.AddLogMessage("Restarting Radeon Software Host Services");
                StaticViewModel.IsLoading = true;

                RadeonSoftwareCli(CNCMD_RESTART);

                //Wait for services to start back up
                ProcessHandler radeonSoftwareProcess = new ProcessHandler(_cnDir.FullName + "RadeonSoftware.exe");
                radeonSoftwareProcess.WaitForProcessToStart(30);


                StaticViewModel.AddLogMessage("Restarted Radeon Software Host Services");
            }
            catch (Exception ex)
            {
                StaticViewModel.AddLogMessage(ex, "Failed to restart Radeon Software Host Services");
            }
            finally
            {
                LoadOrRefresh();
                StaticViewModel.IsLoading = false;
            }
        }
 private void DetermineUninstallCommand()
 {
     if (_windowsInstaller)
     {
         _uninstallExe = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\msiexec.exe";
         if (Guid.TryParse(ProductCode, out Guid productGuid))
         {
             _uninstallArguments = $"/uninstall {productGuid:B}";
             UninstallCommand    = $"{_uninstallExe} {_uninstallArguments}";
             StaticViewModel.AddDebugMessage($"Detected GUID {productGuid} from {ProductCode} for {DisplayName}");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Unable to determine windows installer GUID from {ProductCode} for {DisplayName}");
         }
     }
     else if (!string.IsNullOrWhiteSpace(UninstallCommand))
     {
         StaticViewModel.AddDebugMessage($"Keeping default uninstall command {UninstallCommand} for {DisplayName}");
     }
     else
     {
         StaticViewModel.AddDebugMessage($"Unable to determine uninstall command for {DisplayName}");
     }
 }
        public int RunProcess(string arguments)
        {
            if (!_file.Exists)
            {
                StaticViewModel.AddDebugMessage($"{_file.FullName} does not exist or user does not have access");
                return(-1);
            }

            using (Process process = new Process())
            {
                process.StartInfo.FileName               = _file.FullName;
                process.StartInfo.Arguments              = arguments;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;

                StaticViewModel.AddDebugMessage($"Running {process.StartInfo.FileName} {process.StartInfo.Arguments}");
                process.Start();
                process.WaitForExit();
                StaticViewModel.AddDebugMessage($"Process finished with ExitCode: {process.ExitCode}");
                StaticViewModel.AddDebugMessage($"StandardOutput: {process.StandardOutput.ReadToEnd()}");
                StaticViewModel.AddDebugMessage($"StandardError: {process.StandardError.ReadToEnd()}");

                return(process.ExitCode);
            }
        }
        private void LoadInfFileInformation(IFileInfo infFile)
        {
            StaticViewModel.AddDebugMessage($"Processing inf file {infFile.FullName}");

            using (StreamReader reader = infFile.OpenText())
            {
                string line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (!string.IsNullOrWhiteSpace(line) && line.Equals("[Strings]", StringComparison.Ordinal))
                    {
                        while (!reader.EndOfStream && !string.IsNullOrWhiteSpace(line))
                        {
                            line = reader.ReadLine();

                            //Would love some consistency here
                            if (line.IndexOf("desc", StringComparison.OrdinalIgnoreCase) >= 0 && line.IndexOf("\"", StringComparison.OrdinalIgnoreCase) > 1)
                            {
                                StaticViewModel.AddDebugMessage($"Attempting to obtain inf file description from {line}");
                                Description = line.Substring(line.IndexOf("\"", StringComparison.OrdinalIgnoreCase)).Trim('\"');
                                return;
                            }
                            if (line.IndexOf("ExtendedGraphics", StringComparison.OrdinalIgnoreCase) >= 0 && line.IndexOf("\"", StringComparison.OrdinalIgnoreCase) > 1)
                            {
                                StaticViewModel.AddDebugMessage($"Attempting to obtain inf file description from {line}");
                                Description = line.Substring(line.IndexOf("\"", StringComparison.OrdinalIgnoreCase)).Trim('\"');
                                return;
                            }
                        }
                    }
                } while (!reader.EndOfStream);
            }
        }
Example #9
0
        private static void ClearFolder(string folder)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(folder);

            if (directoryInfo.Exists)
            {
                foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles())
                {
                    try
                    {
                        fileInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        StaticViewModel.AddDebugMessage(ex, $"Unable to delete {fileInfo.FullName}");
                    }
                }

                foreach (DirectoryInfo subDirectoryInfo in directoryInfo.EnumerateDirectories())
                {
                    ClearFolder(subDirectoryInfo.FullName);

                    try
                    {
                        subDirectoryInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        StaticViewModel.AddDebugMessage(ex, $"Unable to delete {subDirectoryInfo.FullName}");
                    }
                }
            }
        }
        private static IEnumerable <PackageModel> GetAllInstallerPackages(DirectoryInfo installDirectory)
        {
            FileInfo[] packageFiles =
            {
                new FileInfo($@"{installDirectory.FullName}\Bin64\cccmanifest_64.json"),
                new FileInfo($@"{installDirectory.FullName}\Config\InstallManifest.json"),
            };

            foreach (FileInfo file in packageFiles)
            {
                if (file.Exists)
                {
                    using (StreamReader streamReader = new StreamReader(file.OpenRead()))
                        using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
                        {
                            JObject jObject = (JObject)JToken.ReadFrom(jsonTextReader);
                            JToken  jToken  = jObject.SelectToken("Packages.Package");
                            foreach (JToken token in jToken.Children())
                            {
                                PackageModel package = new PackageModel(file);
                                package.Description = token.SelectToken("Info.Description").ToString();
                                package.ProductName = token.SelectToken("Info.productName").ToString();
                                package.Url         = token.SelectToken("Info.url").ToString();
                                package.Type        = token.SelectToken("Info.ptype").ToString();

                                StaticViewModel.AddDebugMessage($"Found package {package.ProductName} in {package.GetFile().FullName}");
                                yield return(package);
                            }
                        }
                }
            }
        }
Example #11
0
        public AboutView()
        {
            InitializeComponent();

            lblVersion.Text = $"Version: {System.Windows.Forms.Application.ProductVersion} (.NET Version: {Environment.Version})";
            StaticViewModel.AddDebugMessage($"{nameof(RadeonSoftwareSlimmer)} version {System.Windows.Forms.Application.ProductVersion} (.NET version {Environment.Version})");
        }
        public AboutView()
        {
            InitializeComponent();

            lblVersion.Text = "Version: " + System.Windows.Forms.Application.ProductVersion;
            StaticViewModel.AddDebugMessage($"{nameof(RadeonSoftwareSlimmer)} version {System.Windows.Forms.Application.ProductVersion}");
        }
Example #13
0
 private void DetermineUninstallCommand()
 {
     //if (_windowsInstaller || UninstallCommand.StartsWith("msiexec", StringComparison.OrdinalIgnoreCase))
     if (_windowsInstaller)
     {
         _uninstallExe = "msiexec.exe";
         if (Guid.TryParse(ProductCode, out Guid productGuid))
         {
             _uninstallArguments = $"/uninstall {productGuid:B}";
             UninstallCommand    = $"{_uninstallExe} {_uninstallArguments}";
             StaticViewModel.AddDebugMessage($"Detected GUID {productGuid} from {ProductCode} for {DisplayName}");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Unable to determine windows installer GUID from {ProductCode} for {DisplayName}");
         }
     }
     else if (!string.IsNullOrWhiteSpace(UninstallCommand))
     {
         //_uninstallExe = "cmd.exe";
         //_uninstallArguments = $"/C \"{UninstallCommand}\"";
         //UninstallCommand = $"{_uninstallExe} {_uninstallArguments}";
         StaticViewModel.AddDebugMessage($"Keeping default uninstall command {UninstallCommand} for {DisplayName}");
     }
     else
     {
         StaticViewModel.AddDebugMessage($"Unable to determine uninstall command for {DisplayName}");
     }
 }
        private static IEnumerable <ScheduledTaskXmlModel> GetInstallerScheduledTasks(DirectoryInfo installDirectory)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(installDirectory + "\\Config");

            foreach (FileInfo file in directoryInfo.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly).Where(f => !f.Name.StartsWith("Monet", StringComparison.CurrentCulture)))
            {
                if (TryGetScheduledTaskXDocument(file, out XDocument xDoc))
                {
                    ScheduledTaskXmlModel scheduledTask = new ScheduledTaskXmlModel(file);
                    XNamespace            xNs           = xDoc.Root.GetDefaultNamespace();

                    //Not every file has a URI specified :(
                    XElement uri = xDoc.Root.Element(xNs + "RegistrationInfo").Element(xNs + "URI");
                    if (uri != null)
                    {
                        scheduledTask.Uri = uri.Value;
                    }

                    scheduledTask.Description = xDoc.Root.Element(xNs + "RegistrationInfo").Element(xNs + "Description").Value;
                    scheduledTask.Enabled     = bool.Parse(xDoc.Root.Element(xNs + "Settings").Element(xNs + "Enabled").Value);

                    string command   = xDoc.Root.Element(xNs + "Actions").Element(xNs + "Exec").Element(xNs + "Command").Value;
                    string arguments = xDoc.Root.Element(xNs + "Actions").Element(xNs + "Exec").Element(xNs + "Arguments").Value;
                    scheduledTask.Command = $"{command} {arguments}";

                    StaticViewModel.AddDebugMessage($"Found scheduled task {uri} in {file.FullName}");
                    yield return(scheduledTask);
                }
            }
        }
Example #15
0
        private static bool IsRadeonTask(Task scheduledTask)
        {
            string author = scheduledTask.Definition.RegistrationInfo.Author;

            if (!string.IsNullOrWhiteSpace(author) &&
                author.Equals("Advanced Micro Devices", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            string name = scheduledTask.Name;

            if (!string.IsNullOrWhiteSpace(name) &&
                (
                    name.Equals("StartCN", StringComparison.OrdinalIgnoreCase) ||
                    name.Equals("StartDVR", StringComparison.OrdinalIgnoreCase) ||
                    name.Equals("StartCNBM", StringComparison.OrdinalIgnoreCase)))
            {
                StaticViewModel.AddDebugMessage($"Found scheduled task {name}");
                return(true);
            }


            return(false);
        }
Example #16
0
        private void LoadCnDirectory()
        {
            using (RegistryKey cnKey = Registry.LocalMachine.OpenSubKey(INSTALL_FOLDER_REGISTRY_KEY))
            {
                if (cnKey != null)
                {
                    string installDir = cnKey.GetValue(INSTALL_FOLDER_REGISTRY_VALUE_NAME).ToString();

                    if (string.IsNullOrWhiteSpace(installDir))
                    {
                        _cnDir = new DirectoryInfo(INSTALL_FOLDER_DEFAULT_PATH);
                        StaticViewModel.AddDebugMessage($"Unable to read {INSTALL_FOLDER_REGISTRY_VALUE_NAME} from {INSTALL_FOLDER_REGISTRY_KEY}. Defaulting to {INSTALL_FOLDER_DEFAULT_PATH}.");
                    }
                    else
                    {
                        _cnDir = new DirectoryInfo(installDir);
                        StaticViewModel.AddDebugMessage($"Found {installDir} from {INSTALL_FOLDER_REGISTRY_KEY}.");
                    }
                }
                else
                {
                    _cnDir = new DirectoryInfo(INSTALL_FOLDER_DEFAULT_PATH);
                    StaticViewModel.AddDebugMessage($"Unable to read from {INSTALL_FOLDER_REGISTRY_KEY}. Defaulting to {INSTALL_FOLDER_DEFAULT_PATH}.");
                }
            }
        }
        private void CheckIfHostServiceIsEnabled()
        {
            _rsServFile         = new FileInfo(_cnDir.FullName + HOST_SERVICE_FILE_NAME);
            _rsServDisabledFile = new FileInfo(_cnDir + HOST_SERVICE_DISABLED_FILE_NAME);
            Enabled             = _rsServFile.Exists;

            StaticViewModel.AddDebugMessage($"{_rsServFile.FullName} Exists: {_rsServFile.Exists}");
            StaticViewModel.AddDebugMessage($"{_rsServDisabledFile.FullName} Exists: {_rsServDisabledFile.Exists}");
        }
Example #18
0
 public VendingMachine()
 {
     TeaCup       = new Cup();
     CoffeeCup    = new Cup();
     CoinAcceptor = new StaticViewModel();
     TeaButton    = new StaticViewModel();
     CoffeeButton = new StaticViewModel();
     RefundButton = new StaticViewModel();
     ExtraCoin    = new ExtraCoin();
 }
        private static IEnumerable <ServiceModel> GetAllRadeonServices()
        {
            string[] serviceNames =
            {
                //Values are the first string after AddService in inf files

                //Main display driver
                //Probably no point in showing this. Is there even a reason to remove it?
                //"amdkmdag",
                //"amdwddmg",

                //AMD PCI Root Bus Lower Filter
                //Probably shouldn't mess with this one either
                //"amdkmpfd",

                //System Devices/Kernel Drivers
                "amdfendr",
                "amdlog",
                "AMDXE",

                //Audio
                "amdacpbus",
                "AMDAfdAudioService",
                "AMDHDAudBusService",
                "amdi2stdmafd",
                "AMDSoundWireAudioService",
                "AtiHDAudioService",
                "AMDSAFD",

                //NT/Windows Services
                "AMD Crash Defender Service",
                "AMD External Events Utility",
                "AMD Log Utility",
                "AUEPLauncher",

                //Other
                "AMDRadeonsettings",

                //Radeon Pro Enterprise
                "amducsi",
                "SSGService",
            };

            foreach (string service in serviceNames)
            {
                ServiceModel serviceModel = new ServiceModel(service);

                if (serviceModel.Exists())
                {
                    StaticViewModel.AddDebugMessage($"Found service {service}");
                    yield return(serviceModel);
                }
            }
        }
        public void StopRadeonSoftware()
        {
            StaticViewModel.AddDebugMessage("Stopping Radeon Software Host Service");
            RadeonSoftwareCli(CNCMD_EXIT);

            //The command to stop the services does not wait for them to fully end
            ProcessHandler hostProcess = new ProcessHandler(_cnDir.FullName + "AMDRSServ.exe");

            hostProcess.WaitForProcessToEnd(30);
            ProcessHandler radeonSoftwareProcess = new ProcessHandler(_cnDir.FullName + "RadeonSoftware.exe");

            radeonSoftwareProcess.WaitForProcessToEnd(30);
        }
 public void UninstallIfSelected()
 {
     if (_uninstall && !string.IsNullOrWhiteSpace(UninstallCommand))
     {
         if (_windowsInstaller)
         {
             ProcessHandler processHandler = new ProcessHandler(_uninstallExe);
             processHandler.RunProcess($"{_uninstallArguments} /quiet /norestart REBOOT=ReallySuppress");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Non-Windows Uninstaller for {DisplayName} not supported");
         }
     }
 }
        private bool IsRadeonUninstall(RegistryKey uninstallKey)
        {
            object publisher   = uninstallKey.GetValue("Publisher");
            object displayName = uninstallKey.GetValue("DisplayName");

            if (publisher != null && displayName != null &&
                publisher.ToString().Equals("Advanced Micro Devices, Inc.", StringComparison.OrdinalIgnoreCase) &&
                !AMD_CHIPSET_NAMES.Any(name => displayName.ToString().Contains(name)))
            {
                StaticViewModel.AddDebugMessage($"Found uninstall item {displayName} under {uninstallKey.Name}");
                return(true);
            }

            return(false);
        }
        private void SetStartMode(ServiceStartMode startMode)
        {
            using (ServiceController serviceController = LoadFreshService())
            {
                //It's this or WMI...
                ProcessHandler processHandler = new ProcessHandler(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\sc.exe");
                processHandler.RunProcess($"config \"{Name}\" start= {GetStartModeCommandString(startMode)}");

                serviceController.Refresh();
                StartMode = serviceController.StartType;
                Enabled   = serviceController.StartType != ServiceStartMode.Disabled;

                StaticViewModel.AddLogMessage($"Changed start mode for {Name} to {StartMode}");
            }
        }
        public DisplayComponentModel(IDirectoryInfo installerRootDirectory, IDirectoryInfo componentDirectory)
        {
            StaticViewModel.AddDebugMessage($"Found display component in {componentDirectory.FullName}");

            Keep = true;

            _componentDirectory = componentDirectory;
            Directory           = componentDirectory.FullName.Substring(componentDirectory.FullName.IndexOf(installerRootDirectory.FullName) + installerRootDirectory.FullName.Length);
            IFileInfo[] infFiles = componentDirectory.GetFiles("*.inf", SearchOption.TopDirectoryOnly);
            if (infFiles.Length > 0)
            {
                InfFile = infFiles[0].Name;
                LoadInfFileInformation(infFiles[0]);
            }
        }
Example #25
0
        public bool ValidateInstallerFile()
        {
            if (string.IsNullOrWhiteSpace(_installerFile))
            {
                StaticViewModel.AddLogMessage($"Please provide an installer file");
                return(false);
            }

            if (!File.Exists(_installerFile))
            {
                StaticViewModel.AddLogMessage($"Installer file {_installerFile} does not exist or cannot be accessed");
                return(false);
            }

            return(true);
        }
        public void Enable()
        {
            using (Task task = TaskService.Instance.GetTask(Name))
            {
                if (!task.Definition.Settings.Enabled)
                {
                    StaticViewModel.AddDebugMessage($"Enabling scheduled task {Name}");
                    task.Definition.Settings.Enabled = true;

                    task.RegisterChanges();

                    Active  = task.IsActive;
                    State   = task.State;
                    Enabled = task.Enabled;
                }
            }
        }
        public void Disable()
        {
            if (_rsServFile.Exists)
            {
                if (_rsServDisabledFile.Exists)
                {
                    StaticViewModel.AddDebugMessage($"Deleting previous disable file ${_rsServDisabledFile.FullName}");
                    _rsServDisabledFile.Delete();
                }

                StaticViewModel.AddDebugMessage($"Renaming {_rsServFile.Name} to {_rsServDisabledFile.Name}");
                _rsServFile.MoveTo(_rsServDisabledFile.FullName);

                StaticViewModel.AddDebugMessage("Host Service Disabled");
                Enabled = false;
            }
        }
        private static IEnumerable <TempFileModel> GetAllRadeonTempFiles()
        {
            string[] tempFolders =
            {
                //C:\AMD
                $@"{Environment.GetEnvironmentVariable("SystemDrive", EnvironmentVariableTarget.Process)}\AMD",

                //Computer\HKEY_LOCAL_MACHINE\SOFTWARE\ATI Technologies\Install,InstallDir,C:\Program Files\AMD\CIM
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CIM\Log",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CIM\Reports",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD_Common",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CN\Analytics",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CN\NewsFeed",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\Dx9Cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\DxCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\GLCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\VkCache",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\Radeonsoftware\cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\RadeonInstaller\cache",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\Dx9Cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\DxCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\GLCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\VkCache",

                //C:\Windows\System32\AMD
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.System, Environment.SpecialFolderOption.DoNotVerify)}\AMD",
            };

            foreach (string tempFolder in tempFolders)
            {
                if (Directory.Exists(tempFolder))
                {
                    StaticViewModel.AddDebugMessage($"Found temp folder {tempFolder}");
                    yield return(new TempFileModel(tempFolder));
                }
                else
                {
                    StaticViewModel.AddDebugMessage($"Folder {tempFolder} does not exist or cannot be accessed");
                }
            }
        }
        public void TryStart()
        {
            if (_startMode == ServiceStartMode.Disabled)
            {
                StaticViewModel.AddLogMessage($"Cannot start {Name} because it is disabled");
                return;
            }

            if (_serviceType.HasFlag(ServiceType.KernelDriver))
            {
                StaticViewModel.AddLogMessage($"Cannot start {Name} because it is a kernel driver");
                return;
            }

            try
            {
                StaticViewModel.AddLogMessage("Restarting " + Name);
                StaticViewModel.IsLoading = true;

                TryStop();

                using (ServiceController serviceController = LoadFreshService())
                {
                    if (serviceController.StartType != ServiceStartMode.Disabled && serviceController.ServiceType.HasFlag(ServiceType.Win32OwnProcess))
                    {
                        serviceController.Start();
                        serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30));

                        Status = serviceController.Status;
                        StaticViewModel.AddLogMessage("Restarted " + Name);
                    }
                }
            }
            catch (Exception ex)
            {
                StaticViewModel.AddLogMessage(ex, "Failed to restart " + Name);
            }
            finally
            {
                StaticViewModel.IsLoading = false;
            }
        }
        public void TryStop()
        {
            if (_serviceType.HasFlag(ServiceType.KernelDriver))
            {
                StaticViewModel.AddLogMessage($"Cannot stop {Name} because it is a kernel driver");
                return;
            }

            try
            {
                StaticViewModel.AddLogMessage("Stopping " + Name);
                StaticViewModel.IsLoading = true;

                using (ServiceController serviceController = LoadFreshService())
                {
                    if (serviceController.Status == ServiceControllerStatus.Running && serviceController.ServiceType.HasFlag(ServiceType.Win32OwnProcess))
                    {
                        try
                        {
                            serviceController.Stop();
                            serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30));
                        }
                        catch (InvalidOperationException ex)
                        {
                            StaticViewModel.AddDebugMessage(ex);
                        }

                        Status = serviceController.Status;
                    }
                }

                StaticViewModel.AddLogMessage("Stopped " + Name);
            }
            catch (Exception ex)
            {
                StaticViewModel.AddLogMessage(ex, "Failed to stop " + Name);
            }
            finally
            {
                StaticViewModel.IsLoading = false;
            }
        }