private void mainWindow_Closing(object sender, CancelEventArgs e) { if (!shuttingDown) { Logger.Instance.Log4.Info("Hiding Main Window..."); // If we're NOT shutting down (the user hit the close button or pressed // CTRL-F4) minimize to tray. e.Cancel = true; // Hide the form and make sure the taskbar icon is visible notifyIcon.Visible = true; Hide(); } else { Logger.Instance.Log4.Info("Closing Main Window..."); // Save Commands // Stop file system watcher watcher.Dispose(); watcher = null; Invoker.Save($@"{Program.ConfigPath}MCEControl.commands"); TelemetryService.Instance.Stop(); } }
private void mainWindow_Load(object sender, EventArgs e) { Logger.Instance.Log4.Info($"MCE Controller v{System.Windows.Forms.Application.ProductVersion}" + $" - OS: {Environment.OSVersion.ToString()} on {(Environment.Is64BitProcess ? "x64" : "x86")}" + $" - .NET: {Environment.Version.ToString()}"); // Load AppSettings Settings = AppSettings.Deserialize($@"{Program.ConfigPath}{AppSettings.SettingsFileName}"); // Configure logging (some logging already happened). Logger.Instance.TextBoxThreshold = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap[Instance.Settings.TextBoxLogThreshold]; Logger.Instance.Log4.Info($"Logger: Logging to {Logger.Instance.LogFile}"); // Telemetry TelemetryService.Instance.Start("MCE Controller"); Logger.Instance.Log4.Info($"Telemetry: {(TelemetryService.Instance.TelemetryEnabled ? "Enabled" : "Disabled")}"); // Updates UpdateService.Instance.GotLatestVersion += GotLatestVersionHandler; UpdateService.Instance.CheckVersion(); // Commands if (cmdWindow == null) { cmdWindow = new CommandWindow(); } // watch .command file for changes watcher = new CommandFileWatcher($@"{Program.ConfigPath}MCEControl.commands"); watcher.ChangedEvent += (o, a) => CmdTable_CommandsChangedEvent(o, a); LoadCommands(); if (Settings.HideOnStartup) { Opacity = 0; Win32.PostMessage(Handle, (UInt32)WM.SYSCOMMAND, (UInt32)SC.CLOSE, 0); } SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); // Location can not be changed in constructor, has to be done here // Use Window's default for location initially. Size needs highDPI conversion. if (Settings.WindowLocation.IsEmpty || Settings.WindowSize.IsEmpty) { Size = new Size(this.LogicalToDeviceUnits(1024), this.LogicalToDeviceUnits(640)); } else { Location = Settings.WindowLocation; Size = Settings.WindowSize; } SetStatus($"Version: {Application.ProductVersion}"); Start(); }