diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 395c52959..7ec09bd6a 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -352,7 +352,7 @@ namespace ArchiSteamFarm { SteamClient.Disconnect(); } - Program.OnBotShutdown(); + Events.OnBotShutdown(); } internal void OnFarmingStopped() => ResetGamesPlayed(); diff --git a/ArchiSteamFarm/Events.cs b/ArchiSteamFarm/Events.cs index ede6d1cac..dc84442eb 100644 --- a/ArchiSteamFarm/Events.cs +++ b/ArchiSteamFarm/Events.cs @@ -1,7 +1,19 @@ -using SteamKit2; +using System.Linq; +using System.Threading.Tasks; +using SteamKit2; namespace ArchiSteamFarm { internal static class Events { + internal static void OnBotShutdown() { + if (Program.ShutdownSequenceInitialized || Program.WCF.IsServerRunning() || Bot.Bots.Values.Any(bot => bot.KeepRunning)) { + return; + } + + Logging.LogGenericInfo("No bots are running, exiting"); + Task.Delay(5000).Wait(); + Program.Shutdown(); + } + internal static void OnStateUpdated(Bot bot, SteamFriends.PersonaStateCallback callback) { } } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 1128c22df..aa62f7fb5 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -43,16 +43,17 @@ namespace ArchiSteamFarm { Server // Normal + WCF server } + internal static readonly WCF WCF = new WCF(); + private static readonly object ConsoleLock = new object(); private static readonly ManualResetEventSlim ShutdownResetEvent = new ManualResetEventSlim(false); - private static readonly WCF WCF = new WCF(); internal static bool IsRunningAsService { get; private set; } + internal static bool ShutdownSequenceInitialized { get; private set; } internal static GlobalConfig GlobalConfig { get; private set; } internal static GlobalDatabase GlobalDatabase { get; private set; } internal static WebBrowser WebBrowser { get; private set; } - private static bool ShutdownSequenceInitialized; private static EMode Mode = EMode.Normal; internal static void Exit(byte exitCode = 0) { @@ -134,25 +135,7 @@ namespace ArchiSteamFarm { return !string.IsNullOrEmpty(result) ? result.Trim() : null; } - internal static void OnBotShutdown() { - if (ShutdownSequenceInitialized) { - return; - } - - if (Bot.Bots.Values.Any(bot => bot.KeepRunning)) { - return; - } - - if (WCF.IsServerRunning()) { - return; - } - - Logging.LogGenericInfo("No bots are running, exiting"); - Thread.Sleep(5000); - ShutdownResetEvent.Set(); - } - - private static void Shutdown() { + internal static void Shutdown() { if (!InitShutdownSequence()) { return; } @@ -286,7 +269,7 @@ namespace ArchiSteamFarm { Logging.InitCoreLoggers(); Logging.LogGenericInfo("ASF V" + SharedInfo.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); } @@ -378,7 +361,7 @@ namespace ArchiSteamFarm { // Check if we got any bots running if (!isRunning) { - OnBotShutdown(); + Events.OnBotShutdown(); } } diff --git a/ArchiSteamFarm/Runtime.cs b/ArchiSteamFarm/Runtime.cs index c5d6066c3..cdf8297ce 100644 --- a/ArchiSteamFarm/Runtime.cs +++ b/ArchiSteamFarm/Runtime.cs @@ -55,40 +55,51 @@ namespace ArchiSteamFarm { } } - internal static bool IsRuntimeSupported() { - if (IsRunningOnMono) { - Version monoVersion = GetMonoVersion(); - if (monoVersion == null) { - Logging.LogNullError(nameof(monoVersion)); + private static bool? _IsRuntimeSupported; + internal static bool IsRuntimeSupported { + get { + if (_IsRuntimeSupported.HasValue) { + return _IsRuntimeSupported.Value; + } + + 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); + _IsRuntimeSupported = true; + return true; + } + + Logging.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + _IsRuntimeSupported = false; return false; } - Version minMonoVersion = new Version(4, 4); + Version netVersion = GetNetVersion(); + if (netVersion == null) { + Logging.LogNullError(nameof(netVersion)); + return false; + } - if (monoVersion >= minMonoVersion) { - Logging.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); + Version minNetVersion = new Version(4, 6); + + if (netVersion >= minNetVersion) { + Logging.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); + _IsRuntimeSupported = true; return true; } - Logging.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + Logging.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); + _IsRuntimeSupported = false; 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 diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 788e8f639..380f22867 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -60,7 +60,7 @@ namespace ArchiSteamFarm { // Therefore, call mono-incompatible options in their own function to avoid that, and just leave the function call here // When compiling on Mono, this section is omitted entirely as we never run Mono-compiled ASF on Windows // Moreover, Mono compiler doesn't even include ReusePort field in ServicePointManager, so it's crucial to avoid compilation error - if (!Runtime.IsRunningOnMono) { + if (Runtime.IsRuntimeSupported && !Runtime.IsRunningOnMono) { InitNonMonoBehaviour(); } #endif diff --git a/GUI/BotStatusForm.Designer.cs b/GUI/BotStatusForm.Designer.cs index 0daaf0862..707d05a69 100644 --- a/GUI/BotStatusForm.Designer.cs +++ b/GUI/BotStatusForm.Designer.cs @@ -47,6 +47,7 @@ this.AutoScroll = true; this.ClientSize = new System.Drawing.Size(651, 513); this.Controls.Add(this.AvatarPictureBox); + this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "BotStatusForm"; this.Text = "BotStatusForm"; diff --git a/GUI/Events.cs b/GUI/Events.cs index a63dbd80e..342bab6df 100644 --- a/GUI/Events.cs +++ b/GUI/Events.cs @@ -4,6 +4,8 @@ using SteamKit2; // ReSharper disable once CheckNamespace namespace ArchiSteamFarm { internal static class Events { + internal static void OnBotShutdown() { } + internal static void OnStateUpdated(Bot bot, SteamFriends.PersonaStateCallback callback) { if ((bot == null) || (callback == null)) { Logging.LogNullError(nameof(bot) + " || " + nameof(callback)); diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index 28bbccd4e..90f9d5bda 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -102,6 +102,7 @@ this.Controls.Add(this.LogTextBox); this.Controls.Add(this.BotListView); this.Controls.Add(this.menuStrip1); + this.DoubleBuffered = true; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.menuStrip1; this.Name = "MainForm"; diff --git a/GUI/Program.cs b/GUI/Program.cs index bccf1a0d3..47b0a8ea0 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -11,14 +11,12 @@ using GUI; // ReSharper disable once CheckNamespace namespace ArchiSteamFarm { internal static class Program { - internal static bool IsRunningAsService => false; - internal static GlobalConfig GlobalConfig { get; private set; } internal static GlobalDatabase GlobalDatabase { get; private set; } internal static WebBrowser WebBrowser { get; private set; } internal static string GetUserInput(SharedInfo.EUserInputType userInputType, string botName = SharedInfo.ASF, string extraInformation = null) { - return null; + return null; // TODO } internal static void Exit(int exitCode = 0) { @@ -38,10 +36,6 @@ namespace ArchiSteamFarm { Environment.Exit(0); } - internal static void OnBotShutdown() { - - } - internal static void InitShutdownSequence() { foreach (Bot bot in Bot.Bots.Values.Where(bot => bot.KeepRunning)) { bot.Stop(); @@ -95,7 +89,7 @@ namespace ArchiSteamFarm { Logging.InitCoreLoggers(); - 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!"); } diff --git a/GUI/Properties/AssemblyInfo.cs b/GUI/Properties/AssemblyInfo.cs index 40da6b374..831ac94e8 100644 --- a/GUI/Properties/AssemblyInfo.cs +++ b/GUI/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; using ArchiSteamFarm; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("GUI")] @@ -14,8 +14,8 @@ using ArchiSteamFarm; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] @@ -25,11 +25,11 @@ using ArchiSteamFarm; // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion(SharedInfo.VersionNumber)]