Ejemplo n.º 1
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);
                }
                string[] BLADAMN = hashme.Replace(fields[i].Type, sum).Split('\n');
                hashme = "";
                for (int x = 0; x < BLADAMN.Length; x++)
                {
                    if (BLADAMN[x].Contains(fields[i].Name))
                    {
                        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);
        }