Example #1
0
        private static string PrepareToHash(MsgFile msgFile)
        {
            string hashText = msgFile.Definition.Trim('\n', '\t', '\r', ' ');

            while (hashText.Contains("  "))
            {
                hashText = hashText.Replace("  ", " ");
            }
            while (hashText.Contains("\r\n"))
            {
                hashText = hashText.Replace("\r\n", "\n");
            }
            hashText = hashText.Trim();
            string[] lines = hashText.Split('\n');

            var haves    = new Queue <string>();
            var havenots = new Queue <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    // condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim() + "=" + ls[1].Trim());
                }
                else
                {
                    havenots.Enqueue(l.Trim());
                }
            }

            hashText = "";
            while (haves.Count + havenots.Count > 0)
            {
                hashText += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            }

            Dictionary <string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(msgFile.Stuff);

            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i];
                if (field.IsPrimitive)
                {
                    continue;
                }

                MsgFile ms = msgFile.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(msgFile, msgFile.Stuff[i]);
                    if (msgFile.Stuff[i].Type.Contains("/"))
                    {
                        msgFile.resolve(msgFile.Stuff[i]);
                    }
                    ms = msgFile.Stuff[i].Definer;
                }
                string sum = null;
                if (ms == null)
                {
                    RosMessage rosMessage = null;
                    var        packages   = MessageTypeRegistry.Default.PackageNames;
                    foreach (var package in packages)
                    {
                        try
                        {
                            var name = msgFile.Stuff[i].Type;
                            Console.WriteLine($"generate {package}/{name}");
                            rosMessage = RosMessage.Generate($"{package}/{name}");
                            sum        = rosMessage.MD5Sum();
                            break;
                        }
                        catch
                        {
                        }
                    }
                    if (rosMessage == null)
                    {
                        Logger.LogDebug("NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                        return(null);
                    }
                }
                else
                {
                    sum = MD5.Sum(ms);
                }
                if (sum == null)
                {
                    Logger.LogDebug("STILL NEEDS ANOTHER PASS: "******" B/C OF " + msgFile.Stuff[i].Type);
                    return(null);
                }

                hashText = Regex.Replace(hashText, @"^(.*/)?\b" + fields[i].Type + @"\b(\s*\[\s*\])?", sum, RegexOptions.Multiline);
            }
            return(hashText);
        }
Example #2
0
        private static string PrepareToHash(MsgsFile irm)
        {
            string hashme = irm.Definition.Trim('\n', '\t', '\r', ' ');

            while (hashme.Contains("  "))
            {
                hashme = hashme.Replace("  ", " ");
            }
            while (hashme.Contains("\r\n"))
            {
                hashme = hashme.Replace("\r\n", "\n");
            }
            hashme = hashme.Trim();
            string[] lines = hashme.Split('\n');

            Queue <string> haves = new Queue <string>(), havenots = new Queue <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    //condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim() + "=" + ls[1].Trim());
                }
                else
                {
                    havenots.Enqueue(l.Trim());
                }
            }
            hashme = "";
            while (haves.Count + havenots.Count > 0)
            {
                hashme += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            }
            Dictionary <string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(irm.Stuff);

            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].IsLiteral)
                {
                    continue;
                }
                MsgsFile ms = irm.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(irm, irm.Stuff[i]);
                    if (irm.Stuff[i].Type.Contains("/"))
                    {
                        irm.resolve(irm, irm.Stuff[i]);
                    }
                    ms = irm.Stuff[i].Definer;
                }
                if (ms == null)
                {
                    Debug.WriteLine("NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return(null);
                }
                string sum = MD5.Sum(ms);
                if (sum == null)
                {
                    Debug.WriteLine("STILL NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return(null);
                }
                Regex    findCurrentFieldType = new Regex("\\b" + fields[i].Type + "\\b");
                string[] BLADAMN = findCurrentFieldType.Replace(hashme, sum).Split('\n');
                hashme = "";
                for (int x = 0; x < BLADAMN.Length; x++)
                {
                    if (BLADAMN[x].Contains(fields[i].Name.Replace("@", "")))
                    {
                        if (BLADAMN[x].Contains("/"))
                        {
                            BLADAMN[x] = BLADAMN[x].Split('/')[1];
                        }

                        if (BLADAMN[x].Contains("[]") && !fields[i].IsLiteral)
                        {
                            BLADAMN[x] = BLADAMN[x].Replace("[]", "");
                        }
                    }
                    hashme += BLADAMN[x];
                    if (x < BLADAMN.Length - 1)
                    {
                        hashme += "\n";
                    }
                }
            }
            return(hashme);
        }