private void Ninty_OnPrefsChange(DevicePrefs prefs) { if (!string.IsNullOrWhiteSpace(prefs.nickname)) { nickname.Content = prefs.nickname; } OnPrefsChange?.Invoke(this, prefs); }
public DevicePrefs GetDevicePreferences(string deviceId) { if (string.IsNullOrEmpty(deviceId)) { return(null); } DevicePrefs prefs = devicePreferences.Find((d) => d.deviceId == deviceId); if (prefs != null) { return(prefs); } if (KnownDevices.Contains(deviceId)) { try { string filePath = DataPath + ToFileName(deviceId) + PREFS_DEVICE_EXT; if (File.Exists(filePath)) { using (StreamReader stream = File.OpenText(filePath)) { JsonSerializer jsonSerializer = new JsonSerializer(); prefs = (DevicePrefs)jsonSerializer.Deserialize(stream, typeof(DevicePrefs)); stream.Close(); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } } if (prefs == null) { prefs = new DevicePrefs { deviceId = deviceId }; KnownDevices.Add(deviceId); SaveDevicePrefs(prefs); Save(); } devicePreferences.Add(prefs); return(prefs); }
public bool SaveDevicePrefs(DevicePrefs devicePrefs) { bool success = false; try { File.WriteAllText(DataPath + ToFileName(devicePrefs.deviceId) + PREFS_DEVICE_EXT, JsonConvert.SerializeObject(devicePrefs, Formatting.Indented)); success = true; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } return(success); }
public void Copy(DevicePrefs other) { if (deviceId != other.deviceId) { return; } defaultProfile = other.defaultProfile; nickname = other.nickname; icon = other.icon; autoConnect = other.autoConnect; calibrationFiles.Clear(); foreach (var calibration in other.calibrationFiles) { calibrationFiles.Add(calibration.Key, calibration.Value); } }
public void Refresh() { // Prevent this method from being spammed if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1) { return; } _lastRefreshTime = DateTime.Now; // Bluetooth Devices var devices = WinBtStream.GetPaths(); // Direct input Devices DInput = new SharpDX.DirectInput.DirectInput(); var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices); foreach (var j in joys) { string pid = j.ProductGuid.ToString().Substring(0, 4); string vid = j.ProductGuid.ToString().Substring(4, 4); // devices to ignore if (vid == "057e" && (pid == "0330" || pid == "0306" || pid == "0337")) { continue; } else if (vid == "1234" && pid == "bead") { continue; } devices.Add(new Shared.DeviceInfo() { InstanceGUID = j.InstanceGuid, PID = pid, VID = vid }); } // GCN Adapter WinUsbStream gcnStream = new WinUsbStream(new UsbDeviceFinder(0x057E, 0x0337)); Shared.DeviceInfo gcnDevice = null; if (gcnStream.DeviceFound()) { gcnDevice = new Shared.DeviceInfo() { VID = "057E", PID = "0337", Type = NintrollerLib.ControllerType.Other }; devices.Add(gcnDevice); } #if DEBUG // Test GCN Device else { devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy GCN", PID = "0337", Type = NintrollerLib.ControllerType.Other }); } // Test Device devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy", Type = NintrollerLib.ControllerType.ProController }); devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy Wiimote", Type = NintrollerLib.ControllerType.Wiimote }); #endif foreach (var info in devices) { // Check if we are already showing this one DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID)); // If not add it if (existing == null) { var status = new DeviceStatus(info, info == gcnDevice ? gcnStream : null); status.ConnectClick = DoConnect; status.TypeUpdated = (s, t) => { var p = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath); string title = ""; if (p != null && !string.IsNullOrWhiteSpace(p.nickname)) { title = p.nickname; } else { title = t.ToString(); } foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeIcon(tab as TabItem, t); ChangeTitle(tab as TabItem, title); } } }; status.CloseTab = (s) => { // Find associated tab, skip first as it is home for (int i = 1; i < tabControl.Items.Count; i++) { var tab = tabControl.Items[i]; if (tab is TabItem && (tab as TabItem).Content == s.Control) { tabControl.Items.RemoveAt(i); break; } } }; status.OnPrefsChange = (s, p) => { if (!string.IsNullOrWhiteSpace(p.nickname)) { foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeTitle(tab as TabItem, p.nickname); } } } }; status.OnRumbleSubscriptionChange = RumbleSettingsChanged; _availableDevices.Add(status); statusStack.Children.Add(status); DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (devicePrefs.autoConnect) { status.AutoConnect(); } } else if (!existing.Connected) { DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (existingPrefs.autoConnect) { existing.AutoConnect(); } } } }
public void Refresh() { // Prevent this method from being spammed if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1) { return; } _lastRefreshTime = DateTime.Now; var devices = WinBtStream.GetPaths(); // Direct input Devices DInput = new SharpDX.DirectInput.DirectInput(); var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices); foreach (var j in joys) { string pid = j.ProductGuid.ToString().Substring(0, 4); string vid = j.ProductGuid.ToString().Substring(4, 4); // devices to ignore if (vid == "057e" && (pid == "0330" || pid == "0306")) { continue; } else if (vid == "1234" && pid == "bead") { continue; } devices.Add(new Shared.DeviceInfo() { InstanceGUID = j.InstanceGuid, PID = pid, VID = vid }); } foreach (var info in devices) { // Check if we are already showing this one DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID)); // If not add it if (existing == null) { var status = new DeviceStatus(info); status.ConnectClick = DoConnect; status.TypeUpdated = (s, t) => { var p = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath); string title = ""; if (p != null && !string.IsNullOrWhiteSpace(p.nickname)) { title = p.nickname; } else { title = t.ToString(); } foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeIcon(tab as TabItem, t); ChangeTitle(tab as TabItem, title); } } }; status.CloseTab = (s) => { // Find associated tab, skip first as it is home for (int i = 1; i < tabControl.Items.Count; i++) { var tab = tabControl.Items[i]; if (tab is TabItem && (tab as TabItem).Content == s.Control) { tabControl.Items.RemoveAt(i); break; } } }; status.OnPrefsChange = (s, p) => { if (!string.IsNullOrWhiteSpace(p.nickname)) { foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeTitle(tab as TabItem, p.nickname); } } } }; _availableDevices.Add(status); statusStack.Children.Add(status); DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (devicePrefs.autoConnect) { status.AutoConnect(); } } else if (!existing.Connected) { DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (existingPrefs.autoConnect) { existing.AutoConnect(); } } } }