# HG changeset patch # User Jason Maltzen # Date 2021-09-10 00:03:21 # Node ID 5e28ba3945f728dd4994247ad1188952972ed850 # Parent d6859ea7177f26dd26fbc589ed8a64eb7389400d Recipe count is now a ulong instead of an int so it can show values > 2.47 billion. Also, don't allow clearing the recipe list while the recipe generator is running. 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