Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task ProcessBindingsFile(FileInfo bindingsFile)
        {
            if (bindingsFile == null || !bindingsFile.Exists)
            {
                return;
            }

            var content = _fileReader.ReadAllText(bindingsFile);

            if (!IsInCache(bindingsFile, content))
            {
                AddToCache(bindingsFile, content);

                XmlSerializer serializer = new XmlSerializer(typeof(KeyBindings));

                using (StringReader reader = new StringReader(content))
                {
                    _bindings.Raw    = content;
                    _bindings.Active = (KeyBindings)serializer.Deserialize(reader);
                    _bindings.TriggerOnChange();
                }

                BindingsUpdated?.Invoke(this, content);
            }
        }
Exemplo n.º 2
0
 public static void LoadKeybinds()
 {
     if (File.Exists(Path.Combine(MainWindow.AppDataDir, "bindings.dat")))
     {
         try
         {
             using (var f = new FileStream(Path.Combine(MainWindow.AppDataDir, "bindings.dat"), FileMode.Open))
             {
                 Logger.Write("Loading keybind profile");
                 var x = new DataContractSerializer(typeof(KeybindProfile));
                 _keybind = (KeybindProfile)x.ReadObject(f);
             }
         }
         catch
         {
             Logger.Write("No profile found. Loading default keybinds.");
             _keybind = new KeybindProfile {
                 Keybinds = ControllerData.DefaultBinds
             };
         }
     }
     else
     {
         _keybind = new KeybindProfile {
             Keybinds = ControllerData.DefaultBinds
         };
     }
     BindingsUpdated?.Invoke();
 }
Exemplo n.º 3
0
 public static void ResetBinds()
 {
     _keybind          = new KeybindProfile();
     _keybind.Keybinds = new Dictionary <ControllerButton, Key>(ControllerData.DefaultBinds);
     SaveKeybinds();
     BindingsUpdated?.Invoke();
 }
Exemplo n.º 4
0
 public static void SetKeybind(ControllerButton button, Key key)
 {
     foreach (var k in _keybind.Keybinds)
     {
         if (k.Value == key)
         {
             _keybind.Keybinds[k.Key]  = _keybind.Keybinds[button];
             _keybind.Keybinds[button] = key;
             BindingsUpdated?.Invoke();
             return;
         }
     }
     _keybind.Keybinds[button] = key;
     BindingsUpdated?.Invoke();
 }
Exemplo n.º 5
0
 public static void LoadProfile(KeybindProfile profile)
 {
     _keybind = profile;
     BindingsUpdated?.Invoke();
 }