Refactoring

This commit is contained in:
JustArchi
2016-08-01 17:23:40 +02:00
parent 3934a3fdbc
commit 6977343906
2 changed files with 47 additions and 54 deletions

View File

@@ -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);
}

View File

@@ -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) {