public Dictionary <uint, string> ParseRbacEnum() { var result = new Dictionary <uint, string>(); foreach (var rbacLine in coreSourceProvider.ReadLines(TrinityRbacFilePath) .Select(t => t.Trim()) .Between(t => t.StartsWith("/*"), t => t.EndsWith("*/"), true) .Between(t => t.StartsWith("enum RBACPermissions"), t => t.EndsWith("};")) .Where(t => !string.IsNullOrEmpty(t)) .Where(t => !t.StartsWith("//"))) { var match = rbacEnum.Match(rbacLine); if (!match.Success) { continue; } var name = match.Groups[1].Value; var id = uint.Parse(match.Groups[2].Value); result[id] = name; } return(result); }
public IEnumerable <CoreCommand> GetAllCommands() { List <CoreCommand> result = new(); Dictionary <string, List <(string command, string?rbac, string?reference)> > commands = new(); foreach (var cppFilePath in coreSourceProvider.GetFilesInDirectory(commandsPath, "cpp")) { var cppFile = coreSourceProvider.ReadLines(cppFilePath) .Select(line => line.Trim()) .Between(t => t.StartsWith("/*"), t => t.EndsWith("*/"), true) .Where(line => !line.StartsWith("//")) .Between(line => line.Contains("GetCommands() const override"), line => line.StartsWith("return")); string currentGroupName = ""; commands.Clear(); foreach (var line in cppFile) { Match m = ReNewGroup.Match(line); if (m.Success) { currentGroupName = m.Groups[1].Value; commands[currentGroupName] = new(); continue; } m = ReLineNewStyleReference.Match(line); if (m.Success) { var commandPart = m.Groups[1].Value; var childrenList = m.Groups[2].Value; commands[currentGroupName].Add((commandPart, null, childrenList)); continue; } m = ReLineNewStyleCommand.Match(line); if (m.Success) { var commandPart = m.Groups[1].Value; var rbac = m.Groups[3].Value; commands[currentGroupName].Add((commandPart, rbac, null)); continue; } m = ReLineOldStyle.Match(line); if (m.Success) { var commandPart = m.Groups[1].Value; if (m.Groups[5].Length > 0) { var children = m.Groups[5].Value; commands[currentGroupName].Add((commandPart, null, children)); } else { var rbac = m.Groups[2].Value; commands[currentGroupName].Add((commandPart, rbac, null)); } } } if (commands.Count > 0 && !string.IsNullOrEmpty(currentGroupName)) { DenormalizeCommands(commands, "", currentGroupName, result); } } return(result); }