public static PowerCfg Load() { PowerCfg cfg; Stream stream = null; IFormatter formatter = new BinaryFormatter(); try { stream = new FileStream("jeremy.cfg", FileMode.Open, FileAccess.Read, FileShare.Read); cfg = (PowerCfg)formatter.Deserialize(stream); } catch (FileNotFoundException ex) { Trace.WriteLine("PowerCfg#Load: power.cfg Not Found - Creating New PowerCfg"); cfg = new PowerCfg(); } catch (Exception ex) { Trace.WriteLine(String.Format("PowerCfg#Load: Unhandled Exception - {0}", ex.Message)); cfg = new PowerCfg(); } finally { if (stream != null) { stream.Close(); } } cfg.Save(); return(cfg); }
public SettingsForm(PowerCfg cfg) { Trace.WriteLine("SettingsForm: Initializing"); InitializeComponent(); this.powercfg = cfg; settingsGridView.Rows.Clear(); foreach (var setting in this.powercfg.settings) { settingsGridView.Rows.Add(setting.Value, setting.Key, this.powercfg.timeoutActive[setting.Key], this.powercfg.timeoutInactive[setting.Key]); } }
static void Main() { // Default application setup Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Load powercfg powercfg = PowerCfg.Load(); powercfg.Apply(); // Setup our tray context Icon trayIcon = powercfg.active ? Jeremy.Properties.Resources.TrayIcon_Active : Jeremy.Properties.Resources.TrayIcon_Inactive; trayApp = new TrayApplicationContext("Jeremy", trayIcon); // Add event handlers trayApp.notifyIcon.ContextMenuStrip.Opening += Menu_Opening; trayApp.notifyIcon.MouseClick += NotifyIcon_MouseClick; trayApp.notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; Application.Run(trayApp); }