diff --git a/ViewModels/RecipeGeneratorViewModel.cs b/ViewModels/RecipeGeneratorViewModel.cs --- a/ViewModels/RecipeGeneratorViewModel.cs +++ b/ViewModels/RecipeGeneratorViewModel.cs @@ -90,7 +90,7 @@ namespace DesertPaintCodex.ViewModels private uint _minConcentration; private readonly ConcurrentQueue _pendingNewRecipes = new(); - private volatile int _newRecipeCount; + private ulong _newRecipeCount; private volatile bool _updatesAvailable; private readonly DispatcherTimer _updateTimer; @@ -155,6 +155,8 @@ namespace DesertPaintCodex.ViewModels _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt"); } + CanClear = false; + _generator.BeginRecipeGeneration( _minConcentration, (uint)MaxConcentration, @@ -201,6 +203,7 @@ namespace DesertPaintCodex.ViewModels _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt"); } + CanClear = false; _generator.ResumeRecipeGeneration(); } @@ -299,7 +302,7 @@ namespace DesertPaintCodex.ViewModels #region Event Handlers private void OnProgress(object? sender, EventArgs args) { - _newRecipeCount = (int)_generator.RecipeCount; + _newRecipeCount = _generator.RecipeCount; _updatesAvailable = true; } @@ -313,6 +316,7 @@ namespace DesertPaintCodex.ViewModels private void OnGeneratorStopped(object? sender, EventArgs args) { + Debug.WriteLine($"Generator stopped. Saving = {_saving}"); if (_saving) { SaveState(); @@ -346,7 +350,8 @@ namespace DesertPaintCodex.ViewModels DateTime now = DateTime.Now; // Update test count. - PermutationCount = $"{_newRecipeCount:n0}"; + ulong newRecipeCount = _newRecipeCount; + PermutationCount = $"{newRecipeCount:n0}"; // Pull in new recipes. if (!_pendingNewRecipes.IsEmpty) @@ -387,12 +392,13 @@ namespace DesertPaintCodex.ViewModels if (_unsavedRecipes) { + Debug.WriteLine("Saving generator state."); + _saving = true; + _generator.Stop(); + _profile.SaveRecipes(); _unsavedRecipes = false; } - - _saving = true; - _generator.Stop(); } #endregion