Fixed tasks order (GPU cannot be disabled when there are no other GPUs)

master
Inga 🏳‍🌈 5 years ago
parent 4a588b5d5c
commit 916fe02381
  1. 4
      RadeonResetBugFixService/Constants.cs
  2. 7
      RadeonResetBugFixService/MainHandler.cs
  3. 1
      RadeonResetBugFixService/ProjectInstaller.Designer.cs
  4. 27
      RadeonResetBugFixService/ProjectInstaller.cs
  5. 28
      RadeonResetBugFixService/Tasks/DisableBasicDisplayStartupTask.cs
  6. 4
      RadeonResetBugFixService/Tasks/EnableBasicDisplayStartupTask.cs
  7. 38
      RadeonResetBugFixService/Tasks/LastResortDevicesRestoreTask.cs

@ -6,6 +6,8 @@
{
public static TimeSpan ServiceTimeout { get; } = TimeSpan.FromMinutes(5);
public static string BasicDisplayRegistryKey { get; } = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BasicDisplay";
public static string RegistryKeyBasicDisplay { get; } = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BasicDisplay";
public static string RegistryKeySystemControl { get; } = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control";
}
}

@ -51,8 +51,8 @@
{
new EnableBasicDisplayStartupTask(),
new SleepTask(TimeSpan.FromSeconds(20)),
new DisableVirtualVideoTask(this.StartupDevicesStatus),
new EnableAmdVideoTask(this.StartupDevicesStatus),
new DisableVirtualVideoTask(this.StartupDevicesStatus),
new SleepTask(TimeSpan.FromSeconds(40)),
new FixMonitorTask(),
new DisableVirtualVideoTask(this.StartupDevicesStatus),
@ -84,12 +84,11 @@
new ITask[]
{
new StopAudioServiceTask(),
new SleepTask(TimeSpan.FromSeconds(15)),
new DisableAmdVideoTask(this.ShutdownDevicesStatus),
new EnableVirtualVideoTask(this.ShutdownDevicesStatus),
new DisableAmdVideoTask(this.ShutdownDevicesStatus),
new LastResortDevicesRestoreTask(this.StartupDevicesStatus),
new LastResortDevicesRestoreTask(this.StartupDevicesStatus), // just in case
new DisableBasicDisplayStartupTask(),
new DisableBasicDisplayStartupTask(this.StartupDevicesStatus),
});
}
}

@ -45,6 +45,7 @@
this.serviceInstaller1.ServiceName = "RadeonResetBugFixService";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall);
this.serviceInstaller1.AfterUninstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterUninstall);
//
// ProjectInstaller
//

@ -2,7 +2,9 @@
{
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Management;
using Microsoft.Win32;
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
@ -32,11 +34,36 @@
}
ThirdParty.ServicePreshutdownHelpers.ServicePreshutdownHelpers.SetPreShutdownTimeOut(this.serviceInstaller1.ServiceName, (uint)Constants.ServiceTimeout.TotalMilliseconds);
var preshutdownOrder = GetPreshutdownOrder();
if (!preshutdownOrder.Contains(this.serviceInstaller1.ServiceName))
{
SetPreshutdownOrder(new[] { this.serviceInstaller1.ServiceName }.Concat(preshutdownOrder).ToArray());
}
}
private void serviceInstaller1_AfterUninstall(object sender, InstallEventArgs e)
{
var preshutdownOrder = GetPreshutdownOrder();
if (preshutdownOrder.Contains(this.serviceInstaller1.ServiceName))
{
SetPreshutdownOrder(preshutdownOrder.Where((name) => name != this.serviceInstaller1.ServiceName).ToArray());
}
}
private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
}
private string[] GetPreshutdownOrder()
{
return (string[])Registry.GetValue(Constants.RegistryKeySystemControl, "PreshutdownOrder", new string[0]);
}
private void SetPreshutdownOrder(string[] data)
{
Registry.SetValue(Constants.RegistryKeySystemControl, "PreshutdownOrder", data, RegistryValueKind.MultiString);
}
}
}

@ -1,17 +1,41 @@
namespace RadeonResetBugFixService.Tasks
{
using System;
using Microsoft.Win32;
using Contracts;
using Devices;
class DisableBasicDisplayStartupTask : ITask
{
string ITask.TaskName => "Disabling basic display automatic start";
private DevicesStatus StartupDevicesStatus { get; }
public DisableBasicDisplayStartupTask(DevicesStatus startupDevicesStatus)
{
if (startupDevicesStatus == null)
{
throw new ArgumentNullException(nameof(startupDevicesStatus));
}
this.StartupDevicesStatus = startupDevicesStatus;
}
void ITask.Run(ILogger logger)
{
var originalValue = Registry.GetValue(Constants.BasicDisplayRegistryKey, "Start", -1);
foreach (var device in this.StartupDevicesStatus.DisabledDevices)
{
logger.Log($"Processing {device.Description}; should be enabled");
var disabledStatus = DeviceHelper.IsDeviceCurrentlyDisabled(device);
if (disabledStatus.HasValue && !disabledStatus.Value)
{
logger.Log($"Device is enabled; disabling BasicDisplay service");
var originalValue = Registry.GetValue(Constants.RegistryKeyBasicDisplay, "Start", -1);
logger.Log($"Original start value {originalValue}");
Registry.SetValue(Constants.BasicDisplayRegistryKey, "Start", 4);
Registry.SetValue(Constants.RegistryKeyBasicDisplay, "Start", 4);
}
}
}
}
}

@ -9,9 +9,9 @@
void ITask.Run(ILogger logger)
{
var originalValue = Registry.GetValue(Constants.BasicDisplayRegistryKey, "Start", -1);
var originalValue = Registry.GetValue(Constants.RegistryKeyBasicDisplay, "Start", -1);
logger.Log($"Original start value {originalValue}");
Registry.SetValue(Constants.BasicDisplayRegistryKey, "Start", 3);
Registry.SetValue(Constants.RegistryKeyBasicDisplay, "Start", 3);
}
}
}

@ -22,9 +22,9 @@
void ITask.Run(ILogger logger)
{
foreach (var device in this.StartupDevicesStatus.EnabledDevices)
foreach (var device in this.StartupDevicesStatus.DisabledDevices)
{
logger.Log($"Processing {device.Description}; should be disabled");
logger.Log($"Processing {device.Description}; should be enabled");
try
{
var disabledStatus = DeviceHelper.IsDeviceCurrentlyDisabled(device);
@ -32,19 +32,18 @@
{
logger.Log("Device not present");
}
else if (!disabledStatus.Value)
else if (disabledStatus.Value)
{
logger.Log("Device enabled; attempting to disable...");
DeviceHelper.DisableDevice(device);
logger.Log("Disabled device; checking status...");
logger.Log("Device disabled; attempting to enable...");
DeviceHelper.EnableDevice(device);
logger.Log("Enabled device; checking status...");
var newStatus = DeviceHelper.IsDeviceCurrentlyDisabled(device);
if (!newStatus.HasValue)
{
logger.LogError("Device not present");
}
else if (!newStatus.Value)
} else if (newStatus.Value)
{
logger.LogError("Device is enabled but should be disabled");
logger.LogError("Device is disabled but should be enabled");
}
else
{
@ -53,7 +52,7 @@
}
else
{
logger.Log("Device is disabled");
logger.Log("Device is enabled");
}
}
catch (Exception e)
@ -62,9 +61,9 @@
}
}
foreach (var device in this.StartupDevicesStatus.DisabledDevices)
foreach (var device in this.StartupDevicesStatus.EnabledDevices)
{
logger.Log($"Processing {device.Description}; should be enabled");
logger.Log($"Processing {device.Description}; should be disabled");
try
{
var disabledStatus = DeviceHelper.IsDeviceCurrentlyDisabled(device);
@ -72,18 +71,19 @@
{
logger.Log("Device not present");
}
else if (disabledStatus.Value)
else if (!disabledStatus.Value)
{
logger.Log("Device disabled; attempting to enable...");
DeviceHelper.EnableDevice(device);
logger.Log("Enabled device; checking status...");
logger.Log("Device enabled; attempting to disable...");
DeviceHelper.DisableDevice(device);
logger.Log("Disabled device; checking status...");
var newStatus = DeviceHelper.IsDeviceCurrentlyDisabled(device);
if (!newStatus.HasValue)
{
logger.LogError("Device not present");
} else if (newStatus.Value)
}
else if (!newStatus.Value)
{
logger.LogError("Device is disabled but should be enabled");
logger.LogError("Device is enabled but should be disabled");
}
else
{
@ -92,7 +92,7 @@
}
else
{
logger.Log("Device is enabled");
logger.Log("Device is disabled");
}
}
catch (Exception e)

Loading…
Cancel
Save