Changeset - d16a2d816aa5
[Not reviewed]
default
0 1 0
Jason Maltzen - 3 years ago 2021-08-27 21:57:42
jason@hiddenachievement.com
Don't open the recipe generator log file on view creation - only open it if configured when starting recipe generation. Fixes a crash when importing reaction data / profile data.
1 file changed with 0 insertions and 7 deletions:
0 comments (0 inline, 0 general)
ViewModels/RecipeGeneratorViewModel.cs
Show inline comments
...
 
@@ -78,103 +78,96 @@ namespace DesertPaintCodex.ViewModels
 
        
 
        #region Collections
 
        
 
        public ObservableCollection<Reagent> Reagents { get; } = new();
 
        public ObservableCollection<GeneratorRecipe> AllRecipes { get; } = new();
 
        
 
        #endregion // Collections
 
        
 
        private readonly RecipeGenerator _generator;
 

	
 
        private DateTime _lastSave = DateTime.Now;
 
        private readonly PlayerProfile _profile;
 
        private uint _minConcentration;
 

	
 
        private readonly ConcurrentQueue<PaintRecipe> _pendingNewRecipes = new();
 
        private volatile int _newRecipeCount;
 
        private volatile bool _updatesAvailable;
 
        private readonly DispatcherTimer _updateTimer;
 
        
 
        private bool _ribbonMode;
 
        private bool _unsavedRecipes;
 
        private bool _saving;
 

	
 
        
 
        public RecipeGeneratorViewModel()
 
        {
 
            List<string> reagentNames = ReagentService.Names;
 
            foreach (string name in reagentNames)
 
            {
 
                Reagents.Add(ReagentService.GetReagent(name));
 
            }
 
            
 
            SettingsService.Get("Generator.RibbonMode", out bool ribbonMode, false);
 
            ProductIndex = ribbonMode ? 1 : 0;
 
            _ribbonMode = ribbonMode;
 

	
 
            PlayerProfile? profile = ProfileManager.CurrentProfile;
 
            Debug.Assert(profile != null);
 
            _profile = profile;
 
            
 
            _profile.LoadRecipes();
 

	
 
            _generator = new RecipeGenerator();
 

	
 
            _generator.Progress  += OnProgress;
 
            _generator.NewRecipe += OnNewRecipe;
 
            _generator.Finished  += OnGeneratorStopped;
 

	
 
            SettingsService.Get("Generator.Logging", out bool logGenerator, false);
 
            if (logGenerator)
 
            {
 
                string logDir = DesertPaintCodex.Util.FileUtils.AppDataPath;
 
                _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt");
 
            }
 
            
 
            if (ribbonMode)
 
            {
 
                InitStateForRibbons();
 
            }
 
            else
 
            {
 
                InitStateForPaint();
 
            }
 

	
 
            _updateTimer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(UpdateInterval)};
 
            _updateTimer.Tick += Update;
 

	
 
            this.WhenAnyValue(x => x.ProductIndex).Subscribe(_ => ChangeMode());
 
        }
 

	
 
        public void Start()
 
        {
 
            IsInProgress = true;
 
            IsRunning = true;
 
            ReagentService.SaveProfileReagents(_profile.ReagentFile);
 
            SaveSettings(_ribbonMode ? "Ribbon" : "Paint");
 
            _updateTimer.Start();
 
            SelectedView = 1;
 

	
 
            _generator.CloseLog();
 
            SettingsService.Get("Generator.Logging", out bool logGenerator, false);
 
            if (logGenerator)
 
            {
 
                string logDir = DesertPaintCodex.Util.FileUtils.AppDataPath;
 
                _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt");
 
            }
 

	
 
            _generator.BeginRecipeGeneration(
 
                _minConcentration, 
 
                (uint)MaxConcentration, 
 
                1, 
 
                (uint)MaxReagents, 
 
                (uint)FullQuantityDepth, 
 
                (uint)FullQuantity);
 
        }
 

	
 
        
 
        public void End()
 
        {
 
            IsPaused     = false;
 
            IsRunning    = false;
 
            IsInProgress = false;
 
            _updateTimer.Stop();
0 comments (0 inline, 0 general)