private void LoadProfile(string profilePath, Holders.Holder h) { Profile loadedProfile = null; if (!string.IsNullOrWhiteSpace(profilePath) && File.Exists(profilePath)) { try { XmlSerializer serializer = new XmlSerializer(typeof(Profile)); using (FileStream stream = File.OpenRead(profilePath)) using (StreamReader reader = new StreamReader(stream)) { loadedProfile = serializer.Deserialize(reader) as Profile; reader.Close(); stream.Close(); } } catch { } } if (loadedProfile == null) { loadedProfile = UserPrefs.Instance.defaultProfile; } if (loadedProfile != null) { for (int i = 0; i < Math.Min(loadedProfile.controllerMapKeys.Count, loadedProfile.controllerMapValues.Count); i++) { h.SetMapping(loadedProfile.controllerMapKeys[i], loadedProfile.controllerMapValues[i]); CheckIR(loadedProfile.controllerMapKeys[i]); } } }
public void SetState(DeviceState newState) { state = newState; if (updateTimer != null) { updateTimer.Dispose(); updateTimer = null; } switch (newState) { case DeviceState.None: btnIdentify.IsEnabled = false; btnProperties.IsEnabled = false; btnXinput.IsEnabled = false; //btnVjoy.IsEnabled = false; btnConfig.IsEnabled = false; btnDetatch.IsEnabled = false; btnConfig.Visibility = Visibility.Hidden; btnDetatch.Visibility = Visibility.Hidden; break; case DeviceState.Discovered: btnIdentify.IsEnabled = true; btnProperties.IsEnabled = true; btnXinput.IsEnabled = true; //btnVjoy.IsEnabled = true; btnConfig.IsEnabled = false; btnDetatch.IsEnabled = false; btnConfig.Visibility = Visibility.Hidden; btnDetatch.Visibility = Visibility.Hidden; break; case DeviceState.Connected_XInput: btnIdentify.IsEnabled = true; btnProperties.IsEnabled = true; btnXinput.IsEnabled = false; //btnVjoy.IsEnabled = false; btnConfig.IsEnabled = true; btnDetatch.IsEnabled = true; btnConfig.Visibility = Visibility.Visible; btnDetatch.Visibility = Visibility.Visible; var xHolder = new Holders.XInputHolder(device.Type); LoadProfile(properties.profile, xHolder); xHolder.ConnectXInput(targetXDevice); holder = xHolder; device.SetPlayerLED(targetXDevice); updateTimer = new System.Threading.Timer(HolderUpdate, device, 1000, UPDATE_SPEED); break; //case DeviceState.Connected_VJoy: // btnIdentify.IsEnabled = true; // btnProperties.IsEnabled = true; // btnXinput.IsEnabled = false; // btnVjoy.IsEnabled = false; // btnConfig.IsEnabled = true; // btnDetatch.IsEnabled = true; // btnConfig.Visibility = System.Windows.Visibility.Visible; // btnDetatch.Visibility = System.Windows.Visibility.Visible; // // Instantiate VJoy Holder (not for 1st release) // break; } }