From d395531706b3ad92fbc2246ef6a041faf2a3ad6a Mon Sep 17 00:00:00 2001 From: Julien Moes <35890427+Mrproex@users.noreply.github.com> Date: Mon, 23 Dec 2019 01:44:07 +0100 Subject: [PATCH 1/2] Automation of the detection system for vcredist. The solution has been tested on my own project. The execution time of the function varies between 0 and 1ms. --- src/Alturos.Yolo/YoloWrapper.cs | 52 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Alturos.Yolo/YoloWrapper.cs b/src/Alturos.Yolo/YoloWrapper.cs index b4ae522..ac70861 100644 --- a/src/Alturos.Yolo/YoloWrapper.cs +++ b/src/Alturos.Yolo/YoloWrapper.cs @@ -153,37 +153,41 @@ private bool IsMicrosoftVisualCPlusPlus2017Available() { //Detect if Visual C++ Redistributable for Visual Studio is installed //https://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed/ - var checkKeys = new Dictionary - { - { @"Installer\Dependencies\,,amd64,14.0,bundle", "Microsoft Visual C++ 2017 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.16,bundle", "Microsoft Visual C++ 2017 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.20,bundle", "Microsoft Visual C++ 2015-2019 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.21,bundle", "Microsoft Visual C++ 2015-2019 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.22,bundle", "Microsoft Visual C++ 2015-2019 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.23,bundle", "Microsoft Visual C++ 2015-2019 Redistributable (x64)" }, - { @"Installer\Dependencies\VC,redist.x64,amd64,14.24,bundle", "Microsoft Visual C++ 2015-2019 Redistributable (x64)" }, - }; - foreach (var checkKey in checkKeys) + //Check New Versions + var newVerMinVer = 14.16; //Minimal VCRedist version to check + var newVerMaxVer = 14.30; //Maximal VCRedist version to check (Use a bigger value than the actual true last version in order to prevent update) + + string newVerMinVerStr = null; + + var index = 0; + //We dont need to check the key value because each version of VCResdist C++ is unique. + while (newVerMinVer < newVerMaxVer) { - using (var registryKey = Registry.ClassesRoot.OpenSubKey(checkKey.Key, false)) - { - if (registryKey == null) - { - continue; - } + if (newVerMinVer.ToString().Length == 4) + newVerMinVerStr = newVerMinVer.ToString() + "0"; + else + newVerMinVerStr = newVerMinVer.ToString(); - var displayName = registryKey.GetValue("DisplayName") as string; - if (string.IsNullOrEmpty(displayName)) - { - continue; - } + string[] key = + { + @"Installer\Dependencies\,,amd64,14.0,bundle", //Specific key name, no need to change the version. + @"Installer\Dependencies\VC,redist.x64,amd64," + newVerMinVerStr.Replace(",", ".") + ",bundle", + }; - if (displayName.StartsWith(checkKey.Value, StringComparison.OrdinalIgnoreCase)) + while (index < key.Length) + { + using (var registryKey = Registry.ClassesRoot.OpenSubKey(key[index], false)) { - return true; + if (registryKey != null) + { + return true; + } } + index++; } + index = 0; + newVerMinVer += 0.01; } return false; From 2895dd40a195e17d2e0479d860e879147ce6946a Mon Sep 17 00:00:00 2001 From: Julien Moes <35890427+Mrproex@users.noreply.github.com> Date: Mon, 23 Dec 2019 16:03:39 +0100 Subject: [PATCH 2/2] Detection. Improved detection with a view to making it more automatic --- src/Alturos.Yolo/YoloWrapper.cs | 47 +++++++++++---------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/Alturos.Yolo/YoloWrapper.cs b/src/Alturos.Yolo/YoloWrapper.cs index ac70861..acde663 100644 --- a/src/Alturos.Yolo/YoloWrapper.cs +++ b/src/Alturos.Yolo/YoloWrapper.cs @@ -151,46 +151,31 @@ private void Initialize(string configurationFilename, string weightsFilename, st private bool IsMicrosoftVisualCPlusPlus2017Available() { - //Detect if Visual C++ Redistributable for Visual Studio is installed - //https://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed/ - - //Check New Versions - var newVerMinVer = 14.16; //Minimal VCRedist version to check - var newVerMaxVer = 14.30; //Maximal VCRedist version to check (Use a bigger value than the actual true last version in order to prevent update) - - string newVerMinVerStr = null; - - var index = 0; - //We dont need to check the key value because each version of VCResdist C++ is unique. - while (newVerMinVer < newVerMaxVer) + var index = 14; //Oldest version of VCRedist C++ working with Yolo + while (true) { - if (newVerMinVer.ToString().Length == 4) - newVerMinVerStr = newVerMinVer.ToString() + "0"; - else - newVerMinVerStr = newVerMinVer.ToString(); - - string[] key = + if (GetRegKey(index) != null) { - @"Installer\Dependencies\,,amd64,14.0,bundle", //Specific key name, no need to change the version. - @"Installer\Dependencies\VC,redist.x64,amd64," + newVerMinVerStr.Replace(",", ".") + ",bundle", - }; - - while (index < key.Length) - { - using (var registryKey = Registry.ClassesRoot.OpenSubKey(key[index], false)) + if (GetRegKey(index).GetValue("Installed").ToString() == "1") + { + return true; + } + else { - if (registryKey != null) + if (GetRegKey(index + 1) == null) { - return true; + return false; } } - index++; } - index = 0; - newVerMinVer += 0.01; + index++; } + } - return false; + private RegistryKey GetRegKey(int index) + { + RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\VisualStudio\" + index + @".0\VC\Runtimes\x64", false); + return registryKey; } private EnvironmentReport GetEnvironmentReport()