Ejemplo n.º 1
0
 public SpecActions(Options options, string edit = null, int editindex = -1)
 {
     InitializeComponent();
     this.options = options;
     lbHoldForBatt.Text = lbHoldForProg.Text = lbHoldFor.Text;
     lbSecsBatt.Text = lbSecsBatt.Text = lbSecsBatt.Text;
     device = options.Device;
     cBProfiles.Items.Add(Resources.noneProfile);
     cBProfiles.SelectedIndex = 0;
     cBActions.SelectedIndex = 0;
     cBPressRelease.SelectedIndex = 0;
     if (Environment.OSVersion.Version.Major >= 10)
     {
         cBActions.Items.Add("Xbox Game DVR");
         cBTapDVR.SelectedIndex = 0;
         cBHoldDVR.SelectedIndex = 2;
         cBDTapDVR.SelectedIndex = 1;
     }
     foreach (object s in options.Root.lBProfiles.Items)
     {
         cBProfiles.Items.Add(s.ToString());
     }
     editIndex = editindex;
     if (edit != string.Empty)
     {
         oldprofilename = edit;
         tBName.Text = edit;
         LoadAction();
         loadingAction = false;
     }
 }
Ejemplo n.º 2
0
        public KBM360(int deviceNum, Options options, Button buttonControl)
        {
            InitializeComponent();
            device             = deviceNum;
            this.options       = options;
            this.buttonControl = buttonControl;
            cBToggle.Checked   = this.buttonControl.Font.Italic;
            cBScanCode.Checked = this.buttonControl.Font.Bold;
            oldSC              = cBScanCode.Location;
            defaultText        = btnDefault.Text;

            if (this.buttonControl.Name.StartsWith("bnShift", StringComparison.Ordinal))
            {
                Console.Write("shift");
                Text = Resources.SelectActionTitle.Replace("*action*", this.buttonControl.Name.Substring(7));
                btnDefault.Text = Resources.FallBack;
            }
            else if (this.buttonControl.Name.StartsWith("bn", StringComparison.Ordinal))
            {
                Text = Resources.SelectActionTitle.Replace("*action*", this.buttonControl.Name.Substring(2));
            }

            foreach (Control control in Controls)
            {
                if (control is Button)
                {
                    ((Button)control).Click += anybtn_Click;
                }
            }

            foreach (Control control in pnl360Controls.Controls)
            {
                if (control is Button)
                {
                    ((Button)control).Click += anybtn_Click;
                }
            }

            if (this.buttonControl.Name.Contains("Touch") || this.buttonControl.Name.Contains("Swipe"))
            {
                btnMOUSEDOWN.Visible  = false;
                btnMOUSELEFT.Visible  = false;
                btnMOUSERIGHT.Visible = false;
                btnMOUSEUP.Visible    = false;
            }

            ActiveControl               = lBMacroOn;
            guideText                   = btnGuide.Text;
            btnGuide.Text               = string.Empty;
            cBShiftButton.SelectedIndex = Global.GetDS4STrigger(device, this.buttonControl.Name);
            cBShiftButton.Items[26]     = this.options.fingerOnTouchpadToolStripMenuItem.Text;
            rBRegular.Checked           = true;
            loading                     = false;

            if (Global.GetDS4KeyType(device, this.buttonControl.Name, false).HasFlag(DS4KeyType.HoldMacro))
            {
                MacroRepeat = true;
            }
        }
Ejemplo n.º 3
0
        public DS4Form(string[] args)
        {
            InitializeComponent();

            isLoading = true;

            saveProfiles.Filter = Resources.XMLFiles + "|*.xml";
            openProfiles.Filter = Resources.XMLFiles + "|*.xml";
            ThemeUtil.SetTheme(lvDebug);
            pads      = new Label[4] { lbPad1, lbPad2, lbPad3, lbPad4 };
            batteries = new Label[4] { lbBatt1, lbBatt2, lbBatt3, lbBatt4 };
            cbs       = new ComboBox[4] { cBController1, cBController2, cBController3, cBController4 };
            ebns      = new Button[4] { bnEditC1, bnEditC2, bnEditC3, bnEditC4 };
            lights    = new Button[4] { bnLight1, bnLight2, bnLight3, bnLight4 };
            statPB    = new PictureBox[4] { pBStatus1, pBStatus2, pBStatus3, pBStatus4 };
            shortcuts = new ToolStripMenuItem[4]
            {
                (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[0],
                (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[1],
                (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[2],
                (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[3]
            };
            SystemEvents.PowerModeChanged += OnPowerChange;
            tSOptions.Visible = false;
            bool firstrun = false;
            if (File.Exists(exepath + "\\Auto Profiles.xml")
                && File.Exists(appDataPpath + "\\Auto Profiles.xml"))
            {
                firstrun = true;
                new SaveWhere(true).ShowDialog();
            }
            else if (File.Exists(exepath + "\\Auto Profiles.xml"))
            {
                Global.SaveWhere(exepath);
            }
            else if (File.Exists(appDataPpath + "\\Auto Profiles.xml"))
            {
                Global.SaveWhere(appDataPpath);
            }
            else if (File.Exists(oldappdatapath + "\\Auto Profiles.xml"))
            {
                try
                {
                    if (Directory.Exists(appDataPpath))
                    {
                        Directory.Move(appDataPpath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows Old");
                    }
                    Directory.Move(oldappdatapath, appDataPpath);
                    Global.SaveWhere(appDataPpath);
                }
                catch
                {
                    MessageBox.Show(Resources.CannotMoveFiles, "DS4Windows");
                    Process.Start("explorer.exe", @"/select, " + appDataPpath);
                    Close();
                    return;
                }
            }
            else if (!File.Exists(exepath + "\\Auto Profiles.xml")
                     && !File.Exists(appDataPpath + "\\Auto Profiles.xml"))
            {
                firstrun = true;
                new SaveWhere(false).ShowDialog();
            }
            if (firstrun)
            {
                CheckDrivers();
            }
            else
            {
                var AppCollectionThread = new Thread(CheckDrivers) { IsBackground = true };
                AppCollectionThread.Start();
            }

            if (string.IsNullOrEmpty(Global.appdatapath))
            {
                Close();
                return;
            }
            Graphics g = CreateGraphics();
            try
            {
                dpix = g.DpiX / 100f * 1.041666666667f;
                dpiy = g.DpiY / 100f * 1.041666666667f;
            }
            finally
            {
                g.Dispose();
            }
            Icon = Resources.DS4W;
            notifyIcon1.Icon = Resources.DS4W;
            Program.RootHub.Debug += On_Debug;

            Log.GuiLog += On_Debug;
            //logWriter = File.AppendText(logFile);
            Log.TrayIconLog += ShowNotification;
            // tmrUpdate.Enabled = true; TODO remove tmrUpdate and leave tick()

            Directory.CreateDirectory(Global.appdatapath);
            Global.Load();
            if (!Global.Save()) //if can't write to file
            {
                if (MessageBox.Show("Cannot write at current location\nCopy Settings to appdata?", "DS4Windows",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    try
                    {
                        Directory.CreateDirectory(appDataPpath);
                        File.Copy(exepath + "\\Profiles.xml", appDataPpath + "\\Profiles.xml");
                        File.Copy(exepath + "\\Auto Profiles.xml", appDataPpath + "\\Auto Profiles.xml");
                        Directory.CreateDirectory(appDataPpath + "\\Profiles");
                        foreach (string s in Directory.GetFiles(exepath + "\\Profiles"))
                        {
                            File.Copy(s, appDataPpath + "\\Profiles\\" + Path.GetFileName(s));
                        }
                    }
                    catch
                    {
                    }
                    MessageBox.Show("Copy complete, please relaunch DS4Windows and remove settings from Program Directory", "DS4Windows");
                    Global.appdatapath = null;
                    Close();
                    return;
                }
                MessageBox.Show("DS4Windows cannot edit settings here, This will now close", "DS4Windows");
                Global.appdatapath = null;
                Close();
                return;
            }
            //MessageBox.Show(Environment.OSVersion.VersionString);
            foreach (ToolStripMenuItem t in shortcuts)
            {
                t.DropDownItemClicked += Profile_Changed_Menu;
            }

            hideDS4CheckBox.Checked = Global.UseExclusiveMode;
            checkHideDS4Fix.Checked = Global.HideDS4Fix;
            cBDisconnectBT.Checked = Global.DCBTatStop;
            cBQuickCharge.Checked = Global.QuickCharge;
            nUDXIPorts.Value = Global.FirstXinputPort;
            Program.RootHub.x360Bus.FirstController = Global.FirstXinputPort;
            // New settings
            Width = Global.FormWidth;
            Height = Global.FormHeight;
            startMinimizedCheckBox.Checked = Global.StartMinimized;
            cBCloseMini.Checked = Global.CloseMini;
            string lang = CultureInfo.CurrentCulture.ToString();
            if (lang.StartsWith("en", StringComparison.Ordinal))
            {
                cBDownloadLangauge.Visible = false;
            }
            cBDownloadLangauge.Checked = Global.DownloadLang;
            cBFlashWhenLate.Checked = Global.FlashWhenLate;
            nUDLatency.Value = Global.FlashWhenLateAt;

            if (!Global.LoadActions()) //if first no actions have been made yet, create PS+Option to D/C and save it to every profile
            {
                XmlDocument xDoc = new XmlDocument();
                try
                {
                    string[] profiles = Directory.GetFiles(Global.appdatapath + @"\Profiles\");
                    foreach (string s in profiles)
                    {
                        if (Path.GetExtension(s) == ".xml")
                        {
                            xDoc.Load(s);
                            XmlNode el = xDoc.SelectSingleNode("DS4Windows/ProfileActions"); //.CreateElement("Action");
                            if (el != null)
                            {
                                if (string.IsNullOrEmpty(el.InnerText))
                                {
                                    el.InnerText = "Disconnect Controller";
                                }
                                else
                                {
                                    el.InnerText += "/Disconnect Controller";
                                }
                            }
                            else
                            {
                                XmlNode node = xDoc.SelectSingleNode("DS4Windows");
                                el = xDoc.CreateElement("ProfileActions");
                                el.InnerText = "Disconnect Controller";
                                node?.AppendChild(el);
                            }
                            xDoc.Save(s);
                            Global.LoadActions();
                        }
                    }
                }
                catch
                {
                }
            }

            bool start = true;
            bool mini = false;

            foreach (string arg in args)
            {
                if (arg == "-stop")
                {
                    start = false;
                }
                if (arg == "-m")
                {
                    mini = true;
                }
                if (mini && start)
                {
                    break;
                }
            }

            if (!(startMinimizedCheckBox.Checked || mini))
            {
                mAllowVisible = true;
                Show();
            }

            Form_Resize(null, null);
            RefreshProfiles();

            options = new Options(this)
            {
                //Text          = "Options for Controller " + (devID + 1);
                Icon            = Icon,
                TopLevel        = false,
                Dock            = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None
            };

            tabProfiles.Controls.Add(options);
            NewVersion();

            for (int i = 0; i < 4; i++)
            {
                Global.LoadProfile(i, true, Program.RootHub);
                lights[i].BackColor = Global.UseCustomLed[i] ? Global.CustomColor[i].ToColorA : Global.MainColor[i].ToColorA;
            }

            LoadAutoProfiles();
            Global.ControllerStatusChange += ControllerStatusChange;
            Enable_Controls(0, false);
            Enable_Controls(1, false);
            Enable_Controls(2, false);
            Enable_Controls(3, false);

            btnStartStop.Text = Resources.StartText;
            if (btnStartStop.Enabled && start)
            {
                ToggleControlService();
            }

            startToolStripMenuItem.Text = btnStartStop.Text;
            if (!tLPControllers.Visible)
            {
                tabMain.SelectedIndex = 1;
            }
            //cBNotifications.Checked = Notifications;
            cBoxNotifications.SelectedIndex = Global.Notifications;
            cBSwipeProfiles.Checked = Global.SwipeProfiles;

            //test.Start();
            hotkeysTimer.Start();
            hotkeysTimer.Tick += Hotkeys;
            test.Tick += test_Tick;
            if (!Directory.Exists(Global.appdatapath + "\\Virtual Bus Driver"))
            {
                linkUninstall.Visible = false;
            }

            if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"))
            {
                return;
            }

            StartWindowsCheckBox.Checked = true;
            string lnkpath = WinProgs.ResolveShortcutAndArgument(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
            if (!lnkpath.EndsWith("-m", StringComparison.Ordinal))
            {
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
                AppShortcutToStartup();
            }
        }