Disgusting fix for broken Mono

This commit is contained in:
JustArchi
2016-06-10 20:51:10 +02:00
parent bb05f4c67a
commit 4e22d7fcd1
3 changed files with 57 additions and 0 deletions

View File

@@ -109,6 +109,7 @@
<Compile Include="JSON\GitHub.cs" />
<Compile Include="JSON\Steam.cs" />
<Compile Include="Logging.cs" />
<Compile Include="Mono.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Trading.cs" />

View File

@@ -159,6 +159,11 @@ namespace ArchiSteamFarm {
globalConfig.FarmingDelay = DefaultFarmingDelay;
}
if ((globalConfig.FarmingDelay > 5) && Mono.RequiresWorkaroundForBug41701()) {
Logging.LogGenericWarning("Your Mono runtime is affected by bug 41701, FarmingDelay of " + globalConfig.FarmingDelay + " is not possible - value of 5 will be used instead");
globalConfig.FarmingDelay = 5;
}
if (globalConfig.HttpTimeout == 0) {
Logging.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout + ". Value of " + DefaultHttpTimeout + " will be used instead");
globalConfig.HttpTimeout = DefaultHttpTimeout;

51
ArchiSteamFarm/Mono.cs Normal file
View File

@@ -0,0 +1,51 @@
using System;
using System.Reflection;
namespace ArchiSteamFarm {
internal static class Mono {
internal static bool RequiresWorkaroundForBug41701() {
// https://bugzilla.xamarin.com/show_bug.cgi?id=41701
Version version = GetMonoVersion();
if (version == null) {
return false;
}
return version >= new Version(4, 4);
}
private static Version GetMonoVersion() {
Type type = Type.GetType("Mono.Runtime");
if (type == null) {
return null; // OK, not Mono
}
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName == null) {
Logging.LogNullError(nameof(displayName));
return null;
}
string versionString = (string) displayName.Invoke(null, null);
if (string.IsNullOrEmpty(versionString)) {
Logging.LogNullError(nameof(versionString));
return null;
}
int index = versionString.IndexOf(' ');
if (index <= 0) {
Logging.LogNullError(nameof(index));
return null;
}
versionString = versionString.Substring(0, index);
Version version;
if (Version.TryParse(versionString, out version)) {
return version;
}
Logging.LogNullError(nameof(version));
return null;
}
}
}