diff --git a/Core/Main/PTMagic.cs b/Core/Main/PTMagic.cs index 1270cd0..7ed366f 100644 --- a/Core/Main/PTMagic.cs +++ b/Core/Main/PTMagic.cs @@ -59,6 +59,7 @@ namespace Core.Main private Dictionary _singleMarketSettingsCount = new Dictionary(); Dictionary> _triggeredSingleMarketSettings = new Dictionary>(); private static volatile object _lockObj = new object(); + private Mutex mutex = new Mutex(false, "analyzerStateMutex"); public LogHelper Log { @@ -122,6 +123,22 @@ namespace Core.Main _state = value; } } + public void WriteStateToFile() + { + try + { + mutex.WaitOne(); // Acquire the mutex + + string filePath = "_data/AnalyzerState."; + File.WriteAllText(filePath, this.State.ToString()); + + } + finally + { + mutex.ReleaseMutex(); // Release the mutex even if exceptions occur + } + } + public int RunCount { @@ -840,6 +857,7 @@ namespace Core.Main { // Change state to "Running" this.State = Constants.PTMagicBotState_Running; + this.WriteStateToFile(); this.RunCount++; this.LastRuntime = DateTime.UtcNow; @@ -975,6 +993,7 @@ namespace Core.Main // Change state to Finished / Stopped this.State = Constants.PTMagicBotState_Idle; + this.WriteStateToFile(); } } } @@ -991,6 +1010,7 @@ namespace Core.Main { Log.DoLogWarn("PTMagic raid " + this.RunCount.ToString() + " is taking longer than expected. Consider increasing your IntervalMinues setting, reducing other processes on your PC, or raising PTMagic's priority."); this.State = Constants.PTMagicBotState_Idle; + this.WriteStateToFile(); Log.DoLogInfo("PTMagic status reset, waiting for the next raid to be good to go again."); } } @@ -998,6 +1018,7 @@ namespace Core.Main { Log.DoLogWarn("No LastRuntimeSummary.json found after raid " + this.RunCount.ToString() + ", trying to reset PT Magic status..."); this.State = Constants.PTMagicBotState_Idle; + this.WriteStateToFile(); Log.DoLogInfo("PTMagic status reset, waiting for the next raid to be good to go again."); } } diff --git a/Monitor/Pages/Index.cshtml b/Monitor/Pages/Index.cshtml index 25b691c..901f19f 100644 --- a/Monitor/Pages/Index.cshtml +++ b/Monitor/Pages/Index.cshtml @@ -25,7 +25,8 @@ +