예제 #1
0
        public static void InitializeVJoyDevice(uint vJoyID, HID_USAGES axis)
        {
            lock (vJoyLocker)
            {
                if (vJoyInitialized)
                {
                    return;
                }

                vJoyInitialized = true;
                AppLogger.LogToGui("Initializing VJoy virtual joystick driver via vJoyInterface.dll interface", false);

                try
                {
                    if (vJoyObj == null)
                    {
                        vJoyObj = new VJoy();
                    }

                    if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis))
                    {
                        AppLogger.LogToGui("Connection to VJoy virtual joystick established", false);
                        AppLogger.LogToGui($"VJoy driver. Vendor={vJoyObj.GetvJoyManufacturerString()}  Product={vJoyObj.GetvJoyProductString()}  Version={vJoyObj.GetvJoySerialNumberString()}  Device#={vJoyID}  Axis={axis}", false);

                        // Test if DLL matches the driver
                        UInt32 DllVer = 0, DrvVer = 0;
                        if (!vJoyObj.DriverMatch(ref DllVer, ref DrvVer))
                        {
                            AppLogger.LogToGui("WARNING. VJoy version of Driver {DrvVer}) does not match interface DLL Version {DllVer}. This may lead to unexpected problems or crashes. Update VJoy driver and vJoyInterface.dll", false);
                        }

                        VjdStat status = vJoyObj.GetVJDStatus(vJoyID);
                        if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vJoyObj.AcquireVJD(vJoyID))))
                        {
                            vJoyAvailable = false;
                            AppLogger.LogToGui("ERROR. Failed to acquire vJoy device# {vJoyID}. Use another VJoy device or make sure there are no other VJoy feeder apps using the same device", false);
                        }
                        else
                        {
                            //vJoyObj.GetVJDAxisMax(vJoyID, axis, ref vJoyAxisMaxValue);
                            //AppLogger.LogToGui($"VJoy axis {axis} max value={vJoyAxisMaxValue}", false);
                            vJoyObj.ResetVJD(vJoyID);
                            vJoyAvailable = true;
                        }
                    }
                    else
                    {
                        vJoyAvailable = false;
                        AppLogger.LogToGui($"ERROR. VJoy device# {vJoyID} or {axis} axis not available. Check vJoy driver installation and configuration", false);
                    }
                }
                catch
                {
                    vJoyAvailable = false;
                    AppLogger.LogToGui("ERROR. vJoy initialization failed. Make sure that DS4Windows application can find vJoyInterface.dll library file", false);
                }
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
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);
            }
        }
예제 #5
0
        int AddLoadedApps(bool autoremoveSetupApps = true)
        {
            int numOfAppsAdded = 0;

            if (appsloaded)
            {
                bnAddPrograms.Text = Properties.Resources.AddingToList;

                if (autoremoveSetupApps)
                {
                    for (int i = lodsf.Count - 1; i >= 0; i--)
                    {
                        if (lodsf[i].Contains("etup") || lodsf[i].Contains("dotnet") || lodsf[i].Contains("SETUP") ||
                            lodsf[i].Contains("edist") || lodsf[i].Contains("nstall") || String.IsNullOrEmpty(lodsf[i]))
                        {
                            lodsf.RemoveAt(i);
                        }
                    }

                    // Remove existing program entries from a list of new app paths (no need to add the same path twice)
                    for (int i = lodsf.Count - 1; i >= 0; i--)
                    {
                        for (int j = 0; j < lVPrograms.Items.Count; j++)
                        {
                            if (string.Equals(lVPrograms.Items[j].SubItems[1].Text, lodsf[i], StringComparison.OrdinalIgnoreCase))
                            {
                                lodsf.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }

                try
                {
                    ListViewItem lvi;
                    int          index;

                    lVPrograms.BeginUpdate();
                    foreach (string st in lodsf)
                    {
                        if (File.Exists(st))
                        {
                            index = iLIcons.Images.IndexOfKey(st);
                            if (index < 0)
                            {
                                iLIcons.Images.Add(st, Icon.ExtractAssociatedIcon(st));
                                index = iLIcons.Images.Count - 1;
                            }

                            if (index >= 0)
                            {
                                lvi = new ListViewItem(Path.GetFileNameWithoutExtension(st), index);
                            }
                            else
                            {
                                lvi = new ListViewItem(Path.GetFileNameWithoutExtension(st));
                            }

                            lvi.SubItems.Add(st);
                            lvi.ToolTipText = st;
                            lVPrograms.Items.Add(lvi);
                            numOfAppsAdded++;
                        }
                    }
                }
                catch (Exception e)
                {
                    // Eat all exceptions while processing added apps 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 add selected applications to an auto-profile list. {e.Message}", true);
                }
                finally
                {
                    lVPrograms.EndUpdate();

                    bnAddPrograms.Text    = Properties.Resources.AddPrograms;
                    bnAddPrograms.Enabled = true;
                    appsloaded            = false;
                }
            }

            return(numOfAppsAdded);
        }
예제 #6
0
        public void LoadP()
        {
            try
            {
                XmlDocument doc = new XmlDocument();

                iLIcons.Images.Clear();
                if (!File.Exists(Global.appdatapath + "\\Auto Profiles.xml"))
                {
                    return;
                }

                doc.Load(Global.appdatapath + "\\Auto Profiles.xml");
                XmlNodeList programslist = doc.SelectNodes("Programs/Program");

                int          index;
                ListViewItem lvi;
                string       progPath, progTitle;

                lVPrograms.BeginUpdate();
                foreach (XmlNode progNode in programslist)
                {
                    progPath  = progNode.Attributes["path"]?.Value;
                    progTitle = progNode.Attributes["title"]?.Value;

                    if (!string.IsNullOrEmpty(progPath))
                    {
                        index = iLIcons.Images.IndexOfKey(progPath);
                        if (index < 0 && File.Exists(progPath))
                        {
                            iLIcons.Images.Add(progPath, Icon.ExtractAssociatedIcon(progPath));
                            index = iLIcons.Images.Count - 1;
                        }

                        if (index >= 0)
                        {
                            lvi = new ListViewItem(Path.GetFileNameWithoutExtension(progPath), index);
                        }
                        else
                        {
                            lvi = new ListViewItem(Path.GetFileNameWithoutExtension(progPath));
                        }

                        lvi.Checked = true;
                        lvi.SubItems.Add(progPath);
                        if (!String.IsNullOrEmpty(progTitle))
                        {
                            lvi.SubItems.Add(progTitle);
                        }

                        lVPrograms.Items.Add(lvi);
                    }
                }
            }
            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. Auto-profile XML file {Global.appdatapath}\\Auto Profiles.xml reading failed. {e.Message}", true);
            }
            finally
            {
                lVPrograms.EndUpdate();
            }
        }