fixes for showing AMD driver versions

This commit is contained in:
13xforever 2018-09-08 15:35:36 +05:00 committed by Roberto Anić Banić
parent 4839792879
commit 672d36f1d4
2 changed files with 46 additions and 6 deletions

View File

@ -48,14 +48,43 @@ namespace CompatBot.Database.Providers
} }
} }
public static string GetFromOpengl(string openglVersion) public static async Task<string> GetFromOpenglAsync(string openglVersion, bool autoRefresh = true)
{ {
if (OpenglToDriver.TryGetValue(openglVersion, out var result) && result != null) if (OpenglToDriver.TryGetValue(openglVersion, out var result) && result != null)
return result; return result;
if (Version.TryParse(openglVersion, out var glVersion))
{
var glVersions = new List<(Version v, string vv)>(OpenglToDriver.Count);
foreach (var key in OpenglToDriver.Keys)
{
if (Version.TryParse(key, out var ver))
glVersions.Add((ver, OpenglToDriver[key]));
}
if (glVersions.Count == 0)
return openglVersion;
glVersions.Sort((l, r) => l.v < r.v ? -1 : l.v > r.v ? 1 : 0);
if (glVersion < glVersions[0].v)
return $"older than {glVersions[0].vv} ({openglVersion})";
var newest = glVersions.Last();
if (glVersion > newest.v)
{
if (autoRefresh)
{
await RefreshAsync().ConfigureAwait(false);
return await GetFromOpenglAsync(openglVersion, false).ConfigureAwait(false);
}
return $"newer than {newest.vv} ({openglVersion})";
}
}
return openglVersion; return openglVersion;
} }
public static async Task<string> GetFromVulkanAsync(string vulkanVersion) public static async Task<string> GetFromVulkanAsync(string vulkanVersion, bool autoRefresh = true)
{ {
if (!VulkanToDriver.TryGetValue(vulkanVersion, out var result)) if (!VulkanToDriver.TryGetValue(vulkanVersion, out var result))
await RefreshAsync().ConfigureAwait(false); await RefreshAsync().ConfigureAwait(false);
@ -80,11 +109,19 @@ namespace CompatBot.Database.Providers
vkVersions.Sort((l, r) => l.v < r.v ? -1 : l.v > r.v ? 1 : 0); vkVersions.Sort((l, r) => l.v < r.v ? -1 : l.v > r.v ? 1 : 0);
if (vkVer < vkVersions[0].v) if (vkVer < vkVersions[0].v)
return $"older than {vkVersions[0].vv}"; return $"older than {vkVersions[0].vv} ({vulkanVersion})";
var newest = vkVersions.Last(); var newest = vkVersions.Last();
if (vkVer > newest.v) if (vkVer > newest.v)
return $"newer than {newest.vv}"; {
if (autoRefresh)
{
await RefreshAsync().ConfigureAwait(false);
return await GetFromVulkanAsync(vulkanVersion, false).ConfigureAwait(false);
}
return $"newer than {newest.vv} ({vulkanVersion})";
}
} }
return vulkanVersion; return vulkanVersion;

View File

@ -298,7 +298,7 @@ namespace CompatBot.Utils.ResultFormatters
return null; return null;
if (gpuInfo.Contains("AMD", StringComparison.InvariantCultureIgnoreCase)) if (gpuInfo.Contains("AMD", StringComparison.InvariantCultureIgnoreCase))
return AmdDriverVersionProvider.GetFromOpengl(version); return AmdDriverVersionProvider.GetFromOpenglAsync(version).GetAwaiter().GetResult();
return version; return version;
} }
@ -313,7 +313,10 @@ namespace CompatBot.Utils.ResultFormatters
where m.Success where m.Success
select m select m
).FirstOrDefault(m => m.Groups["device_name"].Value == gpu); ).FirstOrDefault(m => m.Groups["device_name"].Value == gpu);
return info?.Groups["version"].Value; var result = info?.Groups["version"].Value;
if (gpu.Contains("AMD", StringComparison.InvariantCultureIgnoreCase))
return AmdDriverVersionProvider.GetFromVulkanAsync(result).GetAwaiter().GetResult();
return result;
} }
private static string GetVulkanDriverVersionRaw(string gpuInfo, string version) private static string GetVulkanDriverVersionRaw(string gpuInfo, string version)