예제 #1
0
        // Add patching logic here.
        public void ProcessChunk(PatchChunk chunk, string fileName)
        {
            List <Range> diffs = chunk.CalculateDiffs();

            // For each range in diff
            // If one line, and text is "using System.Runtime.Versioning;" then note
            // Else if multiple lines, and the line after it is "partial class" then remove it
            // Else keep
            // If we removed all bits in diff but the using is gone, also remove it
            DiffsRemaining += diffs.Count;
            foreach (var range in diffs)
            {
                bool processed = false;
                if (range.High - range.Low == 1)
                {
                    switch (chunk.Lines[range.Low].Trim())
                    {
                    case "-using System.Runtime.Versioning;":
                        if (UsingLine != null)
                        {
                            throw new InvalidOperationException("More than one using?");
                        }
                        UsingLine      = range.Low;
                        ChunkWithUsing = chunk;
                        // Flip it now, we'll flip back later if needed
                        // processed = true;
                        break;

                    case "-":
                        // Remove whitespace diff while we're here
                        DiffsRemaining -= 1;
                        processed       = true;
                        break;
                    }
                }
                else
                {
                    // if multiple lines, and the line after it is "partial class" then remove it
                    // Else keep
                    string lineAfterChunk = chunk.Lines [range.High];
                    if (lineAfterChunk.Contains("partial") && lineAfterChunk.Contains("class"))
                    {
                        DiffsRemaining -= 1;
                        processed       = true;
                    }
                }

                if (!processed)
                {
                    for (int i = range.Low; i < range.High; ++i)
                    {
                        chunk.FlipFirstCharacter(i, ' ');
                    }
                }
            }
        }
예제 #2
0
파일: Delta.cs 프로젝트: chamons/patch-iron
        public static void ApplyListToChunk(PatchChunk chunk, Dictionary <int, Delta> deltaList)
        {
            foreach (var kv in deltaList.OrderBy(x => x.Key).Reverse())
            {
                var action = kv.Value.Type;
                switch (action)
                {
                case DeltaType.Addition:
                    chunk.InsertAt(kv.Key, kv.Value.Data);
                    break;

                case DeltaType.AddAfter:
                    chunk.InsertAt(kv.Key + 1, kv.Value.Data);
                    break;

                case DeltaType.Removal:
                    chunk.RemoveAt(kv.Key);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
예제 #3
0
 public void Add(PatchChunk chunk) => Chunks.Add(chunk);