From 69773439064fe11eb104a63198f989812e860a93 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 1 Aug 2016 17:23:40 +0200 Subject: [PATCH] Refactoring --- ArchiSteamFarm/Program.cs | 2 +- ArchiSteamFarm/Runtime.cs | 99 ++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index e60aaec3b..d189961ce 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -488,7 +488,7 @@ namespace ArchiSteamFarm { Logging.InitCoreLoggers(); Logging.LogGenericInfo("ASF V" + Version); - if (!Runtime.IsRuntimeSupported) { + if (!Runtime.IsRuntimeSupported()) { Logging.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); Thread.Sleep(10000); } diff --git a/ArchiSteamFarm/Runtime.cs b/ArchiSteamFarm/Runtime.cs index d629b4d87..c5d6066c3 100644 --- a/ArchiSteamFarm/Runtime.cs +++ b/ArchiSteamFarm/Runtime.cs @@ -55,61 +55,40 @@ namespace ArchiSteamFarm { } } - internal static bool IsRuntimeSupported { - get { - if (IsRunningOnMono) { - Version monoVersion = GetMonoVersion(); - if (monoVersion == null) { - Logging.LogNullError(nameof(monoVersion)); - return false; - } - - Version minMonoVersion = new Version(4, 4); - - if (monoVersion >= minMonoVersion) { - Logging.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); - return true; - } - - Logging.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + internal static bool IsRuntimeSupported() { + if (IsRunningOnMono) { + Version monoVersion = GetMonoVersion(); + if (monoVersion == null) { + Logging.LogNullError(nameof(monoVersion)); return false; } - using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) { - if (registryKey == null) { - Logging.LogNullError(nameof(registryKey)); - return false; - } + Version minMonoVersion = new Version(4, 4); - object releaseObj = registryKey.GetValue("Release"); - if (releaseObj == null) { - Logging.LogNullError(nameof(releaseObj)); - return false; - } - - int release = (int) releaseObj; - if (release <= 0) { - Logging.LogNullError(nameof(release)); - return false; - } - - Version netVersion = ParseNetRelease(release); - if (netVersion == null) { - Logging.LogNullError(nameof(netVersion)); - return false; - } - - Version minNetVersion = new Version(4, 6); - - if (netVersion >= minNetVersion) { - Logging.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); - return true; - } - - Logging.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); - return false; + if (monoVersion >= minMonoVersion) { + Logging.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); + return true; } + + Logging.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + return false; } + + Version netVersion = GetNetVersion(); + if (netVersion == null) { + Logging.LogNullError(nameof(netVersion)); + return false; + } + + Version minNetVersion = new Version(4, 6); + + if (netVersion >= minNetVersion) { + Logging.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); + return true; + } + + Logging.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); + return false; } // TODO: Remove me once Mono 4.6 is released @@ -137,10 +116,24 @@ namespace ArchiSteamFarm { } } - private static Version ParseNetRelease(int release) { - if (release <= 0) { - Logging.LogNullError(nameof(release)); - return null; + private static Version GetNetVersion() { + uint release; + using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) { + if (registryKey == null) { + Logging.LogNullError(nameof(registryKey)); + return null; + } + + object releaseObj = registryKey.GetValue("Release"); + if (releaseObj == null) { + Logging.LogNullError(nameof(releaseObj)); + return null; + } + + if (!uint.TryParse(releaseObj.ToString(), out release) || (release == 0)) { + Logging.LogNullError(nameof(release)); + return null; + } } if (release >= 394747) {