private string MatchEvaluatorTags(Match m)
        {
            Type   tagType   = null;
            object tagObject = null;

            switch (m.Groups[RegExConstants.RE_CS_TAGS_TAGNAME].Value)
            {
            case "Assembly":
                tagType   = typeof(TagAssembly);
                tagObject = new TagAssembly();
                break;

            case "CodeTemplate":
                tagType   = typeof(TagCodeTemplate);
                tagObject = new TagCodeTemplate();
                break;

            case "Import":
                tagType   = typeof(TagImport);
                tagObject = new TagImport();
                break;

            case "Property":
                tagType   = typeof(TagProperty);
                tagObject = new TagProperty();
                break;

            case "Register":
                tagType   = typeof(TagRegister);
                tagObject = new TagRegister();
                break;

            default:
                tagType   = null;
                tagObject = null;
                break;
            }

            // Only parse if it's a known tag
            if (tagType != null)
            {
                if (m.Groups[RegExConstants.RE_CS_TAGS_KEY].Captures.Count > 0)
                {
                    for (int i = 0; i < m.Groups[RegExConstants.RE_CS_TAGS_KEY].Captures.Count; i++)
                    {
                        SetProperty(tagType,
                                    tagObject,
                                    m.Groups[RegExConstants.RE_CS_TAGS_KEY].Captures[i].Value,
                                    m.Groups[RegExConstants.RE_CS_TAGS_VALUE].Captures[i].Value);
                    }
                }

                // Add the templateobject to the list
                TemplateObjectList.Add(new TemplateObject(tagType, tagObject));
            }

            return(string.Empty);
        }
示例#2
0
        public override void parse(byte[] data)
        {
            NeedsInit = false;
            DataParser parser = new DataParser(data);

            if (parser.getStringFixed(4) != "VER:")
            {
                throw new Exception("Expected VER: header block");
            }
            SizeVersionString = (int)parser.getDWord();
            Version           = parser.getStringFixed(SizeVersionString);
            if (parser.getStringFixed(4) != "PAG:")
            {
                throw new Exception("Expected PAG: header block");
            }
            Unknown2 = parser.getDWord();
            Unknown3 = parser.getWord();
            if (parser.getStringFixed(4) != "TT3:")
            {
                throw new Exception("Expected TT3: header block");
            }
            TTMSize = parser.getDWord() - 5;
            TTMCompressionMethod = parser.getByte();
            TTMUncompressedSize  = parser.getDWord();
            TTMData = parser.getBytes(TTMSize);
            if (parser.getStringFixed(4) != "TTI:")
            {
                throw new Exception("Expected TTI: header block");
            }
            Unknown4 = parser.getWord();
            Unknown5 = parser.getWord();
            if (parser.getStringFixed(4) != "TAG:")
            {
                throw new Exception("Expected TAG: header block");
            }
            TAGSize  = parser.getDWord();
            TagCount = parser.getWord();
//      System.Diagnostics.Debug.WriteLine("idx\tid\tname");
            for (int j = 0; j < TagCount; j++)
            {
                TagProperty tag = new TagProperty();
                tag.id          = parser.getWord();
                tag.description = parser.getString();
                tags.Add(tag.id, tag.description);
//        System.Diagnostics.Debug.WriteLine(j+"\t"+tag.id+"\t"+tag.description);
            }
            Compression comp = new Compression();

            script = comp.decompress(TTMData, TTMCompressionMethod); // Usually RLE/Huffmann
            //string filename = "c:\\temp\\" + this.FileName;

            /*if (System.IO.File.Exists(filename))
             * System.IO.File.Delete(filename);
             * System.IO.File.WriteAllBytes(filename, script);*/
/*      if (this.FileName == "MEANWHIL.TTM")
 *    { */
            DataParser moviescript = new DataParser(script);

            //UInt32 unknown6 = moviescript.getDWord();
            try
            {
//          System.Diagnostics.Debug.WriteLine("TTM DUMP START");
                while (!moviescript.atEnd())
                {
                    Instruction chunk = new Instruction();
                    UInt16      code  = moviescript.getWord();
                    UInt16      size  = (UInt16)(code & 0x000f);
                    code      &= 0xfff0;
                    chunk.code = code;
                    if (code == 0x1110 && size == 1)
                    {
                        UInt16 id = moviescript.getWord();
                        chunk.data.Add(id);
                        if (tags.ContainsKey(id))
                        {
                            chunk.name = tags[id];
                        }
                    }
                    else if (size == 15)
                    {
                        chunk.name = moviescript.getString().ToUpper();
                        if (moviescript.peekByte() == 0)
                        {
                            moviescript.skip(1);
                        }

                        /*if ((moviescript.bytesLeft() & 1) == 1)
                         * {
                         * moviescript.skip(1);
                         * }*/
                    }

                    /*else if (code == 0x0ff0) // No idea what this is
                     * {
                     * for (int i = 0; i < 28; i++)
                     *  chunk.data.Add(moviescript.getByte());
                     * }*/
                    else
                    {
                        for (int i = 0; i < size; i++)
                        {
                            chunk.data.Add(moviescript.getWord());
                        }
                    }
                    if (chunk.code == 0x1110)
                    {
                        scene = chunk.data[0];
                    }
                    if (!scripts.ContainsKey(scene))
                    {
                        if (scene == 0)
                        {
                            tags.Add(0, "init");
                            NeedsInit = true;
                        }
                        scripts.Add(scene, new List <Instruction>());
                    }
//            System.Diagnostics.Debug.WriteLine(chunk.ToString());
                    scripts[scene].Add(chunk);
                }
//          System.Diagnostics.Debug.WriteLine("TTM DUMP END");
            }
            catch
            {
            }
            // }
        }
示例#3
0
 set => SetValue(TagProperty, value);
示例#4
0
 public void Add(TagProperty TagProperty)
 {
     this.Add(TagProperty);
 }
示例#5
0
 set => this.SetValue(TagProperty, value);
        public static string CreateContents(string nameSpace, string className, string classDefaultInherit, List <TemplateObject> templateObjectList, string templateName)
        {
            StringBuilder result         = new StringBuilder();
            int           currentIndent  = 0;
            int           indentIncrease = 4;

            // Check if this is a special case like Core.cst where there is only one TagText
            // in the whole templateObjectList.
            if (templateObjectList.Count == 1 &&
                templateObjectList[0].TagType == typeof(TagText))
            {
                TagText tText = (TagText)templateObjectList[0].Object;

                // Check if a namespace is defined somewhere, then ignore this
                if (Regex.Matches(tText.Text, @"^namespace\s+\w+\s*$").Count == 0)
                {
                    // Find using statement and i3 the namespace should be inserted
                    MatchCollection mc = Regex.Matches(tText.Text, RegExConstants.RE_CS_USINGSTATEMENTS);

                    // Must be only one match
                    if (mc.Count == 1)
                    {
                        result.Append(mc[0].Groups[RegExConstants.RE_CS_USINGSTATEMENTS_USING].Value);

                        // Add namespace tag
                        result.AppendLine(TemplateCreateNamespacePart(nameSpace, currentIndent));

                        currentIndent += indentIncrease;

                        result.AppendLine(BreakLinesAndOutput(mc[0].Groups[RegExConstants.RE_CS_USINGSTATEMENTS_RESTOFFILE].Value, currentIndent));

                        currentIndent -= indentIncrease;

                        result.AppendLine(string.Format("{0}}}", GetIndent(currentIndent)));

                        return(result.ToString());
                    }
                }
            }

            // Create the using statements
            TagImport tagImport = GetTemplateObject <TagImport>(templateObjectList);

            bool usingSystem = false;
            bool usingSystemCollectionsGeneric = false;
            bool usingCodesmithEngine          = false;

            while (tagImport != null)
            {
                result.AppendLine(TemplateCreateUsingPart(tagImport, currentIndent));

                if (tagImport.Namespace.Equals("System", StringComparison.CurrentCultureIgnoreCase))
                {
                    usingSystem = true;
                }

                if (tagImport.Namespace.Equals("System.Collections.Generic", StringComparison.CurrentCultureIgnoreCase))
                {
                    usingSystemCollectionsGeneric = true;
                }

                if (tagImport.Namespace.Equals("CodeSmith.Engine", StringComparison.CurrentCultureIgnoreCase))
                {
                    usingCodesmithEngine = true;
                }

                tagImport = GetTemplateObject <TagImport>(templateObjectList);
            }

            // Add System and System.Collections.Generic

            if (!usingSystem)
            {
                result.AppendLine(TemplateCreateUsingPart(new TagImport("System"), currentIndent));
            }

            if (!usingSystemCollectionsGeneric)
            {
                result.AppendLine(TemplateCreateUsingPart(new TagImport("System.Collections.Generic"), currentIndent));
            }

            if (!usingCodesmithEngine)
            {
                result.AppendLine(TemplateCreateUsingPart(new TagImport("CodeSmith.Engine"), currentIndent));
            }

            result.AppendLine();

            // Create namespace tag
            result.AppendLine(TemplateCreateNamespacePart(nameSpace, currentIndent));

            currentIndent += indentIncrease;

            // Find the CodeTemplate object in list
            TagCodeTemplate tagCodeTemplate = GetTemplateObject <TagCodeTemplate>(templateObjectList);

            if (tagCodeTemplate != null &&
                tagCodeTemplate.Inherits != string.Empty)
            {
                result.AppendLine(TemplateCreateClassPart(className, tagCodeTemplate.Inherits, currentIndent));
            }
            else
            {
                result.AppendLine(TemplateCreateClassPart(className, classDefaultInherit, currentIndent));
            }

            currentIndent += indentIncrease;

            // Create the properties
            TagProperty tagProperty = GetTemplateObject <TagProperty>(templateObjectList);

            while (tagProperty != null)
            {
                result.AppendLine(TemplateCreateProperty(tagProperty.Name, tagProperty.Type, currentIndent));

                tagProperty = GetTemplateObject <TagProperty>(templateObjectList);
            }

            result.AppendLine();

            StringBuilder __text = new StringBuilder();

            result.AppendLine(string.Format("{0}public override string OriginalTemplateName {{ get {{ return @\"{1}\"; }} }}\r\n", GetIndent(currentIndent), templateName));

            string templateComment = @"Generated from template: " + templateName;

            // Override the Render function
            result.AppendLine(string.Format("{0}public override void Render()\r\n{0}{{\r\n{1}TagFile(@\"{2}\");", GetIndent(currentIndent), GetIndent(currentIndent + indentIncrease), templateComment));

            // Find all TagCSharp and TagText items and create the code from that
            for (int i = 0; i < templateObjectList.Count; i++)
            {
                TemplateObject obj = templateObjectList[i];

                if (obj.TagType == typeof(TagCSharp))
                {
                    result.Append(BreakLinesAndOutput(((TagCSharp)obj.Object).Code, currentIndent));
                }
                else if ((obj.TagType == typeof(TagText)) || (obj.TagType == typeof(TagParameter)))
                {
                    int lookAheadIndex = i + 1;

                    while (lookAheadIndex < templateObjectList.Count)
                    {
                        if ((templateObjectList[lookAheadIndex].TagType == typeof(TagText)) || (templateObjectList[lookAheadIndex].TagType == typeof(TagParameter)))
                        {
                            lookAheadIndex++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    // idx points to the next code fragment i.e. not Text or parameters

                    // create single string.format using the text and parameters
                    // advance i to skip ahead

                    // Do string replace " to "" and the other first ?? togr

                    string argumentList      = string.Empty;
                    int    stringFormatIndex = 0;

                    for (int i2 = i; i2 < lookAheadIndex; i2++)
                    {
                        argumentList = string.Concat(argumentList, string.Format("{{{0}}}", stringFormatIndex));
                        stringFormatIndex++;
                    }

                    StringBuilder code = new StringBuilder();
                    code.AppendLine(string.Format("__text.AppendFormat(\"{0}\\r\\n\"", argumentList));

                    for (int i3 = i; i3 < lookAheadIndex; i3++)
                    {
                        if (templateObjectList[i3].TagType == typeof(TagText))
                        {
                            TagText tText = (TagText)templateObjectList[i3].Object;

                            // Convert text. Change all " to ""
                            tText.Text = tText.Text.Replace("\"", "\"\"");

                            // Remove all consecutive \n and also all \n that is occuring alone not after a \r
                            tText.Text = Regex.Replace(tText.Text, "((?<=[^\r])\n)|(\n{2,})", string.Empty);
                            code.AppendLine(string.Format(",@\"{0}\"", tText.Text));
                        }
                        else
                        {
                            TagParameter tParam = (TagParameter)templateObjectList[i3].Object;
                            code.AppendLine(string.Format(",{0}", tParam.Parameter));
                        }
                    }

                    code.AppendLine(");");

                    result.Append(string.Format("{0}{1}", GetIndent(currentIndent), code.ToString()));
                    i = lookAheadIndex - 1;
                }
            }

            result.AppendLine(string.Format("{0}return;", GetIndent(currentIndent + indentIncrease)));

            result.AppendLine(string.Format("{0}}}", GetIndent(currentIndent)));

            currentIndent -= indentIncrease;

            result.AppendLine();

            // Add the script section the properties
            TagScript tagScript = GetTemplateObject <TagScript>(templateObjectList);

            while (tagScript != null)
            {
                result.AppendLine(tagScript.Text);

                tagScript = GetTemplateObject <TagScript>(templateObjectList);
            }

            result.AppendLine(string.Format("{0}}}", GetIndent(currentIndent)));

            currentIndent -= indentIncrease;

            result.AppendLine(string.Format("{0}}}", GetIndent(currentIndent)));

            return(result.ToString());
        }