Beispiel #1
0
        public void MergeFiles(string filename, string newFilename, string out_filename)
        {
            try
            {
                List <MethodContent> methods     = ReadFileMethods(filename);
                List <MethodContent> new_methods = ReadFileMethods(newFilename);

                using (StringWriter file = new StringWriter())
                {
                    foreach (MethodContent method in new_methods)
                    {
                        MethodContent.Write(file, method.pre);

                        MethodContent old_method = FindMethod(methods, method.old_name);

                        if (old_method == null)
                        {
                            old_method = method;
                        }

                        MethodContent.Write(file, old_method.codes);
                    }

                    UpdateFile(file, out_filename);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Diff Error : {0} {1}", filename, e.Message);
            }
        }
Beispiel #2
0
        private static List <MethodContent> ReadFileMethods(string filename)
        {
            List <MethodContent> methods = new List <MethodContent>();

            using (StreamReader file = new StreamReader(filename))
            {
                while (true)
                {
                    MethodContent method = ReadItem(file);

                    if (method != null)
                    {
                        methods.Add(method);

                        if (methods.Count == 1 && string.IsNullOrEmpty(method.name))
                        {
                            method.name     = "init_part";
                            method.old_name = method.name;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (methods.Count > 1)
                {
                    MethodContent lastMethod = methods[methods.Count - 1];

                    if (string.IsNullOrEmpty(lastMethod.name))
                    {
                        lastMethod.name     = "uninit_part";
                        lastMethod.old_name = lastMethod.name;
                    }
                }

                return(methods);
            }
        }
Beispiel #3
0
        private static MethodContent ReadItem(StreamReader file)
        {
            List <string> lines = new List <string>();

            string line = Readline(file, ref lines);

            if (line == null)
            {
                return(null);
            }

            int    lastIndex = -1;
            string name      = "";
            string old_name  = "";

            while (line != null && !StartsWith(item_begin, line))
            {
                line = Readline(file, ref lines);

                if (line == null)
                {
                    break;
                }

                // old format
                bool bHasItemHead = false;

                // method header
                if (StartsWith(item_head, line))
                {
                    line         = Readline(file, ref lines);
                    bHasItemHead = true;
                }

                // last name
                if (StartsWith(method_head_old_name, line))
                {
                    old_name = ReadMethodOldName(line);

                    //don't include last name
                    lastIndex = lines.Count - 1;
                    lines.RemoveAt(lastIndex);

                    // skip last name
                    line = Readline(file, ref lines);
                }

                if (bHasItemHead)
                {
                    // old format
                    name = ReadMethodName(line);

                    if (string.IsNullOrEmpty(old_name))
                    {
                        old_name = name;
                    }
                }
            }

            if (line != null)
            {
                string item_name = "";

                if (StartsWith(item_begin, line, out item_name))
                {
                    name = item_name;

                    if (string.IsNullOrEmpty(old_name))
                    {
                        old_name = name;
                    }
                }

                //don't include item_begin
                lastIndex = lines.Count - 1;
                lines.RemoveAt(lastIndex);

                MethodContent method = new MethodContent(name, old_name);

                method.pre = lines;

                // add item_begin
                method.Add(line);
                line = Readline(file, ref method.codes);

                while (!StartsWith(item_end, line))
                {
                    line = Readline(file, ref method.codes);
                }

                // item_end added

                return(method);
            }

            name     = "last_part";
            old_name = name;
            MethodContent method2 = new MethodContent(name, old_name);

            method2.pre = lines;

            return(method2);
        }