Пример #1
0
        public static bool ChangeYamlObjectLists(ref List <string> lines, int startLine, ref int endLine, int currentTabDepth,
                                                 BetterDict <string, List <YamlObject> > changeDict)
        {
            int targetStartingSpaces = currentTabDepth * 2;

            for (int i = startLine; i <= endLine; i++)
            {
                string line = lines[i];
                if (!IsKeyValLine(line))
                {
                    continue;
                }

                int lineStartingSpaces = CountStartingSpaces(line);
                if (lineStartingSpaces != targetStartingSpaces)
                {
                    //shouldn't ever leave the targetSection!
                    Console.WriteLine(lineStartingSpaces < targetStartingSpaces
                                                        ? "ChangeYamlObjectLists somehow left the target section!"
                                                        : "ChangeYamlObjectLists somehow entered a subsection!");

                    return(false);
                }

                int    segmentEndLine = GetSegmentEndLineIndex(ref lines, i + 1, currentTabDepth + 1);
                string lineKey        = GetKeyValKey(line);
                if (!changeDict.ContainsKey(lineKey))
                {
                    //go to next segment
                    i = segmentEndLine;
                    continue;
                }

                List <YamlObject> targetList = changeDict[lineKey];
                int initialSegmentEndLine    = segmentEndLine;
                if (!ChangeYamlObjectList(ref lines, i + 1, ref segmentEndLine, currentTabDepth + 1, targetList))
                {
                    Console.WriteLine("failed to save YamlList: " + lineKey);
                    return(false);
                }

                if (segmentEndLine != initialSegmentEndLine)
                {
                    i = segmentEndLine;
                    int delta = segmentEndLine - initialSegmentEndLine;
                    endLine += delta;
                }
                else
                {
                    i = initialSegmentEndLine;
                }
            }

            return(true);
        }
Пример #2
0
        public static bool ChangeSimpleValues(ref List <string> lines, int startLine, ref int endLine, int currentTabDepth,
                                              BetterDict <string, string> changeDict)
        {
            foreach ((string key, string value) in changeDict)
            {
                if (!ChangeSimpleValue(ref lines, startLine, ref endLine, currentTabDepth, key, value))
                {
                    Console.WriteLine("unable to find config key: " + key + " | inserting automatically, formatting might look dumb");
                    string spacing = new string(' ', currentTabDepth * 2);
                    lines.Insert(startLine, spacing + key + ": " + value);
                    endLine++;
                }
            }

            return(true);
        }