Skip to content

Commit

Permalink
update code style and fix some minor compiler complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
13xforever committed Mar 3, 2024
1 parent 1f187ad commit 87b73b0
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 321 deletions.
5 changes: 5 additions & 0 deletions VkDiag.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Khronos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prefs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=RPCS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vkdiag/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 0 additions & 2 deletions VkDiag/Interop/PackageManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions VkDiag/Program.AppxPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
317 changes: 159 additions & 158 deletions VkDiag/Program.GpuDriverInfo.cs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions VkDiag/Program.Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
}
}
121 changes: 59 additions & 62 deletions VkDiag/Program.OsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace VkDiag;

internal static partial class Program
{
private static readonly Dictionary<string, Version> VulkanLoaderExpectedVersions = new Dictionary<string, Version>
private static readonly Dictionary<string, Version> VulkanLoaderExpectedVersions = new()
{
["1"] = new Version(1, 2, 141, 0),
["1"] = new(1, 2, 141, 0),
};

private static Version CheckOs()
Expand All @@ -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);
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit 87b73b0

Please sign in to comment.