Пример #1
0
        private void customizeHosts(HostsProfile hp)
        {
            listLocked = true;
            listView1.Items.Clear();
            int i = 1;

            foreach (Domain d in hp.domains)
            {
                ListViewItem a = new ListViewItem(new string[] { i.ToString(), d.useLocalhost.ToString(), d.alsoWWW.ToString(), d.redirectedAddress, d.domainToRedirect });
                if (d.isEnabled)
                {
                    a.BackColor = Color.PaleGreen;
                    a.ForeColor = Color.DarkGreen;
                    a.Checked   = true;
                }
                else
                {
                    a.BackColor = Color.White;
                    a.ForeColor = Color.DarkGray;
                    a.Checked   = false;
                }
                listView1.Items.Add(a);
                i++;
            }
            listLocked = false;
        }
Пример #2
0
        private void button_copy_Click(object sender, EventArgs e)
        {
            HostsProfile hp       = getProfileByIndex(listBox_hosts.SelectedIndex);
            var          formCopy = new FormCopy(string.Format("Copy {0} to which file ?", hp.profileName), hp.profileName + "_Copy");
            var          result   = formCopy.ShowDialog(this);

            if (result == DialogResult.OK && !string.IsNullOrEmpty(formCopy.FileName))
            {
                if (checkForDuplicates(formCopy.FileName))
                {
                    MessageBox.Show("Error: '" + formCopy.FileName + "' is already an existing profile name");
                }
                else
                {
                    HostsProfile newHp = new HostsProfile();

                    foreach (Domain d in hp.domains)
                    {
                        newHp.domains.Add(d);
                    }

                    newHp.profileName = formCopy.FileName;
                    newHp.isCurrent   = false;
                    profiles.Add(newHp);
                    updateListBox();
                    //m_HostsProvider.CopyHosts((string)listHosts.SelectedItem, formCopy.FileName);
                    //LogInfo("Copied {0} to {1}\r\n", listHosts.SelectedItem, formCopy.FileName);
                    //RefreshList();
                }
            }
        }
Пример #3
0
        public static List <HostsProfile> readFromXML(string file)
        {
            List <HostsProfile> myProfiles = new List <HostsProfile>();
            bool failed = false;

            if (File.Exists(getSettingsFilepath()))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(getSettingsFilepath());

                XmlNode root = doc.DocumentElement.FirstChild;

                if (root == null) //XML file doestn' contain maze
                {
                    failed = true;
                }
                else
                {
                    XmlNode fileVersionNode = root.Attributes["version"];
                    string  fileVersion     = "unknown";
                    if (fileVersionNode != null)
                    {
                        fileVersion = fileVersionNode.InnerText;
                    }

                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        switch (node.Name)
                        {
                        case "HostsProfile":
                            HostsProfile profile = new HostsProfile((XmlElement)node);
                            myProfiles.Add(profile);
                            break;
                        }
                    }
                }
            }
            else
            {
                failed = true;
            }

            if (failed)
            {
                HostsProfile currentHost = new HostsProfile();
                currentHost.isCurrent = true;
                myProfiles.Add(currentHost);
            }

            return(myProfiles);
        }
Пример #4
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog a = new SaveFileDialog();

            a.Filter           = "Exported Hosts Profiles (*.xml)|*.*";
            a.FilterIndex      = 1;
            a.DefaultExt       = ".xml";
            a.RestoreDirectory = true;


            if (a.ShowDialog() == DialogResult.OK)
            {
                HostsProfile.writeToSettingsXML(profiles, a.FileName);
            }
        }
Пример #5
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog a = new OpenFileDialog();

            a.Filter           = "Exported Hosts Profiles (*.xml)|*.*";
            a.FilterIndex      = 1;
            a.RestoreDirectory = true;
            if (a.ShowDialog() == DialogResult.OK)
            {
                profiles     = HostsProfile.readFromXML(a.FileName);
                currentHosts = HostsProfile.getCurrentProfile(profiles);

                selectedProfile = currentHosts;
                customizeHosts(selectedProfile);
                updateListBox();
            }
        }
Пример #6
0
        private void setCurrentByIndex(int curID)
        {
            int i = 0;

            foreach (HostsProfile hp in profiles)
            {
                if (i == curID)
                {
                    hp.isCurrent = true;
                    currentHosts = hp;
                }
                else
                {
                    hp.isCurrent = false;
                }
                i++;
            }

            updateListBox();
        }
Пример #7
0
        private void button_delete_Click(object sender, EventArgs e)
        {
            HostsProfile hp = getProfileByIndex(listBox_hosts.SelectedIndex);

            //if (e.ClickedItem == btnDelete && listHosts.SelectedItem != null)
            //{
            if (hp.profileName != "Default" && MessageBox.Show(string.Format("Really delete {0} ?", hp.profileName), string.Empty, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                if (hp.isCurrent)
                {
                    setCurrentByIndex(0);
                }
                profiles.RemoveAt(listBox_hosts.SelectedIndex);
                listBox_hosts.SelectedIndex = 0;

                //m_HostsProvider.DeleteHosts((string)listHosts.SelectedItem);
                //LogInfo("Deleted {0}\r\n", listHosts.SelectedItem);
                //RefreshList();
                updateListBox();
            }
            //}
        }
Пример #8
0
        private void button_new_Click(object sender, EventArgs e)
        {
            var formCopy = new FormCopy("Enter new profile name");
            var result   = formCopy.ShowDialog(this);

            if (result == DialogResult.OK && !string.IsNullOrEmpty(formCopy.FileName))
            {
                if (checkForDuplicates(formCopy.FileName))
                {
                    MessageBox.Show("Error: '" + formCopy.FileName + "' is already an existing profile name");
                }
                else
                {
                    HostsProfile newHp = new HostsProfile();
                    newHp.profileName = formCopy.FileName;
                    newHp.isCurrent   = false;
                    profiles.Add(newHp);
                    //m_HostsProvider.CopyHosts((string)listHosts.SelectedItem, formCopy.FileName);
                    //LogInfo("Copied {0} to {1}\r\n", listHosts.SelectedItem, formCopy.FileName);
                    updateListBox();
                }
            }
        }
Пример #9
0
        public FormMain()
        {
            InitializeComponent();

            m_HostsProvider = new HostProvider();
            quickSwitchToolStripMenuItem.DropDownItemClicked += new ToolStripItemClickedEventHandler(quickSwitchToolStripMenuItem_DropDownItemClicked);

            Text = string.Format("Hosts Switcher - v.{0}", typeof(FormMain).Assembly.GetName().Version);

            listLocked = true;
            if (File.Exists(appSettingsFilePath))
            {
                profiles     = HostsProfile.readFromXML(appSettingsFilePath);
                currentHosts = HostsProfile.getCurrentProfile(profiles);
            }
            else
            {
                List <HostsProfile> profiles = new List <HostsProfile>();
                currentHosts = new HostsProfile();
                profiles.Add(currentHosts);
                HostsProfile.writeToSettingsXML(profiles);
            }
            initializeListView();

            selectedProfile = currentHosts;
            customizeHosts(selectedProfile);
            updateListBox();
            listView1.ItemChecked += new ItemCheckedEventHandler(listView_CheckedChanged);



            listView1.CheckBoxes            = true;
            listView1.SubItemClicked       += new ListViewEx.SubItemEventHandler(listView1_SubItemClicked);
            listView1.SubItemEndEditing    += new ListViewEx.SubItemEndEditingEventHandler(listView1_SubItemEndEditing);
            listView1.DoubleClickActivation = false;
        }
Пример #10
0
 private void listBox_hosts_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     setCurrentByIndex(listBox_hosts.SelectedIndex);
     HostsProfile.writeToSettingsXML(profiles);
     WriteHosts();
 }
Пример #11
0
 private void button_save_Click(object sender, EventArgs e)
 {
     HostsProfile.writeToSettingsXML(profiles);
 }
Пример #12
0
 private void listBox_hosts_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedProfile = getProfileByIndex(listBox_hosts.SelectedIndex);
     customizeHosts(selectedProfile);
 }
Пример #13
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     HostsProfile.writeToSettingsXML(profiles);
 }
Пример #14
0
        //private void listHosts_DoubleClick(object sender, EventArgs e) {
        //  if (listHosts.SelectedItem != null) {
        //    m_HostsProvider.ReplaceHosts((string)listHosts.SelectedItem);
        //    lblHosts.Text = (string)listHosts.SelectedItem;
        //    LogInfo("Copied {0} to hosts\r\n", listHosts.SelectedItem);
        //  }
        //}



        private void button_use_as_hosts_Click(object sender, EventArgs e)
        {
            setCurrentByIndex(listBox_hosts.SelectedIndex);
            HostsProfile.writeToSettingsXML(profiles);
            WriteHosts();
        }