private static int MetaCompare(BethesdaGroup g1, BethesdaGroup g2) { int cmp = g1.GroupType.CompareTo(g2.GroupType); return(cmp == 0 ? g1.Label.CompareTo(g2.Label) : cmp); }
public BethesdaGroupReader(BethesdaGroup group) => this.Group = group;
private static void Compare(BethesdaGroup first, BethesdaGroup second, StringBuilder sb, int indentLevel) { if (Compare(first.RawData, second.RawData) == 0) { return; } string indent = Indent(indentLevel++); sb.Append(indent).AppendLine(first.ToString()); CompareHeaders(new ArraySegment <byte>(first.Start.Array, first.Start.Offset, 24), new ArraySegment <byte>(second.Start.Array, second.Start.Offset, 24), sb, indentLevel); List <BethesdaRecord> firstRecords = new List <BethesdaRecord>(); List <BethesdaGroup> firstGroups = new List <BethesdaGroup>(); BethesdaGroupReader reader = new BethesdaGroupReader(first); BethesdaGroupReaderState state; while ((state = reader.Read()) != BethesdaGroupReaderState.EndOfContent) { switch (state) { case BethesdaGroupReaderState.Record: firstRecords.Add(reader.CurrentRecord); break; case BethesdaGroupReaderState.Subgroup: firstGroups.Add(reader.CurrentSubgroup); break; } } firstRecords.Sort(MetaCompare); firstGroups.Sort(MetaCompare); List <BethesdaRecord> secondRecords = new List <BethesdaRecord>(); List <BethesdaGroup> secondGroups = new List <BethesdaGroup>(); reader = new BethesdaGroupReader(second); while ((state = reader.Read()) != BethesdaGroupReaderState.EndOfContent) { switch (state) { case BethesdaGroupReaderState.Record: secondRecords.Add(reader.CurrentRecord); break; case BethesdaGroupReaderState.Subgroup: secondGroups.Add(reader.CurrentSubgroup); break; } } secondRecords.Sort(MetaCompare); secondGroups.Sort(MetaCompare); int i = 0, j = 0; while (i < firstRecords.Count || j < secondRecords.Count) { if (j == secondRecords.Count || MetaCompare(firstRecords[i], secondRecords[j]) < 0) { sb.Append(indent).AppendLine("OnlyL: " + firstRecords[i++]); } else if (i == firstRecords.Count || MetaCompare(secondRecords[j], firstRecords[i]) < 0) { sb.Append(indent).AppendLine("OnlyR: " + secondRecords[j++]); } else { Compare(firstRecords[i++], secondRecords[j++], sb, indentLevel); } } i = 0; j = 0; while (i < firstGroups.Count || j < secondGroups.Count) { if (j == secondGroups.Count || MetaCompare(firstGroups[i], secondGroups[j]) < 0) { sb.Append(indent).AppendLine("OnlyL: " + firstGroups[i++]); } else if (i == firstGroups.Count || MetaCompare(secondGroups[j], firstGroups[i]) < 0) { sb.Append(indent).AppendLine("OnlyR: " + secondGroups[j++]); } else { Compare(firstGroups[i++], secondGroups[j++], sb, indentLevel); } } }