private void MainForm_Shown(object sender, EventArgs e) { // Restore window pos WOL2Profile profile = new WOL2Profile(m_bUseRegistryProfile); if (profile.OpenProfile(WOL2Profile.WOL2ProfileAccessMode.ModeRead)) { FormWindowState WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), profile.GetSetting("Window_State", this.WindowState.ToString())); // Minimize to tray? if (WindowState == FormWindowState.Minimized && m_bMinimizeToTray) { this.Hide(); } else this.WindowState = WindowState; // Restore window size and position this.Left = profile.GetSetting("Window_X", this.Left); this.Top = profile.GetSetting("Window_Y", this.Top); this.Width = profile.GetSetting("Window_Width", this.Width); this.Height = profile.GetSetting("Window_Height", this.Height); // Done profile.CloseProfile(); profile = null; } // Do a little survey // MOE: No more for >= 2.0.2.6 // DoSurvey(false); }
/// <summary> /// Exits the tool, saving all settings. /// </summary> public void ExitWOLTool( bool bQuitApp ) { // Save the toolbar // Only do this if the window is visible as the toolpositions would be lost otherwise if (this.WindowState != FormWindowState.Minimized && this.Visible == true ) ToolStripManager.SaveSettings(this); // If the file was changed prop for save if (m_bChangedFile) { string msg = MOE.Utility.GetStringFromRes("strSaveChangedFile"); DialogResult dr = MessageBox.Show(this, msg, "WOL2", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == System.Windows.Forms.DialogResult.Yes) { SaveHostList(m_sHostFileName.Length > 0 ? m_sHostFileName : null); } } WOL2Profile profile = new WOL2Profile(m_bUseRegistryProfile); if (profile.OpenProfile(WOL2Profile.WOL2ProfileAccessMode.ModeWrite)) { profile.SaveSetting("RefreshInterval", m_iOnlineCheckInterval); profile.SaveSetting("GroupWakeDelay", m_iWakeDelay); profile.SaveSetting("WOLPort", m_iWakePort); profile.SaveSetting("PingTimeout", m_iPingTimeout); profile.SaveSetting("ViewStyle", listView.View.ToString()); profile.SaveSetting("OpenLastFile", m_bOpenLastFile); profile.SaveSetting("LastFile", m_sHostFileName); profile.SaveSetting("DoLogging", m_bDoLogging); profile.SaveSetting("ColorizeListView", m_bColorizeListView); profile.SaveSetting("AutosaveHostlist", m_bAutosaveHostFile); profile.SaveSetting("MinimizeToTray", m_bMinimizeToTray); profile.SaveSetting("ConfirmNetworkOptions", m_bConfirmNetActions); profile.SaveSetting("UseIPv6", m_bUseIpV6); profile.SaveSetting("HostStateChangedCommand", m_sHostStateChangedCommand); profile.SaveSetting("GroupStateChangedCommand", m_sGroupStateChangedCommand); profile.SaveSetting("DisplayStateNotifications", m_bDisplayStateNotifications); profile.SaveSetting("AlwaysDisplayNotifications", m_bAlwaysDisplayNotifications); profile.SaveSetting("NotificationTimeout", m_iNotificationTimeout); profile.SaveSetting("UpdateIPAddressesForDHCP", m_bUpdateIPInOnlineChecker); profile.SaveSetting("WOLFlags", m_PacketTransferOptions.ToString()); profile.SaveSetting("AskForSecureOnPwd", m_bAskForSecureOnPwd); profile.SaveSetting("SortColumn", m_ListViewSorter.SortColumn.ToString()); profile.SaveSetting("SortOrder", m_ListViewSorter.Order.ToString()); for( int idx = 0; idx < listView.Columns.Count; idx++ ) { profile.SaveSetting("ColumnOrder" + idx, listView.Columns[idx].DisplayIndex); profile.SaveSetting("ColumnWidth" + idx, listView.Columns[idx].Width); } profile.SaveSetting("ShutdownTimeout", m_iShutdownTimeout); if (m_sShutdownComment != null) profile.SaveSetting("ShutdownComment", m_sShutdownComment); profile.SaveSetting("ShutdownPaswd", MOE.Utility.Base64Encode(MOE.Utility.SecureStringToString(m_sShutdownPaswd))); if (m_sShutdownUser != null) profile.SaveSetting("ShutdownUser", m_sShutdownUser); if (m_sShutdownDomain != null) profile.SaveSetting("ShutdownDomain", m_sShutdownDomain); profile.SaveSetting("ForceShutdown", m_bForceShutdown); profile.SaveSetting("RebootTimeout", m_iRebootTimeout); if (m_sRebootComment != null) profile.SaveSetting("RebootComment", m_sRebootComment); profile.SaveSetting("RebootPaswd", MOE.Utility.Base64Encode(MOE.Utility.SecureStringToString(m_sRebootPaswd))); if (m_sRebootUser != null) profile.SaveSetting("RebootUser", m_sRebootUser); if (m_sRebootDomain != null) profile.SaveSetting("RebootDomain", m_sRebootDomain); profile.SaveSetting("ForceReboot", m_bForceReboot); // Network scanner options profile.SaveSetting("UnresolvedNameOk", m_bUnresolvedNameOk); profile.SaveSetting("UnresolvedMacOk", m_bUnresolvedMacOk); // Survey profile.SaveSetting("SurveyCompleted", m_bHasDoneSurvey); // Save the current window state if (this.Visible == false) profile.SaveSetting("Window_State", FormWindowState.Minimized.ToString()); else profile.SaveSetting("Window_State", this.WindowState.ToString()); // Reset the window state so we know the window sizes this.WindowState = FormWindowState.Normal; // Window position profile.SaveSetting("Window_X", this.Left); profile.SaveSetting("Window_Y", this.Top); profile.SaveSetting("Window_Width", this.Width); profile.SaveSetting("Window_Height", this.Height); // Add new tool keys int i = 0; foreach (WOL2Tool t in m_Tools.Values) { profile.SaveSetting("Tool" + i++, t.ToString()); } // Save the MRU for (int itm = 0; itm < m_MruList.Count; itm++) { if (itm >= 10) break; profile.SaveSetting("MRUItem" + (itm + 1), m_MruList[itm]); } } // Done profile.CloseProfile(); profile = null; MOE.Logger.StopLogging(); if( bQuitApp ) Application.Exit(); }
private Dictionary<string, WOL2Tool> m_Tools = new Dictionary< string, WOL2Tool >(); // The tools list #endregion Fields #region Constructors public MainForm( string[] args ) { // The InitializeComponent() call is required for Windows Forms designer support. InitializeComponent(); // Initialize the command line arguments class Arguments CommandLine = new Arguments(args); // Create a new list view sorter m_ListViewSorter = new ListViewColumnSorter(); listView.ListViewItemSorter = m_ListViewSorter; // Load the settings #region Read Profile ---------------------- string sLastFile = ""; // Check where we should read our settings from if (CommandLine["registry"] != null) { m_bUseRegistryProfile = true; } else if (!WOL2Profile.HasXmlProfile()) { m_bUseRegistryProfile = true; } WOL2Profile profile = new WOL2Profile(m_bUseRegistryProfile); if (profile.OpenProfile(WOL2Profile.WOL2ProfileAccessMode.ModeRead)) { m_iOnlineCheckInterval = profile.GetSetting("RefreshInterval", 10000); // milli seconds m_iWakeDelay = profile.GetSetting("GroupWakeDelay", 500); m_iWakePort = profile.GetSetting("WOLPort", 7); m_iPingTimeout = profile.GetSetting("PingTimeout", 250); listView.View = (View)View.Parse(typeof(View), (string)profile.GetSetting("ViewStyle", "Details")); m_PacketTransferOptions = (WOLPacketTransferMode)Enum.Parse(typeof(WOLPacketTransferMode), profile.GetSetting("WOLFlags", "modeBCast"), true); m_bAskForSecureOnPwd = profile.GetSetting("AskForSecureOnPwd", false); m_bOpenLastFile = profile.GetSetting("OpenLastFile", true); sLastFile = profile.GetSetting("LastFile", ""); m_bHasDoneSurvey = profile.GetSetting("SurveyCompleted", false); m_bDoLogging = profile.GetSetting("DoLogging", false); // Start Logging? #if DEBUG MOE.Logger.StartLogging("wol2.log", Logger.LogLevel.lvlDebug); #else if (m_bDoLogging) MOE.Logger.StartLogging("wol2.log", Logger.LogLevel.lvlDebug); #endif m_bColorizeListView = profile.GetSetting("ColorizeListView", false); m_bAutosaveHostFile = profile.GetSetting("AutosaveHostlist", false); m_bMinimizeToTray = profile.GetSetting("MinimizeToTray", false); m_bConfirmNetActions = profile.GetSetting("ConfirmNetworkOptions", true); m_bUseIpV6 = profile.GetSetting("UseIPv6", false); // Notification options m_bDisplayStateNotifications = profile.GetSetting("DisplayStateNotifications", false); m_bAlwaysDisplayNotifications = profile.GetSetting("AlwaysDisplayNotifications", false); m_iNotificationTimeout = profile.GetSetting("NotificationTimeout", 3000); // ms m_bUpdateIPInOnlineChecker = profile.GetSetting("UpdateIPAddressesForDHCP", false); m_sHostStateChangedCommand = profile.GetSetting("HostStateChangedCommand", ""); m_sGroupStateChangedCommand = profile.GetSetting("GroupStateChangedCommand", ""); // Network scanner options m_bUnresolvedNameOk = profile.GetSetting("UnresolvedNameOk", false); m_bUnresolvedMacOk = profile.GetSetting("UnresolvedMacOk", false); // Restore List View Columns for (int i = 0; i < listView.Columns.Count; i++) { int d = profile.GetSetting("ColumnOrder" + i, -1); int w = profile.GetSetting("ColumnWidth" + i, -1); if (d != -1) listView.Columns[i].DisplayIndex = d; if (w != -1) { listView.Columns[i].Width = w; } } // Restore the list view sort order m_ListViewSorter.SortColumn = profile.GetSetting("SortColumn", 0); m_ListViewSorter.Order = profile.GetSetting("SortOrder", "Ascending") == "Ascending" ? SortOrder.Ascending : SortOrder.Descending; // Make the sort order visible ListViewExtensions.SetSortIcon(listView, m_ListViewSorter.SortColumn, m_ListViewSorter.Order); listView.Sort(); // Load tools string temp = profile.GetSetting("Tool0", ""); int idx = 0; while (temp != "") { WOL2Tool t = WOL2Tool.parse(temp); if (t != null) m_Tools.Add(t.GetName(), t); temp = profile.GetSetting("Tool" + ++idx, ""); } // Load the MRU temp = profile.GetSetting("MRUItem1", ""); idx = 1; while (temp != "") { m_MruList.Add(temp); temp = profile.GetSetting("MRUItem" + ++idx, ""); } BuildMruList(); m_iShutdownTimeout = profile.GetSetting("ShutdownTimeout", 60); // seconds m_sShutdownComment = profile.GetSetting("ShutdownComment", ""); temp = profile.GetSetting("ShutdownPaswd", ""); if (temp != "") { string s = MOE.Utility.Base64Decode(temp); m_sShutdownPaswd = MOE.Utility.SecureStringFromString(s); } m_sShutdownUser = profile.GetSetting("ShutdownUser", ""); m_sShutdownDomain = profile.GetSetting("ShutdownDomain", ""); m_bForceShutdown = profile.GetSetting("ForceShutdown", false); m_iRebootTimeout = profile.GetSetting("RebootTimeout", 60); m_sRebootComment = profile.GetSetting("RebootComment", ""); temp = profile.GetSetting("RebootPaswd", ""); if (temp != "") { string s = MOE.Utility.Base64Decode(temp); m_sRebootPaswd = MOE.Utility.SecureStringFromString(s); } m_sRebootUser = profile.GetSetting("RebootUser", ""); m_sRebootDomain = profile.GetSetting("RebootDomain", ""); m_bForceReboot = profile.GetSetting("ForceReboot", false); // Done profile.CloseProfile(); profile = null; } #endregion // Create an empty document CreateNewHostsFile(); // Parse the command line. if( CommandLine["file"] != null ) { OpenHostList( CommandLine["file"] ); } else { // Check whether to open the last file if( m_bOpenLastFile && sLastFile != "" ) { m_sHostFileName = sLastFile; OpenHostList(m_sHostFileName); } } if( CommandLine["wake"] != null ) { string s = CommandLine["wake"]; string [] sHosts = s.Split( ';' ); Monitor.Enter( m_LockHosts ); foreach( string sHost in sHosts ) { WOL2Host h = m_Hosts.Find( delegate( WOL2Host theHost ) { return theHost.GetName().ToLower() == sHost.ToLower(); } ); if( h != null ) WakeHost( h, true ); DateTime dwTime = DateTime.Now.AddMilliseconds(m_iWakeDelay); while (DateTime.Now < dwTime) Application.DoEvents(); } Monitor.Exit( m_LockHosts ); } if (CommandLine["shutdown"] != null) { string s = CommandLine["shutdown"]; string[] sHosts = s.Split(';'); Monitor.Enter(m_LockHosts); foreach (string sHost in sHosts) { WOL2Host h = m_Hosts.Find(delegate(WOL2Host theHost) { return theHost.GetName().ToLower() == sHost.ToLower(); }); if (h != null) ShutdownHost(h, true); } Monitor.Exit(m_LockHosts); } if (CommandLine["reboot"] != null) { string s = CommandLine["reboot"]; string[] sHosts = s.Split(';'); Monitor.Enter(m_LockHosts); foreach (string sHost in sHosts) { WOL2Host h = m_Hosts.Find(delegate(WOL2Host theHost) { return theHost.GetName().ToLower() == sHost.ToLower(); }); if (h != null) RebootHost(h, true); } Monitor.Exit(m_LockHosts); } if (CommandLine["wakegrp"] != null) { string s = CommandLine["wakegrp"]; string[] sGroups = s.Split(';'); foreach (string sGroup in sGroups) { WOL2Group g; if( m_Groups.TryGetValue( sGroup, out g ) ) WakeGroup(g, true); } } if (CommandLine["rebootgrp"] != null) { string s = CommandLine["rebootgrp"]; string[] sGroups = s.Split(';'); foreach (string sGroup in sGroups) { WOL2Group g; if (m_Groups.TryGetValue(sGroup, out g)) RebootGroup(g, true); } } if (CommandLine["shutdowngrp"] != null) { string s = CommandLine["shutdowngrp"]; string[] sGroups = s.Split(';'); foreach (string sGroup in sGroups) { WOL2Group g; if (m_Groups.TryGetValue(sGroup, out g)) ShutdownGroup(g, true); } } // Last parameter: Close the App. if( CommandLine["close"] != null ) { this.Close(); m_bNoStart = true; return; } // Refresh the tools menu RefreshToolsMenu(); // Kick Up the OnlineStateChecker InitOnlineStateChecker(); // Say hello lblStatus.Text = MOE.Utility.GetStringFromRes("strWelcome"); // Load toolbar settings ToolStripManager.LoadSettings(this); // Make the toolbars visible if they were hidden (by a bug in ToolStripManager) toolStrip1.Visible = true; toolStripTools.Visible = true; menuStrip1.Visible = true; statusStrip1.Visible = true; }