コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (Program.mode == 0)
            {
                if (DeckDevice == null)
                {
                    return;
                }
                int textHeight      = (int)e.Graphics.MeasureString("AaBbCc", Font).Height;
                var backgroundColor = Selected ? ColorSchemeCentral.FromAppTheme(ApplicationSettingsManager.Settings.Theme).SecondaryColor : Color.Transparent;
                using (var sb = new SolidBrush(Selected ? GetReadableForeColor(backgroundColor) : ForeColor)) {
                    if (Selected)
                    {
                        using (var sb2 = new SolidBrush(backgroundColor)) {
                            e.Graphics.FillRectangle(sb2, new Rectangle(Point.Empty, Size));
                        }
                    }
                    e.Graphics.DrawString(deviceNamePrefix + DeckDevice.DeviceName, Font, sb, Padding.Left, Padding.Top);
                    using (var sb2 = new SolidBrush(Color.FromArgb(150, ForeColor))) {
                        e.Graphics.DrawString("ID: " + DeckDevice.DeviceGuid, Font, sb, Padding.Left, Padding.Top + textHeight);
                    }
                }
            }
            else
            {
                if (DeckUsb == null)
                {
                    return;
                }
                int textHeight      = (int)e.Graphics.MeasureString("AaBbCc", Font).Height;
                var backgroundColor = Selected ? ColorSchemeCentral.FromAppTheme(ApplicationSettingsManager.Settings.Theme).SecondaryColor : Color.Transparent;
                using (var sb = new SolidBrush(Selected ? GetReadableForeColor(backgroundColor) : ForeColor))
                {
                    if (Selected)
                    {
                        using (var sb2 = new SolidBrush(backgroundColor))
                        {
                            e.Graphics.FillRectangle(sb2, new Rectangle(Point.Empty, Size));
                        }
                    }
                    e.Graphics.DrawString(DeckUsb.Product + " " + DeckUsb.Model, Font, sb, Padding.Left, Padding.Top);

                    using (var sb2 = new SolidBrush(Color.FromArgb(150, ForeColor)))
                    {
                        string status;
                        if (DevicePersistManager.IsPersistedUsbMode() == true)
                        {
                            status = "Connected";
                        }
                        else
                        {
                            status = "Disconnected";
                        }
                        e.Graphics.DrawString("MODO: USB" + "Persisted: " + status, Font, sb, Padding.Left, Padding.Top + textHeight);
                    }
                }
            }
        }
コード例 #2
0
        public override void Execute(ConnectionState state)
        {
            var device = DevicePersistManager.GetDeckDeviceFromConnectionGuid(state.ConnectionGuid);

            if (PerformedAction != ButtonAction.ButtonClick)
            {
                device.OnButtonInteraction(PerformedAction, SlotID);
            }
        }
コード例 #3
0
        public override void Execute(ConnectionState state)
        {
            DeckDevice deckDevice = new DeckDevice(DeviceGuid, DeviceName);

            DevicePersistManager.PersistDevice(deckDevice);
            DevicePersistManager.ChangeConnectedState(state, deckDevice);


            DevicePersistManager.OnDeviceConnected(this, deckDevice);
            Debug.WriteLine("MOSTRANDO GUID PARA: " + DeviceName);
            Debug.WriteLine("MOSTRANDO GUID PARA: " + DeviceGuid);
        }
コード例 #4
0
        public override void Execute(ConnectionState state)
        {
            DeckDevice deckDevice = new DeckDevice(DeviceGuid, DeviceName);

            DevicePersistManager.PersistDevice(deckDevice);
            DevicePersistManager.ChangeConnectedState(state, deckDevice);

            /*
             * var deckImage = new DeckImage(new System.Drawing.Bitmap("streamdeck_key.png"));
             * var packet = new SlotImageChangeChunkPacket();
             * packet.AddToQueue(1, deckImage);
             * packet.AddToQueue(3, deckImage);
             * packet.AddToQueue(5, deckImage);
             * packet.AddToQueue(15, deckImage);
             * state.SendPacket(packet);*/
            DevicePersistManager.OnDeviceConnected(this, deckDevice);
        }
コード例 #5
0
 public override void OnDropConnection(ConnectionState state)
 {
     state.SendPacket(new DesktopDisconnectPacket());
     DevicePersistManager.RemoveConnectionState(state);
 }
コード例 #6
0
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);
            if (e is MouseEventArgs e2)
            {
                if (Program.mode == 1)
                {
                    if (NameLabelRectangle.Contains(e2.Location))
                    {
                        if (DeckUsb != null)
                        {
                            TextBox txtBox = new TextBox()
                            {
                                Bounds      = NameLabelRectangleWithoutPrefix,
                                Width       = Width - Padding.Right * 2,
                                Text        = DeckUsb.Model,
                                BorderStyle = BorderStyle.None,
                                BackColor   = BackColor,
                                ForeColor   = ForeColor,
                            };
                            txtBox.LostFocus += (s, ee) =>
                            {
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckUsb.Model = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            txtBox.KeyUp += (s, ee) =>
                            {
                                if (ee.KeyCode != Keys.Enter)
                                {
                                    return;
                                }
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckUsb.Model = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            Controls.Add(txtBox);
                            txtBox.Focus();
                        }
                    }
                    else
                    {
                        if (Tag is MainForm frm)
                        {
                            if (DevicePersistManager.IsDeviceTest)
                            {
                                Program.client.RemoveAllForwards(DeckUsb);
                                Program.client.CreateForward(DevicePersistManager.DeviceUsb, $"tcp:{ApplicationSettingsManager.Settings.PORT}", $"tcp:{ApplicationSettingsManager.Settings.PORT}", true);

                                Program.client.ExecuteRemoteCommand("am force-stop net.nickac.DisplayButtons", DeckUsb, null);
                                Thread.Sleep(1400);
                                Program.client.ExecuteRemoteCommand("am start -a android.intent.action.VIEW -e mode 1 net.nickac.DisplayButtons/.MainActivity", DeckUsb, null);
                                Thread.Sleep(1200);
                                Initilizator.ClientThread.Stop();
                                Initilizator.ClientThread = new Misc.ClientThread();
                                Initilizator.ClientThread.Start();
                                //   DevicePersistManager.PersistUsbMode(DeckUsb);
                                //       MainForm.Instance.StartLoad(true);
                                //   MainForm.Instance.Start_configs();
                            }
                            else
                            {
                                //  PersistUsbMode(DeckUsb);
                                Program.client.RemoveAllForwards(DeckUsb);
                                Program.client.CreateForward(DevicePersistManager.DeviceUsb, $"tcp:{ApplicationSettingsManager.Settings.PORT}", $"tcp:{ApplicationSettingsManager.Settings.PORT}", true);

                                Initilizator.ClientThread.Stop();
                                Initilizator.ClientThread = new Misc.ClientThread();
                                Initilizator.ClientThread.Start();
                            }
                        }
                    }
                }
                else
                {
                    if (DeckDevice != null)
                    {
                        if (NameLabelRectangle.Contains(e2.Location))
                        {
                            TextBox txtBox = new TextBox()
                            {
                                Bounds      = NameLabelRectangleWithoutPrefix,
                                Width       = Width - Padding.Right * 2,
                                Text        = DeckDevice.DeviceName,
                                BorderStyle = BorderStyle.None,
                                BackColor   = BackColor,
                                ForeColor   = ForeColor,
                            };
                            txtBox.LostFocus += (s, ee) =>
                            {
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckDevice.DeviceName = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            txtBox.KeyUp += (s, ee) =>
                            {
                                if (ee.KeyCode != Keys.Enter)
                                {
                                    return;
                                }
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckDevice.DeviceName = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            Controls.Add(txtBox);
                            txtBox.Focus();
                        }
                        else
                        {
                            if (Tag is MainForm frm)
                            {
                                if (DevicePersistManager.IsVirtualDeviceConnected)
                                {
                                    Debug.WriteLine("DEVICE MNANAWE 2");
                                    if (frm.CurrentDevice.DeviceGuid == DeckDevice.DeviceGuid)
                                    {
                                        //Someone clicked on the same device. Unload this one.
                                        DevicePersistManager.OnDeviceDisconnected(this, DeckDevice);
                                        DevicePersistManager.IsVirtualDeviceConnected = false;


                                        frm.ChangeButtonsVisibility(false);
                                        frm.CurrentDevice = null;
                                        frm.RefreshAllButtons(false);
                                        frm.Activate();
                                    }
                                    else
                                    {
                                        Debug.WriteLine("DEVICE MNANAWE 2");
                                        //Someone requested another device. Unload current virtual device..
                                        DevicePersistManager.OnDeviceDisconnected(this, frm.CurrentDevice);
                                        DevicePersistManager.IsVirtualDeviceConnected = false;
                                        frm.ChangeButtonsVisibility(false);
                                        frm.CurrentDevice = null;
                                        frm.RefreshAllButtons(false);
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine("DEVICE MNANAWE 3");
                                    frm.CurrentDevice = DeckDevice;
                                    DevicePersistManager.IsVirtualDeviceConnected = true;
                                    DevicePersistManager.OnDeviceConnected(this, DeckDevice);
                                    frm.ChangeButtonsVisibility(true);
                                    frm.RefreshAllButtons(false);
                                    void tempConnected(object s, DevicePersistManager.DeviceEventArgs ee)
                                    {
                                        if (ee.Device.DeviceGuid == DeckDevice.DeviceGuid)
                                        {
                                            return;
                                        }
                                        DevicePersistManager.DeviceConnected -= tempConnected;
                                        if (DevicePersistManager.IsVirtualDeviceConnected)
                                        {
                                            //We had a virtual device.
                                            DevicePersistManager.OnDeviceDisconnected(this, DeckDevice);
                                            DevicePersistManager.IsVirtualDeviceConnected = false;
                                            frm.ChangeButtonsVisibility(false);
                                        }
                                    }

                                    DevicePersistManager.DeviceConnected += tempConnected;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(errorFileName));
            Trace.AutoFlush = true;

            if (args.Any(c => c.ToLower() == "/armobs"))
            {
                if (args.Length == 1)
                {
                    var obs32List = Process.GetProcessesByName("obs32");
                    var obs64List = Process.GetProcessesByName("obs64");
                    if (obs32List.Length == 0 && obs64List.Length == 0)
                    {
                        //No OBS found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);

                        return;
                    }
                    List <Process> obsProcesses = new List <Process>();
                    obsProcesses.AddRange(obs32List);
                    obsProcesses.AddRange(obs64List);

                    if (obsProcesses.Count != 1)
                    {
                        //Multiple OBS instances found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);

                        return;
                    }
                    var obsProcess = obsProcesses.First();

                    string path = OBSUtils.GetProcessPath(obsProcess.Id);


                    string zipTempPath = Path.GetFileNameWithoutExtension(OBSUtils.obswszip);

                    OBSUtils.ExtractZip(OBSUtils.obswszip, zipTempPath);


                    OBSUtils.DirectoryCopy(zipTempPath, OBSUtils.GetPathFromOBSExecutable(path), true);

                    File.Delete(OBSUtils.obswszip);
                    Directory.Delete(zipTempPath, true);

                    var obsGlobalFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "obs-studio", "global.ini");

                    if (File.Exists(obsGlobalFilePath) && !File.ReadAllText(obsGlobalFilePath).Contains("[WebsocketAPI]"))
                    {
                        Trace.WriteLine("File exist and not contain web socket.");
                        while (!obsProcess.HasExited)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALL", Texts.cultereinfo));
                            sb.AppendLine("");
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONAPPLY", Texts.cultereinfo));
                            MessageBox.Show(sb.ToString());
                        }

                        using (StreamWriter outputFile = new StreamWriter(obsGlobalFilePath))
                        {
                            outputFile.WriteLine("");
                            outputFile.WriteLine("[WebsocketAPI]");
                            outputFile.WriteLine("ServerPort=4444");
                            outputFile.WriteLine("DebugEnabled=false");
                            outputFile.WriteLine("AlertsEnabled=false");
                            outputFile.WriteLine("AuthRequired=false");
                        }

                        bool shouldRepeat = true;
                        while (shouldRepeat)
                        {
                            var obs32List2 = Process.GetProcessesByName("obs32");
                            var obs64List2 = Process.GetProcessesByName("obs64");

                            shouldRepeat = obs32List2.Length == 0 && obs64List2.Length == 0;
                            if (!shouldRepeat)
                            {
                                break;
                            }

                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALLSUCESSFULL", Texts.cultereinfo));
                            sb.AppendLine("");
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONCONFIRMOBS", Texts.cultereinfo));
                            MessageBox.Show(sb.ToString());
                        }
                    }

                    return;
                }
            }

#if FORCE_SILENCE
            Silent = true;
#else
            Silent = args.Any(c => c.ToLower() == "/s");
#endif
            const string appName = "DisplayButtons";
            bool         createdNew;

            mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                //app is already running! Exiting the application
                if (MessageBox.Show(Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPEN", Texts.cultereinfo), Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPENTITLE", Texts.cultereinfo), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var myapp = Process.GetProcessesByName(Assembly.GetCallingAssembly().GetName().Name);

                    List <Process> obsProcesses = new List <Process>();
                    obsProcesses.AddRange(myapp);


                    if (obsProcesses.Count > 1)
                    {
                        var last = obsProcesses.First();
                        last.Kill();
                    }
                }
                //return;
            }


            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


            EventXml.LoadSettings();

            ApplicationSettingsManager.LoadSettings();
            Texts.initilizeLang();
            errorText = String.Format(Texts.rm.GetString("INTEGRATIONERROROCURRED", Texts.cultereinfo), errorFileName);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OBSUtils.PrepareOBSIntegration();
            if (ApplicationSettingsManager.Settings.FirstRun)
            {
                FirstSetupForm firstRunForm = new FirstSetupForm();
                Application.Run(firstRunForm);
                if (!firstRunForm.FinishedSetup)
                {
                    return;
                }
            }
            //  EnsureBrowserEmulationEnabled("DisplayButtons.exe");

            new WebBrowserInstanceHelper().SetBrowserFeatureControl();

            dynamic form = Activator.CreateInstance(FindType("DisplayButtons.Forms.ActionHelperForms.MainFormMenuOption")) as Form;

            if (form.ShowDialog() == DialogResult.OK)
            {
                Initilizator.mode         = 0;
                Initilizator.ServerThread = new ServerThread();
                Initilizator.ServerThread.Start();


                Debug.WriteLine("MODO SOCKET CLIENT");
            }
            else
            {
                // Silent = true;
                Debug.WriteLine("MODO USB");
                Initilizator.mode = 1;

                Adbserver = new AdbServer();

                Adbserver.StartServer(Path.Combine(Application.StartupPath, @"Data\adb\adb.exe"), restartServerIfNewer: true);

                monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
                client  = new AdbClient(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort), Factories.AdbSocketFactory);

                monitor.DeviceConnected    += MainForm.DeviceAdbConnected;
                monitor.DeviceDisconnected += MainForm.DeviceAdbDisconnected;
                monitor.Start();



                if (client.GetDevices().Count == 1)
                {
                    Debug.WriteLine("ONE DEVICE");



                    //   client.ExecuteRemoteCommand("am start -a android.intent.action.VIEW -e mode 1 net.nickac.DisplayButtons/.MainActivity", client.GetDevices().First(), null);

                    DevicePersistManager.PersistUsbMode(client.GetDevices().First());
                    //      client.CreateForward(client.GetDevices().First(), "tcp:5095", "tcp:5095", true);

                    Initilizator.ClientThread = new ClientThread();
                    Initilizator.ClientThread.Start();
                }
                else
                {
                    Initilizator.ClientThread = new ClientThread();
                }
            }
            Application.Run(new MainForm());


            //Application.Run(new MainFormMenuOption());
            OBSUtils.Disconnect();
            if (Initilizator.mode == 1)
            {
                foreach (var device in client.GetDevices().ToList())
                {
                    //   client.ExecuteRemoteCommand("am force-stop net.nickac.DisplayButtons", device, null);
                    // client.ExecuteRemoteCommand("kill-server", device, null);

                    //   client.KillAdb();
                }
            }

            //   client.KillAdb();
            EventXml.SaveSettings();
            ApplicationSettingsManager.SaveSettings();
            DevicePersistManager.SaveDevices();

            NetworkChange.NetworkAddressChanged      -= NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged -= NetworkChange_NetworkAddressChanged;
            Trace.Flush();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(errorFileName));
            Trace.AutoFlush = true;

            if (args.Any(c => c.ToLower() == "/armobs"))
            {
                if (args.Length == 1)
                {
                    var obs32List = Process.GetProcessesByName("obs32");
                    var obs64List = Process.GetProcessesByName("obs64");
                    if (obs32List.Length == 0 && obs64List.Length == 0)
                    {
                        //No OBS found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);
                        return;
                    }
                    List <Process> obsProcesses = new List <Process>();
                    obsProcesses.AddRange(obs32List);
                    obsProcesses.AddRange(obs64List);

                    if (obsProcesses.Count != 1)
                    {
                        //Multiple OBS instances found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);
                        return;
                    }
                    var obsProcess = obsProcesses.First();

                    string path        = OBSUtils.GetProcessPath(obsProcess.Id);
                    string zipTempPath = Path.GetFileNameWithoutExtension(OBSUtils.obswszip);
                    OBSUtils.ExtractZip(OBSUtils.obswszip, zipTempPath);

                    OBSUtils.DirectoryCopy(zipTempPath, OBSUtils.GetPathFromOBSExecutable(path), true);
                    File.Delete(OBSUtils.obswszip);
                    Directory.Delete(zipTempPath, true);

                    var obsGlobalFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "obs-studio", "global.ini");
                    if (File.Exists(obsGlobalFilePath) && !File.ReadAllText(obsGlobalFilePath).Contains("[WebsocketAPI]"))
                    {
                        while (!obsProcess.HasExited)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("OBS plugin install completed!");
                            sb.AppendLine("");
                            sb.AppendLine("Please close OBS and click OK to apply the final touches.");
                            MessageBox.Show(sb.ToString());
                        }

                        using (StreamWriter outputFile = new StreamWriter(obsGlobalFilePath)) {
                            outputFile.WriteLine("");
                            outputFile.WriteLine("[WebsocketAPI]");
                            outputFile.WriteLine("ServerPort=4444");
                            outputFile.WriteLine("DebugEnabled=false");
                            outputFile.WriteLine("AlertsEnabled=false");
                            outputFile.WriteLine("AuthRequired=false");
                        }

                        bool shouldRepeat = true;
                        while (shouldRepeat)
                        {
                            var obs32List2 = Process.GetProcessesByName("obs32");
                            var obs64List2 = Process.GetProcessesByName("obs64");

                            shouldRepeat = obs32List2.Length == 0 && obs64List2.Length == 0;
                            if (!shouldRepeat)
                            {
                                break;
                            }

                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("OBS plugin install successfully!");
                            sb.AppendLine("");
                            sb.AppendLine("Please open OBS and click OK to continue to the app.");
                            MessageBox.Show(sb.ToString());
                        }
                    }

                    return;
                }
            }

#if FORCE_SILENCE
            Silent = true;
#else
            Silent = args.Any(c => c.ToLower() == "/s");
#endif
            errorText = $"An error occured! And it was saved to a file called {errorFileName}." + Environment.NewLine + "Please send this to the developer of the application.";

            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            ApplicationSettingsManager.LoadSettings();
            DevicePersistManager.LoadDevices();


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (ApplicationSettingsManager.Settings.FirstRun)
            {
                FirstSetupForm firstRunForm = new FirstSetupForm();
                Application.Run(firstRunForm);
                if (!firstRunForm.FinishedSetup)
                {
                    return;
                }
            }

            OBSUtils.PrepareOBSIntegration();


            NetworkChange.NetworkAddressChanged      += NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAddressChanged;

            ServerThread = new ServerThread();
            ServerThread.Start();

            Application.Run(new MainForm());

            OBSUtils.Disconnect();

            ServerThread.Stop();
            NetworkChange.NetworkAddressChanged      -= NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged -= NetworkChange_NetworkAddressChanged;
            ApplicationSettingsManager.SaveSettings();
            DevicePersistManager.SaveDevices();
            Trace.Flush();
        }