private void Cleanup() { _regWatcher?.Stop(); _tcpListener?.Stop(); _udpServer?.Close(); JsonImageCache.Save(); }
private void RegEventHandler(object sender, EventArrivedEventArgs e) { using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\GaRyan2\epg123", false)) { if (key != null) { var regToken = (string)key.GetValue("token", ""); if (regToken != TokenService.Token) { Helper.WriteLogEntry($"New token detected in registry. token={regToken}"); TokenService.Token = regToken; TokenService.GoodToken = true; JsonImageCache.Save(); // seems like a good time to save } var regRefresh = (int)key.GetValue("autoRefreshToken", 0) > 0; if (regRefresh != TokenService.RefreshToken) { Helper.WriteLogEntry($"Auto token refresh setting changed. autoRefreshToken={regRefresh}"); TokenService.RefreshToken = regRefresh; } var regCache = (int)key.GetValue("cacheImages", 0) > 0; if (regCache != JsonImageCache.cacheImages) { Helper.WriteLogEntry($"Cache images setting changed. cacheImages={regCache}"); JsonImageCache.cacheImages = regCache; } var regCacheRetent = (int)key.GetValue("cacheRetention", 30); if (regCacheRetent != JsonImageCache.cacheRetention) { Helper.WriteLogEntry($"Cache retention setting changed. cacheRetention={regCacheRetent}"); JsonImageCache.cacheRetention = regCacheRetent; } } else { Helper.WriteLogEntry("Registry key no longer exists. Stopping watcher."); _regWatcher.Stop(); } } }