Пример #1
0
        public static void SendKeystrokesForCallbackName(string callbackName, KeyFile keyFile)
        {
            var keyBinding = keyFile.GetBindingForCallback(callbackName) as KeyBinding;

            if (keyBinding == null)
            {
                return;
            }
            SendKeystrokesForKeyBinding(keyBinding);
        }
Пример #2
0
        public static KeyFile Load(string fileName, Encoding encoding)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            var file    = new FileInfo(fileName);
            var keyFile = new KeyFile {
                FileName = file.FullName, _encoding = encoding
            };

            using (var sr = new StreamReader(file.FullName, encoding))
            {
                var lineNum = 0;
                while (!sr.EndOfStream)
                {
                    lineNum++;
                    var currentLine = sr.ReadLine();
                    if (currentLine != null)
                    {
                        var currentLineTrim = currentLine.Trim();
                        if (currentLineTrim.TrimStart().StartsWith("/") || currentLineTrim.TrimStart().StartsWith("#"))
                        {
                            keyFile._lines.Add(new CommentLine(currentLine)
                            {
                                LineNum = lineNum
                            });
                            continue;
                        }
                    }

                    var tokenList = Util.Tokenize(currentLine);
                    if (tokenList == null || tokenList.Count == 0)
                    {
                        keyFile._lines.Add(new BlankLine()
                        {
                            LineNum = lineNum
                        });
                        continue;
                    }

                    try
                    {
                        int token3;
                        Int32.TryParse(tokenList[2], out token3);
                        if (token3 == -1 || token3 == -2 || token3 == -4 || token3 == 8)
                        {
                            DirectInputBinding directInputBinding;
                            var parsed = DirectInputBinding.TryParse(currentLine, out directInputBinding);
                            if (!parsed)
                            {
                                keyFile._lines.Add(new UnparsableLine(currentLine)
                                {
                                    LineNum = lineNum
                                });
                                continue;
                            }
                            directInputBinding.LineNum = lineNum;
                            keyFile._lines.Add(directInputBinding);
                        }
                        else
                        {
                            KeyBinding keyBinding;
                            var        parsed = KeyBinding.TryParse(currentLine, out keyBinding);
                            if (!parsed)
                            {
                                keyFile._lines.Add(new UnparsableLine(currentLine)
                                {
                                    LineNum = lineNum
                                });
                                continue;
                            }
                            keyBinding.LineNum = lineNum;
                            keyFile._lines.Add(keyBinding);
                        }
                    }
                    catch (Exception e)
                    {
                        keyFile._lines.Add(new UnparsableLine(currentLine)
                        {
                            LineNum = lineNum
                        });
                        Log.Error($"Line {lineNum} in key file {file.FullName} could not be parsed.", e);
                    }
                }
            }
            keyFile.UpdateIndexOfCallbacks();
            return(keyFile);
        }
Пример #3
0
 public static void SendKeystrokesForCallback(Callbacks callback, KeyFile keyFile)
 {
     SendKeystrokesForCallbackName(callback.ToString(), keyFile);
 }