diff --git a/VkDiag.sln.DotSettings b/VkDiag.sln.DotSettings new file mode 100644 index 0000000..36ccb43 --- /dev/null +++ b/VkDiag.sln.DotSettings @@ -0,0 +1,5 @@ + + True + True + True + True \ No newline at end of file diff --git a/VkDiag/Interop/PackageManager.cs b/VkDiag/Interop/PackageManager.cs index f035e52..8654bfa 100644 --- a/VkDiag/Interop/PackageManager.cs +++ b/VkDiag/Interop/PackageManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.Linq; using Windows.Win32; using Windows.Win32.Foundation; @@ -58,7 +57,6 @@ public static string GetPackageVersion(string packageFullName, string defaultVer if (PInvoke.OpenPackageInfoByFullName(packageFullName, out var pkgRef) is WIN32_ERROR.NO_ERROR) try { - var handle = Process.GetCurrentProcess().SafeHandle; uint bufLen = 0; var result = PInvoke.GetPackageInfo( pkgRef, diff --git a/VkDiag/Program.AppxPackages.cs b/VkDiag/Program.AppxPackages.cs index ec2718b..674ad70 100644 --- a/VkDiag/Program.AppxPackages.cs +++ b/VkDiag/Program.AppxPackages.cs @@ -6,10 +6,12 @@ namespace VkDiag; internal static partial class Program { + // ReSharper disable StringLiteralTypo private static readonly List<(string id, string title)> KnownPackages = [ ("Microsoft.D3DMappingLayers_8wekyb3d8bbwe", "OpenCL, OpenGL, and Vulkan Compatibility Pack"), ]; + // ReSharper restore StringLiteralTypo private static void CheckAppxPackages() { diff --git a/VkDiag/Program.GpuDriverInfo.cs b/VkDiag/Program.GpuDriverInfo.cs index 2969c42..2c7851e 100644 --- a/VkDiag/Program.GpuDriverInfo.cs +++ b/VkDiag/Program.GpuDriverInfo.cs @@ -10,18 +10,20 @@ namespace VkDiag; internal static partial class Program { - private static readonly HashSet ServiceBlockList = new HashSet - { + // ReSharper disable StringLiteralTypo + private static readonly HashSet ServiceBlockList = + [ "BasicDisplay", "WUDFRd", "HyperVideo", "MS Idd Device", "IndirectKmd", "spacedesk Graphics Adapter", - + "LuminonCore IDDCX Adapter", - "Parsec Virtual Display Adapter", - }; + "Parsec Virtual Display Adapter" + ]; + // ReSharper restore StringLiteralTypo private static bool CheckGpuDrivers() { @@ -43,187 +45,186 @@ private static bool CheckGpuDrivers() } foreach (var gpuGuid in videoKey.GetSubKeyNames()) - using (var gpuKey = videoKey.OpenSubKey(gpuGuid)) - { - if (gpuKey is null) - continue; + { + using var gpuKey = videoKey.OpenSubKey(gpuGuid); + if (gpuKey is null) + continue; - var gpuSubKeys = gpuKey.GetSubKeyNames(); - if (!gpuSubKeys.Contains("Video")) - continue; + var gpuSubKeys = gpuKey.GetSubKeyNames(); + if (!gpuSubKeys.Contains("Video")) + continue; - if (gpuSubKeys.Contains("0000")) - gpuGuidList.Add(gpuGuid); - else - using (var videoSubKey = gpuKey.OpenSubKey("Video")) - { - if ((videoSubKey?.GetValueNames().Contains("Service") ?? false) - && !ServiceBlockList.Contains(videoSubKey.GetValue("Service"))) - { - inactiveGpuGuidList.Add(gpuGuid); - } - } + if (gpuSubKeys.Contains("0000")) + gpuGuidList.Add(gpuGuid); + else + { + using var videoSubKey = gpuKey.OpenSubKey("Video"); + if ((videoSubKey?.GetValueNames().Contains("Service") ?? false) + && !ServiceBlockList.Contains(videoSubKey.GetValue("Service"))) + { + inactiveGpuGuidList.Add(gpuGuid); + } } + } WriteLogLine(); WriteLogLine($"Found {gpuGuidList.Count} active GPU{(gpuGuidList.Count == 1 ? "" : "s")}:"); foreach (var gpuGuid in inactiveGpuGuidList.Concat(gpuGuidList)) - using (var gpuKey = videoKey.OpenSubKey(gpuGuid)) + { + using var gpuKey = videoKey.OpenSubKey(gpuGuid); + if (gpuKey == null) { - if (gpuKey == null) - { - WriteLogLine(ConsoleColor.Red, "x", $"Failed to read driver info for GPU {gpuGuid}"); - continue; - } - var name = ""; - if (inactiveGpuGuidList.Contains(gpuGuid)) - { - using (var gpuVideoKey = gpuKey.OpenSubKey("Video")) - name = ((string)gpuVideoKey?.GetValue("DeviceDesc"))?.Split(';').Last() - ?? (string)gpuVideoKey?.GetValue("Service") - ?? gpuGuid; - WriteLogLine(defaultFgColor, "-", name); - } - else + WriteLogLine(ConsoleColor.Red, "x", $"Failed to read driver info for GPU {gpuGuid}"); + continue; + } + var name = ""; + if (inactiveGpuGuidList.Contains(gpuGuid)) + { + using (var gpuVideoKey = gpuKey.OpenSubKey("Video")) + name = ((string)gpuVideoKey?.GetValue("DeviceDesc"))?.Split(';').Last() + ?? (string)gpuVideoKey?.GetValue("Service") + ?? gpuGuid; + WriteLogLine(DefaultFgColor, "-", name); + } + else + { + var vkReg = false; + var broken = false; + var brokenDriverRegistration = false; + var removedBroken = true; + var driverVer = ""; + var driverDate = ""; + var outputList = gpuKey.GetSubKeyNames().Where(n => Regex.IsMatch(n, @"\d{4}")).ToList(); + foreach (var output in outputList) { - var vkReg = false; - var broken = false; - var brokenDriverRegistration = false; - var removedBroken = true; - var driverVer = ""; - var driverDate = ""; - var outputList = gpuKey.GetSubKeyNames().Where(n => Regex.IsMatch(n, @"\d{4}")).ToList(); - foreach (var output in outputList) - using (var outputKey = gpuKey.OpenSubKey(output, autofix)) - { - if (outputKey == null) - continue; + using var outputKey = gpuKey.OpenSubKey(output, autofix); + if (outputKey == null) + continue; - if (string.IsNullOrEmpty(driverVer)) - driverVer = outputKey.GetValue("DriverVersion") as string; - if (string.IsNullOrEmpty(driverDate)) - driverDate = outputKey.GetValue("DriverDate") as string; - if (string.IsNullOrEmpty(name)) - name = outputKey.GetValue("DriverDesc") as string; - if (string.IsNullOrEmpty(name)) - { - name = gpuGuid; - hasBrokenEntries = brokenDriverRegistration = true; - } + if (string.IsNullOrEmpty(driverVer)) + driverVer = outputKey.GetValue("DriverVersion") as string; + if (string.IsNullOrEmpty(driverDate)) + driverDate = outputKey.GetValue("DriverDate") as string; + if (string.IsNullOrEmpty(name)) + name = outputKey.GetValue("DriverDesc") as string; + if (string.IsNullOrEmpty(name)) + { + name = gpuGuid; + hasBrokenEntries = brokenDriverRegistration = true; + } - foreach (var entry in driverVkEntries) - { - var entryValue = outputKey.GetValue(entry); - if (entryValue == null) - continue; + foreach (var entry in driverVkEntries) + { + var entryValue = outputKey.GetValue(entry); + if (entryValue == null) + continue; - var fixedList = new List(); + var fixedList = new List(); + void ValidatePath(string p) + { + if (File.Exists(p)) + { + fixedList.Add(p); + if (entry.StartsWith("VulkanDriverName")) + hasProperVulkanDrivers = vkReg = true; + } + else + hasBrokenEntries = broken = true; + } - void validatePath(string p) - { - if (File.Exists(p)) - { - fixedList.Add(p); - if (entry.StartsWith("VulkanDriverName")) - hasProperVulkanDrivers = vkReg = true; - } - else - hasBrokenEntries = broken = true; - } + if (entryValue is string[] multiline) + foreach (var p in multiline) + ValidatePath(p); + else + { + var p = (string)entryValue; + ValidatePath(p); + } + if (!broken) + continue; - if (entryValue is string[] multiline) - foreach (var p in multiline) - validatePath(p); + if (autofix) + { + RestartIfNotElevated(); + try + { + if (fixedList.Count == 0) + outputKey.DeleteValue(entry); + else if (fixedList.Count == 1) + outputKey.SetValue(entry, fixedList[0]); else - { - var p = (string)entryValue; - validatePath(p); - } - if (!broken) - continue; - - if (autofix) - { - RestartIfNotElevated(); - try - { - if (fixedList.Count == 0) - outputKey.DeleteValue(entry); - else if (fixedList.Count == 1) - outputKey.SetValue(entry, fixedList[0]); - else - outputKey.SetValue(entry, fixedList.ToArray()); - } - catch - { - fixedEverything = removedBroken = false; + outputKey.SetValue(entry, fixedList.ToArray()); + } + catch + { + fixedEverything = removedBroken = false; #if DEBUG WriteLogLine(ConsoleColor.Red, "x", $"Failed to fix {outputKey} @{entry}"); #endif - } - } - else - fixedEverything = removedBroken = false; } } - - // device name with overall status - var color = ConsoleColor.Green; - var status = "+"; - if ((!broken || removedBroken) && !brokenDriverRegistration) - { - if (vkReg) - status = "v"; - } - else - { - color = ConsoleColor.DarkYellow; - status = "!"; + else + fixedEverything = removedBroken = false; } - WriteLogLine(color, status, name); - // per-gpu checks - if (brokenDriverRegistration) - WriteLogLine(ConsoleColor.Red, "x", " Broken driver registration (?)"); - if (!string.IsNullOrEmpty(driverVer)) - { - if (!string.IsNullOrEmpty(driverDate)) - driverVer += $" ({driverDate})"; - WriteLogLine(defaultFgColor, "+", " Driver version: " + driverVer); + } - var hasDate = DateTime.TryParseExact(driverDate, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var driverDateTime); - if (!hasDate) - { - var match = Regex.Match(driverDate, @"(?\d{1,2})-(?\d{1,2})-(?\d{4})"); - if (match.Success - && int.TryParse(match.Groups["year"].Value, out var year) - && int.TryParse(match.Groups["month"].Value, out var month) - && int.TryParse(match.Groups["day"].Value, out var day)) - { - driverDateTime = new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Utc); - hasDate = true; - } - } - if (hasDate) + // device name with overall status + var color = ConsoleColor.Green; + var status = "+"; + if ((!broken || removedBroken) && !brokenDriverRegistration) + { + if (vkReg) + status = "v"; + } + else + { + color = ConsoleColor.DarkYellow; + status = "!"; + } + WriteLogLine(color, status, name); + // per-gpu checks + if (brokenDriverRegistration) + WriteLogLine(ConsoleColor.Red, "x", " Broken driver registration (?)"); + if (!string.IsNullOrEmpty(driverVer)) + { + if (!string.IsNullOrEmpty(driverDate)) + driverVer += $" ({driverDate})"; + WriteLogLine(DefaultFgColor, "+", " Driver version: " + driverVer); + + var hasDate = DateTime.TryParseExact(driverDate, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var driverDateTime); + if (!hasDate) + { + var match = Regex.Match(driverDate, @"(?\d{1,2})-(?\d{1,2})-(?\d{4})"); + if (match.Success + && int.TryParse(match.Groups["year"].Value, out var year) + && int.TryParse(match.Groups["month"].Value, out var month) + && int.TryParse(match.Groups["day"].Value, out var day)) { - if (driverDateTime < DateTime.UtcNow.AddMonths(-2)) - WriteLogLine(ConsoleColor.DarkYellow, "!", " Please consider updating your video driver"); - else if (driverDateTime < DateTime.UtcNow.AddMonths(-6)) - { - everythingIsFine = false; - WriteLogLine(ConsoleColor.Red, "x", " Please update your video driver"); - } + driverDateTime = new(year, month, day, 0, 0, 0, DateTimeKind.Utc); + hasDate = true; } } - if (vkReg) - WriteLogLine(ConsoleColor.Green, "v", " Proper Vulkan driver registration"); - if (broken) + if (hasDate) { - if (removedBroken) - WriteLogLine(ConsoleColor.Green, "+", " Removed broken Vulkan registration entries"); - else - WriteLogLine(ConsoleColor.DarkYellow, "!", " Has broken Vulkan registration entries"); + if (driverDateTime < DateTime.UtcNow.AddMonths(-2)) + WriteLogLine(ConsoleColor.DarkYellow, "!", " Please consider updating your video driver"); + else if (driverDateTime < DateTime.UtcNow.AddMonths(-6)) + { + everythingIsFine = false; + WriteLogLine(ConsoleColor.Red, "x", " Please update your video driver"); + } } } + if (vkReg) + WriteLogLine(ConsoleColor.Green, "v", " Proper Vulkan driver registration"); + if (broken) + { + if (removedBroken) + WriteLogLine(ConsoleColor.Green, "+", " Removed broken Vulkan registration entries"); + else + WriteLogLine(ConsoleColor.DarkYellow, "!", " Has broken Vulkan registration entries"); + } } + } } return inactiveGpuGuidList.Count > 0; diff --git a/VkDiag/Program.Logging.cs b/VkDiag/Program.Logging.cs index 24b731b..609bae2 100644 --- a/VkDiag/Program.Logging.cs +++ b/VkDiag/Program.Logging.cs @@ -4,8 +4,8 @@ namespace VkDiag; internal static partial class Program { - private static readonly ConsoleColor defaultFgColor = Console.ForegroundColor; - private static readonly object theDoor = new(); + private static readonly ConsoleColor DefaultFgColor = Console.ForegroundColor; + private static readonly object TheDoor = new(); private static void WriteLogLine(ConsoleColor statusColor, string status, string description) { @@ -14,33 +14,33 @@ private static void WriteLogLine(ConsoleColor statusColor, string status, string if (val.Length < description.Length) prefix = description.Substring(0, description.Length - val.Length); - lock (theDoor) + lock (TheDoor) { Console.Write(prefix + '['); Console.ForegroundColor = statusColor; Console.Write(status); - Console.ForegroundColor = defaultFgColor; + Console.ForegroundColor = DefaultFgColor; Console.WriteLine("] " + val); } } private static void WriteLogLine(ConsoleColor statusColor, string line) { - lock (theDoor) + lock (TheDoor) { Console.ForegroundColor = statusColor; Console.WriteLine(line); - Console.ForegroundColor = defaultFgColor; + Console.ForegroundColor = DefaultFgColor; } } private static void WriteLogLine(string line) { - lock (theDoor) Console.WriteLine(line); + lock (TheDoor) Console.WriteLine(line); } private static void WriteLogLine() { - lock (theDoor) Console.WriteLine('\u200b'); // zero width space to workaround bug with emitted \r instead of \r\n + lock (TheDoor) Console.WriteLine('\u200b'); // zero width space to workaround bug with emitted \r instead of \r\n } } \ No newline at end of file diff --git a/VkDiag/Program.OsInfo.cs b/VkDiag/Program.OsInfo.cs index b1dae17..bd4f6db 100644 --- a/VkDiag/Program.OsInfo.cs +++ b/VkDiag/Program.OsInfo.cs @@ -11,9 +11,9 @@ namespace VkDiag; internal static partial class Program { - private static readonly Dictionary VulkanLoaderExpectedVersions = new Dictionary + private static readonly Dictionary VulkanLoaderExpectedVersions = new() { - ["1"] = new Version(1, 2, 141, 0), + ["1"] = new(1, 2, 141, 0), }; private static Version CheckOs() @@ -24,9 +24,9 @@ private static Version CheckOs() var scope = ManagementPath.DefaultPath.ToString(); using var searcher = new ManagementObjectSearcher(scope, "SELECT Name FROM CIM_Processor"); using var collection = searcher.Get(); - foreach (var cpui in collection) + foreach (var cpuInfo in collection) { - var cpuName = cpui.GetPropertyValue("Name") as string; + var cpuName = cpuInfo.GetPropertyValue("Name") as string; WriteLogLine(ConsoleColor.Cyan, "i", "CPU: " + cpuName); } } @@ -45,52 +45,49 @@ private static Version CheckOs() try { var scope = ManagementPath.DefaultPath.ToString(); - using (var searcher = new ManagementObjectSearcher(scope, "SELECT Caption, Version FROM CIM_OperatingSystem")) - using (var collection = searcher.Get()) + using var searcher = new ManagementObjectSearcher(scope, "SELECT Caption, Version FROM CIM_OperatingSystem"); + using var collection = searcher.Get(); + foreach (var osi in collection) { - foreach (var osi in collection) + var osName = osi.GetPropertyValue("Caption") as string; + var osVersion = osi.GetPropertyValue("Version") as string ?? ""; + var color = DefaultFgColor; + var verColor = color; + var status = "+"; + var verStatus = "+"; + var osStatus = OsSupportStatus.Unknown; + if (Version.TryParse(osVersion, out osVer)) + { + (osStatus, var osVerName) = GetWindowsInfo(osVer); + if (!string.IsNullOrEmpty(osVerName)) + osVersion += $" (Windows {osVerName})"; + } + if (osStatus != OsSupportStatus.Unknown) { - var osName = osi.GetPropertyValue("Caption") as string; - var osVersion = osi.GetPropertyValue("Version") as string ?? ""; - var color = defaultFgColor; - var verColor = color; - var status = "+"; - var verStatus = "+"; - var osStatus = OsSupportStatus.Unknown; - if (Version.TryParse(osVersion, out osVer)) + if (osStatus == OsSupportStatus.Deprecated) { - string osVerName; - (osStatus, osVerName) = GetWindowsInfo(osVer); - if (!string.IsNullOrEmpty(osVerName)) - osVersion += $" (Windows {osVerName})"; + color = ConsoleColor.DarkYellow; + status = "!"; + verColor = color; + verStatus = status; } - if (osStatus != OsSupportStatus.Unknown) + else if (osStatus == OsSupportStatus.Prerelease) { - if (osStatus == OsSupportStatus.Deprecated) - { - color = ConsoleColor.DarkYellow; - status = "!"; - verColor = color; - verStatus = status; - } - else if (osStatus == OsSupportStatus.Prerelease) - { - verColor = ConsoleColor.DarkYellow; - verStatus = "!"; - } - else - { - color = ConsoleColor.Green; - verColor = color; - } + verColor = ConsoleColor.DarkYellow; + verStatus = "!"; + } + else + { + color = ConsoleColor.Green; + verColor = color; } - WriteLogLine(color, status, "OS: " + osName); - WriteLogLine(verColor, verStatus, "Version: " + osVersion); - if (osStatus == OsSupportStatus.Deprecated) - WriteLogLine(verColor, "!", " This version of Windows has reached the End of Service status for mainstream support"); - else if (osStatus == OsSupportStatus.Prerelease) - WriteLogLine(verColor, "!", " This version of Windows is a pre-release software and may contain all kinds of issues"); } + WriteLogLine(color, status, "OS: " + osName); + WriteLogLine(verColor, verStatus, "Version: " + osVersion); + if (osStatus == OsSupportStatus.Deprecated) + WriteLogLine(verColor, "!", " This version of Windows has reached the End of Service status for mainstream support"); + else if (osStatus == OsSupportStatus.Prerelease) + WriteLogLine(verColor, "!", " This version of Windows is a pre-release software and may contain all kinds of issues"); } } #if DEBUG @@ -123,7 +120,7 @@ private static Version CheckOs() if (!string.IsNullOrEmpty(libVerInfo.FileVersion)) { var abiVersion = Path.GetFileNameWithoutExtension(libPath).Split('-').Last(); - var color = defaultFgColor; + var color = DefaultFgColor; if (Version.TryParse(libVerInfo.FileVersion, out var libDllVersion) && VulkanLoaderExpectedVersions.TryGetValue(abiVersion, out var expectedVersion) && libDllVersion >= expectedVersion) @@ -214,27 +211,27 @@ private static (OsSupportStatus status, string name) GetWindowsInfo(Version wind private static bool HasPerformanceModeProfile() { - var imagePath = Assembly.GetEntryAssembly().Location; + if (Assembly.GetEntryAssembly()?.Location is not { } imagePath) + return false; + var basePath = @"Software\Microsoft\DirectX\UserGpuPreferences"; - using (var userGpuPrefs = Registry.CurrentUser.OpenSubKey(basePath, true)) - { - if (userGpuPrefs is null) - return true; + using var userGpuPrefs = Registry.CurrentUser.OpenSubKey(basePath, true); + if (userGpuPrefs is null) + return true; - var globalPrefValue = userGpuPrefs.GetValue("DirectXUserGlobalSettings") as string; - if (globalPrefValue?.Contains("GpuPreference=2") ?? false) - return true; + var globalPrefValue = userGpuPrefs.GetValue("DirectXUserGlobalSettings") as string; + if (globalPrefValue?.Contains("GpuPreference=2") ?? false) + return true; - var profile = userGpuPrefs.GetValueNames().Any(v => v == imagePath); - if (profile) - { - var curVal = userGpuPrefs.GetValue(imagePath) as string; - if (curVal?.Contains("GpuPreference=2") ?? false) - return true; - } - - userGpuPrefs.SetValue(imagePath, "GpuPreference=2;"); - return false; + var profile = userGpuPrefs.GetValueNames().Any(v => v == imagePath); + if (profile) + { + var curVal = userGpuPrefs.GetValue(imagePath) as string; + if (curVal?.Contains("GpuPreference=2") ?? false) + return true; } + + userGpuPrefs.SetValue(imagePath, "GpuPreference=2;"); + return false; } } \ No newline at end of file diff --git a/VkDiag/Program.VulkanMetaInfo.cs b/VkDiag/Program.VulkanMetaInfo.cs index 44638fa..770e792 100644 --- a/VkDiag/Program.VulkanMetaInfo.cs +++ b/VkDiag/Program.VulkanMetaInfo.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Text; using System.Text.Json; using Microsoft.Win32; @@ -12,13 +11,14 @@ namespace VkDiag; internal static partial class Program { - private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions + private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNamingPolicy = new SnakeCasePolicy(), WriteIndented = true, }; - private static readonly Dictionary KnownProblematicLayers = new Dictionary + // ReSharper disable StringLiteralTypo + private static readonly Dictionary KnownProblematicLayers = new() { ["MirillisActionVulkanLayer.json"] = null, ["ow-vulkan-overlay64.json"] = null, @@ -30,11 +30,12 @@ internal static partial class Program ["playclawvk32.json"] = null, ["VK_LAYER_FCAT_DT_overlay_JSON_x64.json"] = null, ["VK_LAYER_FCAT_DT_overlay_JSON_x86.json"] = null, - ["bdcamvk64.json"] = new Version(1, 1, 0, 111), - ["bdcamvk32.json"] = new Version(1, 1, 0, 111), - ["obs-vulkan64.json"] = new Version(1, 2, 2, 0), - ["obs-vulkan32.json"] = new Version(1, 2, 2, 0), + ["bdcamvk64.json"] = new(1, 1, 0, 111), + ["bdcamvk32.json"] = new(1, 1, 0, 111), + ["obs-vulkan64.json"] = new(1, 2, 2, 0), + ["obs-vulkan32.json"] = new(1, 2, 2, 0), }; + // ReSharper restore StringLiteralTypo private static void CheckVulkanMeta() { @@ -45,56 +46,56 @@ private static void CheckVulkanMeta() var removedBroken = true; clear &= hasProperVulkanDrivers; foreach (var basePath in basePaths) - using (var driversKey = Registry.LocalMachine.OpenSubKey(Path.Combine(basePath, "Drivers"), autofix || clear)) - { - if (driversKey == null) - continue; + { + using var driversKey = Registry.LocalMachine.OpenSubKey(Path.Combine(basePath, "Drivers"), autofix || clear); + if (driversKey == null) + continue; - var entries = driversKey.GetValueNames(); - foreach (var driverPath in entries) + var entries = driversKey.GetValueNames(); + foreach (var driverPath in entries) + { + if (File.Exists(driverPath)) { - if (File.Exists(driverPath)) + hasExplicitDriverReg = true; + if (clear) { - hasExplicitDriverReg = true; - if (clear) + RestartIfNotElevated(); + try { - RestartIfNotElevated(); - try - { - driversKey.DeleteValue(driverPath); - } - catch - { - removedExplicitDriverReg = false; + driversKey.DeleteValue(driverPath); + } + catch + { + removedExplicitDriverReg = false; #if DEBUG WriteLogLine(ConsoleColor.Red, "x", $"Failed to fix {driversKey} @{driverPath}"); #endif - } } } - else + } + else + { + hasBrokenEntries = broken = true; + if (autofix) { - hasBrokenEntries = broken = true; - if (autofix) + RestartIfNotElevated(); + try { - RestartIfNotElevated(); - try - { - driversKey.DeleteValue(driverPath); - } - catch - { - fixedEverything = removedBroken = false; + driversKey.DeleteValue(driverPath); + } + catch + { + fixedEverything = removedBroken = false; #if DEBUG WriteLogLine(ConsoleColor.Red, "x", $"Failed to fix {driversKey} @{driverPath}"); #endif - } } - else - fixedEverything = removedBroken = false; } + else + fixedEverything = removedBroken = false; } } + } if ((!hasExplicitDriverReg || removedExplicitDriverReg) && (!broken || removedBroken)) @@ -143,7 +144,7 @@ private static void CheckVulkanMeta() var isEnabled = ((int?)layerKey.GetValue(layerPath)) == 0; var isConflicting = false; - bool disableLayer(string path) + bool DisableLayer(string path) { hasConflictingLayers = conflicts = true; if (disableLayers) @@ -204,7 +205,7 @@ bool disableLayer(string path) if (KnownProblematicLayers.TryGetValue(layerJsonName, out var minLayerVersion) && (layerInfo.dllVer == null || minLayerVersion == null || layerInfo.dllVer < minLayerVersion)) { - isEnabled = !disableLayer(layerPath); + isEnabled = !DisableLayer(layerPath); isConflicting = true; } else @@ -212,8 +213,8 @@ bool disableLayer(string path) var idx = -1; for (var i = 0; i < layerInfoList.Count; i++) { - var l = layerInfoList[i]; - if (!l.broken && l.enabled && Path.GetFileName(l.path).Equals(layerJsonName, StringComparison.OrdinalIgnoreCase)) + if (layerInfoList[i] is { broken: false, enabled: true, path: {Length: >0} path } + && Path.GetFileName(path).Equals(layerJsonName, StringComparison.OrdinalIgnoreCase)) { idx = i; break; @@ -226,10 +227,9 @@ bool disableLayer(string path) #endif var dupLayer = layerInfoList[idx]; var dupLayerInfo = GetLayerInfo(dupLayer.path)[0]; - var curIsNewer = true; var defVer = new Version(0, 0); - curIsNewer = (layerInfo.dllVer ?? defVer) > (dupLayerInfo.dllVer ?? defVer) + var curIsNewer = (layerInfo.dllVer ?? defVer) > (dupLayerInfo.dllVer ?? defVer) || (layerInfo.apiVer ?? defVer) > (dupLayerInfo.apiVer ?? defVer); if ((layerInfo.apiVer == null || dupLayerInfo.apiVer == null) && (layerInfo.dllVer == null || dupLayerInfo.dllVer == null)) @@ -241,7 +241,7 @@ bool disableLayer(string path) #if DEBUG WriteLogLine(ConsoleColor.Cyan, "i", $" Disabling older layer {layerJsonName}, v{dupLayerInfo.dllVer}, api v{dupLayerInfo.apiVer}"); #endif - if (disableLayer(dupLayer.path)) + if (DisableLayer(dupLayer.path)) layerInfoList[idx] = (dupLayer.path, false, true, true); } else @@ -249,7 +249,7 @@ bool disableLayer(string path) #if DEBUG WriteLogLine(ConsoleColor.Cyan, "i", $" Disabling current layer {layerJsonName}, v{dupLayerInfo.dllVer}, api v{dupLayerInfo.apiVer}"); #endif - isEnabled = !disableLayer(layerPath); + isEnabled = !DisableLayer(layerPath); isConflicting = true; } } @@ -284,10 +284,9 @@ bool disableLayer(string path) if (isBroken) { status = "x"; - if (layer == "Implicit") - color = ConsoleColor.Red; - else - color = ConsoleColor.DarkYellow; + color = layer is "Implicit" + ? ConsoleColor.Red + : ConsoleColor.DarkYellow; } else if (isConflicting) { @@ -324,7 +323,7 @@ bool disableLayer(string path) return defaultResult; var regInfo = JsonSerializer.Deserialize(layerContent, JsonOptions); - var layers = regInfo?.Layers ?? new List(); + var layers = regInfo?.Layers ?? []; if (regInfo?.Layer != null) layers.Add(regInfo.Layer); if (layers.Count == 0) @@ -364,7 +363,7 @@ bool disableLayer(string path) #if DEBUG WriteLogLine(ConsoleColor.Red, "x", e.ToString()); #endif - return new List<(string title, Version dllVer, Version apiVer)> { (layerFilename, libDllVer, apiVer) }; + return [(layerFilename, libDllVer, apiVer)]; } } } \ No newline at end of file diff --git a/VkDiag/Program.cs b/VkDiag/Program.cs index 5ec666e..9e11131 100644 --- a/VkDiag/Program.cs +++ b/VkDiag/Program.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Linq; using System.Net.Http; -using System.Net.Http.Headers; using System.Security.Principal; using System.Text; using System.Text.Json; @@ -17,17 +16,17 @@ internal static partial class Program { private const string VkDiagVersion = "1.3.2"; - private static bool isAdmin = false; - private static bool autofix = false; - private static bool clear = false; - private static bool disableLayers = false; - private static bool ignoreHighPerfCheck = false; + private static bool isAdmin; + private static bool autofix; + private static bool clear; + private static bool disableLayers; + private static bool ignoreHighPerfCheck; private static bool everythingIsFine = true; - private static bool hasBrokenEntries = false; - private static bool hasProperVulkanDrivers = false; - private static bool hasExplicitDriverReg = false; - private static bool hasConflictingLayers = false; + private static bool hasBrokenEntries; + private static bool hasProperVulkanDrivers; + private static bool hasExplicitDriverReg; + private static bool hasConflictingLayers; private static bool disabledConflictingLayers = true; private static bool removedExplicitDriverReg = true; private static bool fixedEverything = true; @@ -88,37 +87,35 @@ private static async Task CheckVkDiagVersionAsync() { try { - using (var client = new HttpClient()) + using var client = new HttpClient(); + var curVerParts = VkDiagVersion.Split([' ', '-'], 2); + client.DefaultRequestHeaders.UserAgent.Add(new("vkdiag", curVerParts[0])); + var responseJson = await client.GetStringAsync("https://api.github.com/repos/13xforever/vkdiag/releases").ConfigureAwait(false); + var releaseList = JsonSerializer.Deserialize>(responseJson, JsonOptions); + releaseList = releaseList?.OrderByDescending(r => Version.TryParse(r.TagName.TrimStart('v'), out var v) ? v : null).ToList(); + var latest = releaseList?.FirstOrDefault(r => !r.Prerelease); + var latestBeta = releaseList?.FirstOrDefault(r => r.Prerelease); + Version.TryParse(curVerParts[0], out var curVer); + Version.TryParse(latest?.TagName.TrimStart('v') ?? "0", out var latestVer); + var latestBetaParts = latestBeta?.TagName.Split([' ', '-'], 2); + Version.TryParse(latestBetaParts?[0] ?? "0", out var latestBetaVer); + if (latestVer > curVer || latestVer == curVer && curVerParts.Length > 1) { - var curVerParts = VkDiagVersion.Split(new[] {' ', '-'}, 2); - client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("vkdiag", curVerParts[0])); - var responseJson = await client.GetStringAsync("https://api.github.com/repos/13xforever/vkdiag/releases").ConfigureAwait(false); - var releaseList = JsonSerializer.Deserialize>(responseJson, JsonOptions); - releaseList = releaseList?.OrderByDescending(r => Version.TryParse(r.TagName.TrimStart('v'), out var v) ? v : null).ToList(); - var latest = releaseList?.FirstOrDefault(r => !r.Prerelease); - var latestBeta = releaseList?.FirstOrDefault(r => r.Prerelease); - Version.TryParse(curVerParts[0], out var curVer); - Version.TryParse(latest?.TagName.TrimStart('v') ?? "0", out var latestVer); - var latestBetaParts = latestBeta?.TagName.Split(new[] {' ', '-'}, 2); - Version.TryParse(latestBetaParts?[0] ?? "0", out var latestBetaVer); - if (latestVer > curVer || latestVer == curVer && curVerParts.Length > 1) - { - WriteLogLine(ConsoleColor.DarkYellow, "!", "VkDiag version: " + VkDiagVersion); - WriteLogLine(ConsoleColor.DarkYellow, "!", $" Newer version available: {latestVer}"); - } - else - WriteLogLine(ConsoleColor.Green, "+", "VkDiag version: " + VkDiagVersion); - if (latestBetaVer > latestVer - || (latestVer == latestBetaVer - && curVerParts.Length > 1 - && (latestBetaParts?.Length > 1 && latestBetaParts[1] != curVerParts[1] - || (latestBetaParts?.Length ?? 0) == 0))) - WriteLogLine(defaultFgColor, "+", $" Newer prerelease version available: {latestBetaVer}"); + WriteLogLine(ConsoleColor.DarkYellow, "!", "VkDiag version: " + VkDiagVersion); + WriteLogLine(ConsoleColor.DarkYellow, "!", $" Newer version available: {latestVer}"); } + else + WriteLogLine(ConsoleColor.Green, "+", "VkDiag version: " + VkDiagVersion); + if (latestBetaVer > latestVer + || (latestVer == latestBetaVer + && curVerParts.Length > 1 + && (latestBetaParts?.Length > 1 && latestBetaParts[1] != curVerParts[1] + || (latestBetaParts?.Length ?? 0) == 0))) + WriteLogLine(DefaultFgColor, "+", $" Newer prerelease version available: {latestBetaVer}"); } catch { - WriteLogLine(defaultFgColor, "+", "VkDiag version: " + VkDiagVersion); + WriteLogLine(DefaultFgColor, "+", "VkDiag version: " + VkDiagVersion); WriteLogLine(ConsoleColor.DarkYellow, "!", $" Failed to check for updates"); } } @@ -142,7 +139,7 @@ private static void GetOptions(string[] args) WriteLogLine("Usage:"); WriteLogLine(" vkdiag [OPTIONS]"); WriteLogLine("Available options:"); - lock (theDoor) options.WriteOptionDescriptions(Console.Out); + lock (TheDoor) options.WriteOptionDescriptions(Console.Out); Environment.Exit(0); } } @@ -212,7 +209,7 @@ private static void ShowMenu() WriteLogLine(ConsoleColor.Cyan, key.ToString(), prompt); validResponses.Add(key); } - lock (theDoor) Console.Write("Selected option: "); + lock (TheDoor) Console.Write("Selected option: "); char result; do {