diff --git a/Code/OS/OSUtils.cs b/Code/OS/OSUtils.cs index 1fbb8de..25efc99 100644 --- a/Code/OS/OSUtils.cs +++ b/Code/OS/OSUtils.cs @@ -137,21 +137,28 @@ namespace Flowframes.OS } } - public static string GetOs() + public static string TryGetOs() { string info = ""; - using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")) + try { - ManagementObjectCollection information = searcher.Get(); - - if (information != null) + using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")) { - foreach (ManagementObject obj in information) - info = $"{obj["Caption"]} | {obj["OSArchitecture"]}"; - } + ManagementObjectCollection information = searcher.Get(); - info = info.Replace("NT 5.1.2600", "XP").Replace("NT 5.2.3790", "Server 2003"); + if (information != null) + { + foreach (ManagementObject obj in information) + info = $"{obj["Caption"]} | {obj["OSArchitecture"]}"; + } + + info = info.Replace("NT 5.1.2600", "XP").Replace("NT 5.2.3790", "Server 2003"); + } + } + catch (Exception e) + { + Logger.Log("TryGetOs Error: " + e.Message, true); } return info; diff --git a/Code/OS/StartupChecks.cs b/Code/OS/StartupChecks.cs index fed3032..f70a160 100644 --- a/Code/OS/StartupChecks.cs +++ b/Code/OS/StartupChecks.cs @@ -10,21 +10,32 @@ namespace Flowframes.OS { class StartupChecks { - static bool IsWin10 () + static bool IsWin10() { - string[] osInfo = OSUtils.GetOs().Split(" | "); + string osInfoStr = OSUtils.TryGetOs(); + + if (string.IsNullOrWhiteSpace(osInfoStr)) + return true; // If it fails, assume we are on Win10 + + string[] osInfo = osInfoStr.Split(" | "); string version = osInfo[0].Remove("Microsoft").Trim(); + return version.ToLower().Contains("windows 10"); } - static bool Is32Bit () + static bool Is32Bit() { - string[] osInfo = OSUtils.GetOs().Split(" | "); + string osInfoStr = OSUtils.TryGetOs(); + + if (string.IsNullOrWhiteSpace(osInfoStr)) + return false; // If it fails, assume we are on 64bit + + string[] osInfo = osInfoStr.Split(" | "); string arch = osInfo[1].Trim(); return arch.Contains("32"); } - public static void CheckOs () + public static void CheckOs() { if (!File.Exists(Paths.GetVerPath()) && Paths.GetExeDir().ToLower().Contains("temp")) { @@ -33,7 +44,7 @@ namespace Flowframes.OS Application.Exit(); } - string[] osInfo = OSUtils.GetOs().Split(" | "); + string[] osInfo = OSUtils.TryGetOs().Split(" | "); string version = osInfo[0].Remove("Microsoft").Trim(); if (Is32Bit() && !Config.GetBool("allow32Bit", false)) @@ -42,6 +53,9 @@ namespace Flowframes.OS Application.Exit(); } + if (string.IsNullOrWhiteSpace(version)) + return; + if (!version.ToLower().Contains("windows 10") && !Config.GetBool("ignoreIncompatibleOs", false)) { MessageBox.Show($"This application was made for Windows 10 and is not officially compatible with {version}.\n\n" + @@ -83,7 +97,7 @@ namespace Flowframes.OS { symlinksWorksNow = Symlinks.SymlinksAllowed(); - if(symlinksWorksNow) + if (symlinksWorksNow) break; await Task.Delay(500);