Example #1
0
        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);
        }
Example #2
0
        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;
        }