private void UpdateProfileComboListValues(ProgramPathItem progItem) { if (progItem != null) { for (int i = 0; i < 4; i++) { cbs[i].Enabled = true; } tBPath.Enabled = tBWndTitle.Enabled = cBTurnOffDS4W.Enabled = true; LoadP(progItem); bnDelete.Enabled = true; } else { int last = cbs[0].Items.Count - 1; // Set all profile combox values to "none" value (ie. the last item in a controller combobox list) for (int i = 0; i < 4; i++) { cbs[i].Enabled = false; if (cbs[i].SelectedIndex != last) { cbs[i].SelectedIndex = last; } } bnSave.Enabled = bnDelete.Enabled = false; tBPath.Enabled = tBWndTitle.Enabled = cBTurnOffDS4W.Enabled = false; tBPath.Text = tBWndTitle.Text = ""; cBTurnOffDS4W.Checked = false; } }
private void lBProgramPath_SelectedIndexChanged(object sender, EventArgs e) { if (lVPrograms.SelectedItems.Count > 0 && lVPrograms.SelectedIndices[0] > -1) { if (selectedProgramPathItem == null) { selectedProgramPathItem = new ProgramPathItem(String.Empty, String.Empty); } selectedProgramPathItem.path = lVPrograms.SelectedItems[0].SubItems[1].Text; if (lVPrograms.SelectedItems[0].SubItems.Count >= 3) { selectedProgramPathItem.title = lVPrograms.SelectedItems[0].SubItems[2].Text; } else { selectedProgramPathItem.title = String.Empty; } UpdateProfileComboListValues(selectedProgramPathItem); } else { selectedProgramPathItem = null; UpdateProfileComboListValues(null); } }
private void bnDelete_Click(object sender, EventArgs e) { RemoveP(selectedProgramPathItem, true); selectedProgramPathItem = null; bnSave.Enabled = bnDelete.Enabled = false; if (lVPrograms.SelectedItems.Count > 0) { lVPrograms.SelectedItems[0].Selected = lVPrograms.SelectedItems[0].Focused = false; } }
private void bnHideUnchecked_Click(object sender, EventArgs e) { // Remove all unchecked items from autoprofile XML file and listView list foreach (ListViewItem lvi in lVPrograms.Items) { if (!lvi.Checked) { RemoveP(new ProgramPathItem(lvi.SubItems[1]?.Text, (lvi.SubItems.Count >= 3 ? lvi.SubItems[2]?.Text : null)), false); } } selectedProgramPathItem = null; form.RefreshAutoProfilesPage(); }
public void RemoveP(ProgramPathItem removeProgPathItem, bool uncheck) { bnSave.Enabled = false; if (removeProgPathItem == null) { return; } try { XmlDocument doc = new XmlDocument(); doc.Load(m_Profile); XmlNode programItem = FindProgramXMLItem(doc, removeProgPathItem.path, removeProgPathItem.title); if (programItem != null) { XmlNode parentNode = programItem.ParentNode; if (parentNode != null) { parentNode.RemoveChild(programItem); doc.AppendChild(parentNode); doc.Save(m_Profile); } } if (lVPrograms.SelectedItems.Count > 0 && uncheck) { lVPrograms.SelectedItems[0].Checked = false; } } catch (Exception e) { // Eat all exceptions while updating 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. Failed to remove {removeProgPathItem.path} {removeProgPathItem.title} XML entry. {e.Message}", true); } UpdateProfileComboListValues(null); }
public void LoadP(ProgramPathItem loadProgPathItem) { if (loadProgPathItem == null) { return; } try { XmlDocument doc = new XmlDocument(); doc.Load(m_Profile); XmlNode programItem = FindProgramXMLItem(doc, loadProgPathItem.path, loadProgPathItem.title); if (programItem != null) { XmlNode profileItem; for (int i = 0; i < 4; i++) { profileItem = programItem.SelectSingleNode($".//Controller{i + 1}"); if (profileItem != null) { for (int j = 0; j < cbs[i].Items.Count; j++) { if (cbs[i].Items[j].ToString() == profileItem.InnerText) { cbs[i].SelectedIndex = j; break; } else { cbs[i].SelectedIndex = cbs[i].Items.Count - 1; } } } else { cbs[i].SelectedIndex = cbs[i].Items.Count - 1; } } bool turnOff; profileItem = programItem.SelectSingleNode($".//TurnOff"); if (profileItem != null && bool.TryParse(profileItem.InnerText, out turnOff)) { cBTurnOffDS4W.Checked = turnOff; } else { cBTurnOffDS4W.Checked = false; } } tBPath.Text = loadProgPathItem.path; tBWndTitle.Text = loadProgPathItem.title; } catch (Exception e) { // Eat all exceptions while reading 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. Failed to read {loadProgPathItem.path} {loadProgPathItem.title} XML entry. {e.Message}", true); } bnSave.Enabled = false; }
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); } }
public WinProgs(string[] oc, DS4Form main) { ToolTip tp = new ToolTip(); InitializeComponent(); openProgram.Filter = Properties.Resources.Programs + "|*.exe|" + Properties.Resources.Shortcuts + "|*.lnk"; form = main; cbs = new ComboBox[4] { cBProfile1, cBProfile2, cBProfile3, cBProfile4 }; for (int i = 0; i < 4; i++) { cbs[i].Items.AddRange(oc); cbs[i].Items.Add(Properties.Resources.noneProfile); cbs[i].SelectedIndex = cbs[i].Items.Count - 1; } tp.SetToolTip(cBAutoProfileDebugLog, Properties.Resources.ShowAutoProfileDebugLogTip); tp.SetToolTip(tBPath, Properties.Resources.AutoProfilePathAndWindowTitleEditTip); tp.SetToolTip(tBWndTitle, Properties.Resources.AutoProfilePathAndWindowTitleEditTip); if (!File.Exists(Global.appdatapath + @"\Auto Profiles.xml")) { Create(); } LoadP(); if (UseCustomSteamFolder && Directory.Exists(CustomSteamFolder)) { steamgamesdir = CustomSteamFolder; } else if (Directory.Exists(steamCommx86Loc)) { steamgamesdir = steamCommx86Loc; } else if (Directory.Exists(steamCommLoc)) { steamgamesdir = steamCommLoc; } else { cMSPrograms.Items.Remove(addSteamGamesToolStripMenuItem); } if (Directory.Exists(originx86Loc)) { origingamesdir = originx86Loc; } else if (Directory.Exists(originLoc)) { origingamesdir = originLoc; } else { cMSPrograms.Items.Remove(addOriginGamesToolStripMenuItem); } cBAutoProfileDebugLog.Checked = (DS4Form.autoProfileDebugLogLevel > 0); selectedProgramPathItem = null; UpdateProfileComboListValues(null); }