示例#1
0
        /**
         * Opens the profile for reading / writing.
         */
        public bool OpenProfile(WOL2ProfileAccessMode mode)
        {
            switch (mode)
            {

                case WOL2ProfileAccessMode.ModeRead:
                    {
                        // If in xml mode open the xml file
                        if (!UseRegistry)
                        {
                            m_xmlProfile = new XmlDocument();
                            try
                            {
                                // Load the file
                                m_xmlProfile.Load(PROFILE_FILE_NAME);

                                // Get the main node
                                m_xmlMain = m_xmlProfile.GetElementsByTagName("WakeOnLanProfile")[0];
                            }
                            catch
                            {
                                return false;
                            }
                        }
                    }
                    break;

                case WOL2ProfileAccessMode.ModeWrite:
                    {
                        // If in xml mode open a new xml file
                        if (!UseRegistry)
                        {

                            // Create the XML document
                            m_xmlProfile = new XmlDocument();
                            m_xmlProfile.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><WakeOnLanProfile></WakeOnLanProfile>");

                            // Get the main node
                            m_xmlMain = m_xmlProfile.GetElementsByTagName("WakeOnLanProfile")[0];
                        }
                        else
                        {
                            // if in Reg. mode: clear the old keys
                            try
                            {
                                Registry.CurrentUser.DeleteSubKeyTree(PROFILE_REG_KEY);
                            }
                            catch
                            {
                            }
                        }
                    }
                    break;

                case WOL2ProfileAccessMode.ModeClosed:
                    {
                        // Close the file if any
                        if ( m_Mode == WOL2ProfileAccessMode.ModeWrite && m_xmlProfile != null )
                        {
                            // Save the file
                            try
                            {
                                m_xmlProfile.Save(PROFILE_FILE_NAME);
                            }
                            catch
                            {
                                return false;
                            }
                        }

                        m_xmlProfile = null;
                        m_xmlMain = null;
                    }
                    break;
            }

            m_Mode = mode;

            // all done
            return true;
        }
示例#2
0
        /**
         * Opens the profile for reading / writing.
         */
        public bool OpenProfile(WOL2ProfileAccessMode mode)
        {
            switch (mode)
            {
            case WOL2ProfileAccessMode.ModeRead:
            {
                // If in xml mode open the xml file
                if (!UseRegistry)
                {
                    m_xmlProfile = new XmlDocument();
                    try
                    {
                        // Load the file
                        m_xmlProfile.Load(PROFILE_FILE_NAME);

                        // Get the main node
                        m_xmlMain = m_xmlProfile.GetElementsByTagName("WakeOnLanProfile")[0];
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            break;

            case WOL2ProfileAccessMode.ModeWrite:
            {
                // If in xml mode open a new xml file
                if (!UseRegistry)
                {
                    // Create the XML document
                    m_xmlProfile = new XmlDocument();
                    m_xmlProfile.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><WakeOnLanProfile></WakeOnLanProfile>");

                    // Get the main node
                    m_xmlMain = m_xmlProfile.GetElementsByTagName("WakeOnLanProfile")[0];
                }
                else
                {
                    // if in Reg. mode: clear the old keys
                    try
                    {
                        Registry.CurrentUser.DeleteSubKeyTree(PROFILE_REG_KEY);
                    }
                    catch
                    {
                    }
                }
            }
            break;

            case WOL2ProfileAccessMode.ModeClosed:
            {
                // Close the file if any
                if (m_Mode == WOL2ProfileAccessMode.ModeWrite && m_xmlProfile != null)
                {
                    // Save the file
                    try
                    {
                        m_xmlProfile.Save(PROFILE_FILE_NAME);
                    }
                    catch
                    {
                        return(false);
                    }
                }

                m_xmlProfile = null;
                m_xmlMain    = null;
            }
            break;
            }

            m_Mode = mode;

            // all done
            return(true);
        }