Example #1
0
        public void Save(string name)
        {
            m_Xdoc.Load(m_Profile);
            XmlNode Node;

            Node = m_Xdoc.CreateComment(String.Format(" Auto-Profile Configuration Data. {0} ", DateTime.Now));
            foreach (XmlNode node in m_Xdoc.SelectNodes("//comment()"))
                node.ParentNode.ReplaceChild(Node, node);

            Node = m_Xdoc.SelectSingleNode("Programs");
            string programname;
            programname = Path.GetFileNameWithoutExtension(name);
            XmlElement el = m_Xdoc.CreateElement("Program");
            el.SetAttribute("path", name);
            el.AppendChild(m_Xdoc.CreateElement("Controller1")).InnerText = cBProfile1.Text;
            el.AppendChild(m_Xdoc.CreateElement("Controller2")).InnerText = cBProfile2.Text;
            el.AppendChild(m_Xdoc.CreateElement("Controller3")).InnerText = cBProfile3.Text;
            el.AppendChild(m_Xdoc.CreateElement("Controller4")).InnerText = cBProfile4.Text;
            el.AppendChild(m_Xdoc.CreateElement("TurnOff")).InnerText = cBTurnOffDS4W.Checked.ToString();

            try
            {
                XmlNode oldxmlprocess = m_Xdoc.SelectSingleNode("/Programs/Program[@path=\"" + lBProgramPath.Text + "\"]");
                Node.ReplaceChild(el, oldxmlprocess);
            }
            catch { Node.AppendChild(el); }

            m_Xdoc.AppendChild(Node);
            m_Xdoc.Save(m_Profile);

            if (lVPrograms.SelectedItems.Count > 0)
                lVPrograms.SelectedItems[0].Checked = true;

            form.LoadP();
        }
Example #2
0
        public void Save(ProgramPathItem progPathItem)
        {
            XmlDocument doc = new XmlDocument();
            XmlNode     Node;
            string      newPath, newTitle;

            newPath  = tBPath.Text.Trim();
            newTitle = tBWndTitle.Text;

            if (progPathItem == null || String.IsNullOrEmpty(progPathItem.path) || String.IsNullOrEmpty(newPath))
            {
                return;
            }

            try
            {
                doc.Load(m_Profile);
                Node = doc.CreateComment(String.Format(" Auto-Profile Configuration Data. {0} ", DateTime.Now));
                foreach (XmlNode node in doc.SelectNodes("//comment()"))
                {
                    node.ParentNode.ReplaceChild(Node, node);
                }

                // Find the existing XML program entry using the old path and title value as a search key and replace it with new path and title values (or add a new entry if this was a new program path)
                XmlNode oldxmlprocess = FindProgramXMLItem(doc, progPathItem.path, progPathItem.title);
                Node = doc.SelectSingleNode("Programs");

                XmlElement el = doc.CreateElement("Program");
                el.SetAttribute("path", newPath);
                if (!String.IsNullOrEmpty(newTitle))
                {
                    el.SetAttribute("title", newTitle);
                }

                el.AppendChild(doc.CreateElement("Controller1")).InnerText = cBProfile1.Text;
                el.AppendChild(doc.CreateElement("Controller2")).InnerText = cBProfile2.Text;
                el.AppendChild(doc.CreateElement("Controller3")).InnerText = cBProfile3.Text;
                el.AppendChild(doc.CreateElement("Controller4")).InnerText = cBProfile4.Text;
                el.AppendChild(doc.CreateElement("TurnOff")).InnerText     = cBTurnOffDS4W.Checked.ToString();

                if (oldxmlprocess != null)
                {
                    Node.ReplaceChild(el, oldxmlprocess);
                }
                else
                {
                    Node.AppendChild(el);
                }

                doc.AppendChild(Node);
                doc.Save(m_Profile);

                if (selectedProgramPathItem != null)
                {
                    selectedProgramPathItem.path  = newPath;
                    selectedProgramPathItem.title = newTitle;
                }

                if (lVPrograms.SelectedItems.Count > 0)
                {
                    lVPrograms.SelectedItems[0].Checked = true;

                    lVPrograms.SelectedItems[0].SubItems[0].Text = Path.GetFileNameWithoutExtension(newPath);
                    lVPrograms.SelectedItems[0].SubItems[1].Text = newPath;
                    if (lVPrograms.SelectedItems[0].SubItems.Count < 3)
                    {
                        if (!String.IsNullOrEmpty(newTitle))
                        {
                            lVPrograms.SelectedItems[0].SubItems.Add(newTitle);
                        }
                    }
                    else
                    {
                        lVPrograms.SelectedItems[0].SubItems[2].Text = newTitle;
                    }

                    if (!String.IsNullOrEmpty(newTitle))
                    {
                        lVPrograms.SelectedItems[0].ToolTipText = $"{newPath}  [{newTitle}]";
                    }
                    else
                    {
                        lVPrograms.SelectedItems[0].ToolTipText = newPath;
                    }
                }

                form.LoadP();
            }
            catch (Exception e)
            {
                // Eat all exceptions while writing auto-profile file because we don't want to crash DS4Win app just because there are some permissions or other issues with the file
                AppLogger.LogToGui($"ERROR. Auto-profile XML file {Global.appdatapath}\\Auto Profiles.xml writing failed. {e.Message}", true);
            }
        }