From 61ef03616262b67b7bc74f30a2319623f494918b Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Fri, 23 Feb 2018 22:31:38 +0900 Subject: [PATCH 1/1] =?utf8?q?=E3=81=BB=E3=81=8B=E3=81=AEPC=E3=81=A7status?= =?utf8?q?.xml=E3=81=8C=E6=9B=B4=E6=96=B0=E3=81=95=E3=82=8C=E3=81=9F?= =?utf8?q?=E3=81=A8=E3=81=8D=E3=81=AB=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=82=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer/MainForm.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index 168f30e..2d2dcdc 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -90,7 +90,7 @@ namespace KancolleSniffer _proxyManager.UpdatePacFile(); PerformZoom(); _shipLabels.AdjustAkashiTimers(); - _sniffer.LoadState(); + LoadState(); _sniffer.RepeatingTimerController = new RepeatingTimerController(_notificationManager, _config); } @@ -107,6 +107,32 @@ namespace KancolleSniffer handle = panel.Handle; } + private readonly FileSystemWatcher _watcher = new FileSystemWatcher + { + Path = AppDomain.CurrentDomain.BaseDirectory, + Filter = "status.xml", + NotifyFilter = NotifyFilters.LastWrite + }; + + private readonly Timer _watcherTimer = new Timer {Interval = 1000}; + + private void LoadState() + { + _sniffer.LoadState(); + _watcher.SynchronizingObject = this; + _watcherTimer.Tick += (sender, ev) => + { + _watcherTimer.Stop(); + _sniffer.LoadState(); + }; + _watcher.Changed += (sender, ev) => + { + _watcherTimer.Stop(); + _watcherTimer.Start(); + }; + _watcher.EnableRaisingEvents = true; + } + private class RepeatingTimerController : Sniffer.IRepeatingTimerController { private readonly NotificationManager _manager; -- 2.11.0