Example #1
0
        private void SendConfig(GamepadConfig gpc, string fileName)
        {
            // Thank you all!
            HttpWebRequest r = WebRequest.Create("http://stridetechnologies.net/padtie/submit-dmap.php") as HttpWebRequest;

            r.Method      = "POST";
            r.ContentType = "application/x-www-form-urlencoded";
            string data;

            using (var sr = new StreamReader(fileName))
                data = string.Format("id={1}&config={0}", Uri.EscapeDataString(sr.ReadToEnd()).Replace("%20", "+"),
                                     gpc.DeviceID);

            byte[] d = Encoding.ASCII.GetBytes(data);
            using (var st = r.GetRequestStream())
                st.Write(d, 0, d.Length);
            HttpWebResponse resp = null;

            try {
                resp = r.GetResponse() as HttpWebResponse;

                if (resp.StatusCode == HttpStatusCode.NoContent)
                {
                    MessageBox.Show("Thank you for submitting the new mapping!");
                }
                else
                {
                    string rs;
                    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                        rs = sr.ReadToEnd();

                    MessageBox.Show("Could not contact upload server :-( : " + resp.StatusCode +
                                    Environment.NewLine + Environment.NewLine + rs);
                }
            } catch (WebException e2) {
                string rs;
                using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                    rs = sr.ReadToEnd();

                MessageBox.Show("An error occurred while sending the mapping :-( : " + e2.Message + Environment.NewLine + Environment.NewLine + rs);
            }
            if (resp != null)
            {
                resp.Close();
            }
        }
Example #2
0
        private void startBtn_Click(object sender, EventArgs e)
        {
            if (page == 1)
            {
                page = 2;
                page2.BringToFront();
                pbar.Visible     = true;
                startBtn.Enabled = false;
                startBtn.Text    = "Finish";
                ButtonSpot[] buttonSpots = new[] {
                    new ButtonSpot(VirtualController.Button.Bl, 70, 119),
                    new ButtonSpot(VirtualController.Button.Br, 199, 119),
                    new ButtonSpot(VirtualController.Button.Tl, 70, 91),
                    new ButtonSpot(VirtualController.Button.Tr, 199, 91),
                    new ButtonSpot(VirtualController.Button.A, 204, 86),
                    new ButtonSpot(VirtualController.Button.B, 222, 67),
                    new ButtonSpot(VirtualController.Button.X, 185, 67),
                    new ButtonSpot(VirtualController.Button.Y, 204, 49),
                    new ButtonSpot(VirtualController.Button.Start, 160, 69),
                    new ButtonSpot(VirtualController.Button.Back, 110, 69),
                    new ButtonSpot(VirtualController.Button.System, 135, 69),
                    new ButtonSpot(VirtualController.Button.LeftAnalog, 67, 67),
                    new ButtonSpot(VirtualController.Button.RightAnalog, 167, 107),
                };

                AxisSpot[] axisSpots = new[] {
                    new AxisSpot(VirtualController.Axis.Trigger, 70, 91),
                    new AxisSpot(VirtualController.Axis.LeftY, 67, 53),
                    new AxisSpot(VirtualController.Axis.LeftX, 52, 65),
                    new AxisSpot(VirtualController.Axis.DigitalY, 99, 94),
                    new AxisSpot(VirtualController.Axis.DigitalX, 85, 108),
                    new AxisSpot(VirtualController.Axis.RightY, 167, 94),
                    new AxisSpot(VirtualController.Axis.RightX, 154, 107),
                };

                // Adjust by the design-time location of the image...
                var pos = new Point(13, 25);

                foreach (var spot in buttonSpots)
                {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                foreach (var spot in axisSpots)
                {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                front.Hide();
                remainingBtnSpots = new List <ButtonSpot>();
                remainingBtnSpots.AddRange(buttonSpots);
                remainingAxisSpots = new List <AxisSpot>();
                remainingAxisSpots.AddRange(axisSpots);

                foreach (var btn in Controller.Device.Buttons)
                {
                    btn.PressReceived += buttonPressed;
                }

                foreach (var axis in Controller.Device.Axes)
                {
                    axis.EnableGestures = true;
                    axis.PositivePress += axisPressed;
                    axis.NegativePress += axisPressed;
                }

                Controller.Virtual.Enabled = false;

                indicator.Tag      = "on";
                indicator.Location = new Point(front.Left + remainingBtnSpots[0].X, front.Top + remainingBtnSpots[0].Y);

                progress.Text    += " - Product: " + Controller.Device.ProductName + "\n";
                noHaveBtn.Enabled = true;
            }
            else
            {
                Controller.Virtual.Enabled = true;

                foreach (var btn in Controller.Device.Buttons)
                {
                    btn.PressReceived -= buttonPressed;
                }

                foreach (var axis in Controller.Device.Axes)
                {
                    axis.EnableGestures = false;
                    axis.PositivePress -= axisPressed;
                    axis.NegativePress -= axisPressed;
                }

                GamepadConfig gpc      = new GamepadConfig();
                string        deviceID = Controller.Device.VendorID.ToString("X4") + Controller.Device.ProductID.ToString("X4");
                gpc.DeviceID = "0x" + deviceID.ToLower();
                gpc.Mappings = mappings;
                gpc.Notes    = "Created by Pad Tie's Mapping Wizard!";
                gpc.Product  = Controller.Device.ProductName;
                gpc.Vendor   = "";
                var    myModcumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var    gpcFolder          = Path.Combine("Pad Tie", "gamepads");
                string fileName           = Path.Combine(Path.Combine(myModcumentsFolder, gpcFolder), gpc.DeviceID + ".xml");

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }

                if (File.Exists(fileName))
                {
                    fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "gamepads");
                    fileName = Path.Combine(fileName, gpc.DeviceID + "-autogen.xml");
                }

                try {
                    gpc.Save(fileName);
                } catch (UnauthorizedAccessException e2) {
                    MessageBox.Show("Failed to save mapping for later use. Your gamepad will still work. Message: " + e2.Message);
                }

                if (sendPermission.Checked)
                {
                    SendConfig(gpc, fileName);
                }


                Controller.DeviceConfig.Mappings = gpc.Mappings;
                //Controller.Device.Reset();

                foreach (var dm in gpc.Mappings)
                {
                    if (dm.Source.StartsWith("button:"))
                    {
                        int btn = int.Parse(dm.Source.Substring("button:".Length));
                        VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), dm.Destination);
                        var ba = new VirtualController.ButtonAction(Controller.Virtual, b);

                        if (dm.Gesture != "Link" && dm.Gesture != "" && dm.Gesture != null)
                        {
                            // We need to enable gesture support at the device level for this button
                            Controller.Device.Buttons[btn].EnableGestures = true;
                        }

                        switch (dm.Gesture)
                        {
                        case "Link":
                        case null:
                        case "":
                            Controller.Device.Buttons[btn].Link = ba;
                            break;

                        case "Tap":
                            Controller.Device.Buttons[btn].Tap = ba;
                            break;

                        case "DoubleTap":
                            Controller.Device.Buttons[btn].DoubleTap = ba;
                            break;

                        case "Hold":
                            Controller.Device.Buttons[btn].Hold = ba;
                            break;
                        }
                    }
                    else
                    {
                        int axis = int.Parse(dm.Source.Substring("axis:".Length));
                        VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), dm.Destination);
                        Controller.Device.Axes[axis].Analog = new VirtualController.AxisAction(Controller.Virtual, a);
                    }
                }
                MainForm.GlobalConfig.Save();
                this.Close();
            }
        }