Work work

This commit is contained in:
JustArchi
2016-08-02 22:51:09 +02:00
parent 6bd161359f
commit 4481fb3a86
10 changed files with 68 additions and 64 deletions

View File

@@ -352,7 +352,7 @@ namespace ArchiSteamFarm {
SteamClient.Disconnect();
}
Program.OnBotShutdown();
Events.OnBotShutdown();
}
internal void OnFarmingStopped() => ResetGamesPlayed();

View File

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

View File

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

View File

@@ -55,7 +55,13 @@ namespace ArchiSteamFarm {
}
}
internal static bool IsRuntimeSupported() {
private static bool? _IsRuntimeSupported;
internal static bool IsRuntimeSupported {
get {
if (_IsRuntimeSupported.HasValue) {
return _IsRuntimeSupported.Value;
}
if (IsRunningOnMono) {
Version monoVersion = GetMonoVersion();
if (monoVersion == null) {
@@ -67,10 +73,12 @@ namespace ArchiSteamFarm {
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;
}
@@ -84,12 +92,15 @@ namespace ArchiSteamFarm {
if (netVersion >= minNetVersion) {
Logging.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion);
_IsRuntimeSupported = true;
return true;
}
Logging.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion);
_IsRuntimeSupported = false;
return false;
}
}
// TODO: Remove me once Mono 4.6 is released
internal static bool RequiresWorkaroundForMonoBug41701() {

View File

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

View File

@@ -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";

View File

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

View File

@@ -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";

View File

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