From afe40ba1a45a889e5e3f93d3c17eb5e78ad47f91 Mon Sep 17 00:00:00 2001 From: Mirsario Date: Mon, 6 Jun 2022 03:37:30 +0300 Subject: [PATCH] Polished auto config reloading a bit more. --- Core/Configuration/ConfigSystem.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/Configuration/ConfigSystem.cs b/Core/Configuration/ConfigSystem.cs index 2148ec1e..efbd7b92 100644 --- a/Core/Configuration/ConfigSystem.cs +++ b/Core/Configuration/ConfigSystem.cs @@ -145,6 +145,8 @@ public static void SaveConfig(string? oldJson = null) string newJson = SaveConfigInner(); if (newJson != oldJson || oldJson == null) { + lastConfigWatcherWriteTime = DateTime.Now.AddSeconds(0.5d); // Really ensure that this doesn't trigger an automatic config reload. + File.WriteAllText(ConfigPath, newJson); } } @@ -272,7 +274,7 @@ private static void OnConfigDirectoryFileUpdateChanged(object sender, FileSystem DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); if (lastWriteTime > lastConfigWatcherWriteTime) { - lastConfigWatcherWriteTime = lastWriteTime.AddSeconds(1d); + lastConfigWatcherWriteTime = lastWriteTime.AddSeconds(0.1d); Thread.Sleep(50); // Wait a bit, because the file is frequently still being written to here. @@ -283,7 +285,10 @@ private static void OnConfigDirectoryFileUpdateChanged(object sender, FileSystem if (!Main.dedServ) { var sound = Common.Magic.MagicWeapon.MagicBlastSound; - SoundEngine.PlaySound(sound with { Volume = 0.33f }); + try { + SoundEngine.PlaySound(sound with { Volume = 0.33f }); + } + catch { } } } }