private void Connect(DeviceDescriptor client) { if (currentClient != null) { // Ignore when connected. return; } currentClient = client; var task = clientSocket.Connect(currentClient.ClientHost, currentClient.ClientPort); connectedLabel.Text = "Connected!\r\n\r\n" + currentClient.DeviceName + "\r\n" + currentClient.ClientAddr.ToString() + "\r\n" + currentClient.RefreshRates[0] + "Hz " + currentClient.DefaultWidth + "x" + currentClient.DefaultHeight; autoConnectCheckBox.CheckedChanged -= autoConnectCheckBox_CheckedChanged; autoConnectCheckBox.Checked = clientList.InAutoConnectList(currentClient); autoConnectCheckBox.CheckedChanged += autoConnectCheckBox_CheckedChanged; UpdateResolutionLabel(); ShowConnectedPanel(); UpdateServerStatus(); // To ensure the driver can detect current config (MemoryMappedFile) on startup, // when SteamVR is launched by external. SaveConfig(); }
async private void UpdateClients() { if (!socket.Connected) { UpdateConnectionState(false); return; } string str = await socket.SendCommand("GetConfig"); if (str == "") { UpdateConnectionState(false); return; } logText.Text = str.Replace("\n", "\r\n"); var configs = ParsePacket(str); if (configs["Connected"] == "1") { // Connected UpdateConnectionState(true, configs["ClientName"] + " " + configs["Client"] + " " + configs["RefreshRate"]); connectedLabel.Text = "Connected!\r\n\r\n" + configs["ClientName"] + "\r\n" + configs["Client"] + "\r\n" + configs["RefreshRate"] + " FPS"; autoConnectCheckBox.CheckedChanged -= autoConnectCheckBox_CheckedChanged; autoConnectCheckBox.Checked = clientList.InAutoConnectList(configs["ClientName"], configs["Client"]); autoConnectCheckBox.CheckedChanged += autoConnectCheckBox_CheckedChanged; ShowConnectedPanel(); UpdateClientStatistics(); return; } UpdateConnectionState(false); ShowFindingPanel(); var clients = clientList.ParseRequests(await socket.SendCommand("GetRequests")); foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { // Mark as old data ((ClientTag)row.Tag).updated = false; } foreach (var client in clients) { DataGridViewRow found = null; foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { ClientTag tag1 = ((ClientTag)row.Tag); if (tag1.client.Equals(client)) { found = row; tag1.client = client; tag1.updated = true; } } if (found == null) { int index = dataGridView1.Rows.Add(); found = dataGridView1.Rows[index]; ClientTag tag2 = new ClientTag(); found.Tag = tag2; tag2.client = client; tag2.updated = true; } Color color = Color.Black; if (!client.Online) { color = Color.DarkGray; } found.Cells[0].Style.ForeColor = color; found.Cells[0].Style.SelectionForeColor = color; found.Cells[1].Style.ForeColor = color; found.Cells[1].Style.SelectionForeColor = color; found.Cells[2].Style.ForeColor = color; found.Cells[2].Style.SelectionForeColor = color; found.Cells[0].Value = client.Name; found.Cells[1].Value = client.Address; found.Cells[2].Value = client.Online ? (client.RefreshRate + " FPS") : "Offline"; string buttonLabel = "Connect"; if (!client.Online) { buttonLabel = "Remove"; } else if (!client.VersionOk) { buttonLabel = "Wrong version"; } if ((string)found.Cells[3].Value != buttonLabel) { found.Cells[3].Value = buttonLabel; } } for (int j = dataGridView1.Rows.Count - 1; j >= 0; j--) { // Remove old row ClientTag tag3 = ((ClientTag)dataGridView1.Rows[j].Tag); if (!tag3.updated) { dataGridView1.Rows.RemoveAt(j); } } noClientLabel.Visible = dataGridView1.Rows.Count == 0; var autoConnect = clientList.GetAutoConnectableClient(); if (autoConnect != null) { await clientList.Connect(socket, autoConnect); } }