Пример #1
0
        public void ParseSections(string edlFilePath, string outputFilePath, Predicate <IEdlEntry> predicate)
        {
            var edlFileContents = File.ReadAllText(edlFilePath);
            var edl             = new CMX3600Deserializer().Read(edlFileContents);

            List <Section> sections = new();

            foreach (var entry in edl)
            {
                if (predicate == null || predicate(entry))
                {
                    var outTC   = new TimeCode(entry.RecordOut, SmpteFrameRate.Smpte25);
                    var outTC2  = TimeCode.FromFrames(outTC.TotalFrames - 1, outTC.FrameRate);
                    var section = new Section()
                    {
                        In  = new TimeCode(entry.RecordIn, SmpteFrameRate.Smpte25),
                        Out = outTC2
                    };

                    sections.Add(section);
                }
            }

            var sw = new SectionWriter();

            sw.WriteToFile(outputFilePath, sections);
        }
Пример #2
0
        public void SectionsNotRenderedRenderBodyTest()
        {
            // Layout page does not render all the defined sections, but it calls RenderBody.
            var layoutPath   = "~/Layout.cshtml";
            var sectionName1 = "section1";
            var sectionName2 = "section2";
            // A dummy section action that does nothing
            SectionWriter sectionAction = () => { };

            var page = CreatePageWithLayout(
                p =>
            {
                p.DefineSection(sectionName1, sectionAction);
                p.DefineSection(sectionName2, sectionAction);
            },
                // The layout page only calls RenderBody
                p =>
            {
                p.Write(p.RenderBody());
            },
                layoutPath: layoutPath
                );

            var sectionsNotRendered = "section1; section2";

            Assert.Throws <HttpException>(
                () => Utils.RenderWebPage(page),
                String.Format(
                    CultureInfo.CurrentCulture,
                    WebPageResources.WebPage_SectionsNotRendered,
                    layoutPath,
                    sectionsNotRendered
                    )
                );
        }
Пример #3
0
        public void SectionsNotRenderedTest()
        {
            // Layout page does not render all the defined sections.

            var layoutPath   = "~/Layout.cshtml";
            var sectionName1 = "section1";
            var sectionName2 = "section2";
            var sectionName3 = "section3";
            var sectionName4 = "section4";
            var sectionName5 = "section5";
            // A dummy section action that does nothing
            SectionWriter sectionAction = () => { };

            // The page defines 5 sections.
            var page = CreatePageWithLayout(
                p => {
                p.DefineSection(sectionName1, sectionAction);
                p.DefineSection(sectionName2, sectionAction);
                p.DefineSection(sectionName3, sectionAction);
                p.DefineSection(sectionName4, sectionAction);
                p.DefineSection(sectionName5, sectionAction);
            },
                // The layout page renders only two of the sections
                p => {
                p.Write(p.RenderSection(sectionName2));
                p.Write(p.RenderSection(sectionName4));
            },
                layoutPath: layoutPath);

            var sectionsNotRendered = "section1; section3; section5";

            ExceptionAssert.Throws <HttpException>(() => Utils.RenderWebPage(page),
                                                   String.Format(CultureInfo.CurrentCulture, WebPageResources.WebPage_SectionsNotRendered, layoutPath, sectionsNotRendered));
        }
Пример #4
0
 public void DefineSection(string name, SectionWriter action)
 {
     if (SectionWriters.ContainsKey(name))
     {
         throw new HttpException(String.Format("WebPageResources.WebPage_SectionAleadyDefined {0}", name));
     }
     SectionWriters[name] = action;
 }
Пример #5
0
 protected void DefineSection(string name, SectionWriter action)
 {
     if (SectionWriters.ContainsKey(name))
     {
         throw new ApplicationException(string.Format("Section {0}, already defined.", name));
     }
     SectionWriters[name] = action;
 }
Пример #6
0
 public void DefineSection(string name, SectionWriter action)
 {
     if (SectionWriters.ContainsKey(name))
     {
         throw new HttpException(String.Format(CultureInfo.InvariantCulture, WebPageResources.WebPage_SectionAleadyDefined, name));
     }
     SectionWriters[name] = action;
 }
Пример #7
0
        /// <summary>由内容页调用以创建指定的内容部分。</summary>
        /// <param name="name">要创建的部分的名称。</param>
        /// <param name="action">在新部分中要执行的操作的类型。</param>
        public void DefineSection(string name, SectionWriter action)
        {
            if (CurrentContext.Sections == null)
            {
                CurrentContext.Sections = new Dictionary <string, SectionWriter>();
            }

            CurrentContext.Sections[name] = action;
        }
Пример #8
0
 public void DefineSection(string name, SectionWriter action)
 {
     if (this.SectionWriters.ContainsKey(name))
     throw new HttpException(string.Format((IFormatProvider) CultureInfo.InvariantCulture, WebPageResources.WebPage_SectionAleadyDefined, new object[1]
     {
       (object) name
     }));
       else
     this.SectionWriters[name] = action;
 }
Пример #9
0
 public void DefineSection(string name, SectionWriter action) {
     if (SectionWriters.ContainsKey(name)) {
         throw new HttpException(String.Format(CultureInfo.InvariantCulture, WebPageResources.WebPage_SectionAleadyDefined, name));
     }
     SectionWriters[name] = action;
 }
 /// <summary>
 /// Defines a template section.
 /// </summary>
 /// <param name="name">The section name.</param>
 /// <param name="writer">The writer delegate.</param>
 protected virtual void DefineSection(string name, SectionWriter writer)
 {
     writer.Invoke();
 }
Пример #11
0
        public static byte[] WriteFile(string baseDir, JsonData projFile, GMFile f)
        {
            Console.WriteLine($"Preparing strings...");
            var stringsChunkBuilder = new StringsChunkBuilder();

            stringsChunkBuilder.AddStrings(f.Strings);

            var texpChunk = new BBData(new BinBuffer(), new int[0]);

            Console.WriteLine($"Preparing textures...");
            int[] texPagOffsets = SectionWriter.WriteTexturePages(texpChunk, f.TexturePages);

            var codeChunk = new BBData(new BinBuffer(), new int[0]);

            Console.WriteLine($"Preparing code...");
            var codeChunkStringOffsetOffsets = Assembler.WriteCodes(codeChunk, f, stringsChunkBuilder);

            var    offsets = new int[0];
            BBData writer  = new BBData(new BinBuffer(), offsets);

            writer.Buffer.Write(SectionHeaders.Form);
            writer.Buffer.Write(0);

            var stringOffsetOffsets = new List <int>();
            int stringsDataPosition = 0;
            var texpOffsetOffsets   = new List <int>();
            int texpChunkPosition   = 0;
            var codeOffsetOffsets   = new List <int>();
            int codeChunkPosition   = 0;

            foreach (SectionHeaders chunkId in f.ChunkOrder)
            {
                Console.WriteLine($"Writing {chunkId}...");
                BBData chunk = new BBData(new BinBuffer(), new int[0]);
                int[]  chunkStringOffsetOffsets = null;
                int[]  chunkTexpOffsetOffsets   = null;
                int[]  chunkCodeOffsetOffsets   = null;
                switch (chunkId)
                {
                case SectionHeaders.General:
                    chunkStringOffsetOffsets = SectionWriter.WriteGeneral(chunk, f.General, f.Rooms, stringsChunkBuilder);
                    break;

                case SectionHeaders.Options:
                    chunkStringOffsetOffsets = SectionWriter.WriteOptions(chunk, f.Options, stringsChunkBuilder);
                    break;

                case SectionHeaders.Sounds:
                    chunkStringOffsetOffsets = SectionWriter.WriteSounds(chunk, f.Sound, stringsChunkBuilder, f.AudioGroups);
                    break;

                case SectionHeaders.AudioGroup:
                    chunkStringOffsetOffsets = SectionWriter.WriteAudioGroups(chunk, f.AudioGroups, stringsChunkBuilder);
                    break;

                case SectionHeaders.Sprites:
                    SectionWriter.WriteSprites(chunk, f.Sprites, stringsChunkBuilder, texPagOffsets,
                                               out chunkStringOffsetOffsets, out chunkTexpOffsetOffsets);
                    break;

                case SectionHeaders.Backgrounds:
                    SectionWriter.WriteBackgrounds(chunk, f.Backgrounds, stringsChunkBuilder, texPagOffsets,
                                                   out chunkStringOffsetOffsets, out chunkTexpOffsetOffsets);
                    break;

                case SectionHeaders.Paths:
                    chunkStringOffsetOffsets = SectionWriter.WritePaths(chunk, f.Paths, stringsChunkBuilder);
                    break;

                case SectionHeaders.Scripts:
                    chunkStringOffsetOffsets = SectionWriter.WriteScripts(chunk, f.Scripts, stringsChunkBuilder);
                    break;

                case SectionHeaders.Fonts:
                    SectionWriter.WriteFonts(chunk, f.Fonts, stringsChunkBuilder, texPagOffsets,
                                             out chunkStringOffsetOffsets, out chunkTexpOffsetOffsets);
                    break;

                case SectionHeaders.Objects:
                    chunkStringOffsetOffsets = SectionWriter.WriteObjects(chunk, f.Objects, stringsChunkBuilder);
                    break;

                case SectionHeaders.Rooms:
                    chunkStringOffsetOffsets = SectionWriter.WriteRooms(chunk, f.Rooms, stringsChunkBuilder);
                    break;

                case SectionHeaders.TexturePage:
                    chunk             = texpChunk;
                    texpChunkPosition = writer.Buffer.Position + 8;
                    break;

                case SectionHeaders.Code:
                    chunk = codeChunk;
                    chunkStringOffsetOffsets = codeChunkStringOffsetOffsets;
                    codeChunkPosition        = writer.Buffer.Position + 8;
                    break;

                case SectionHeaders.Variables:
                    if (f.VariableExtra != null)
                    {
                        foreach (var e in f.VariableExtra)
                        {
                            chunk.Buffer.Write(e);
                        }
                    }
                    SectionWriter.WriteRefDefs(chunk, f.RefData.Variables, stringsChunkBuilder, f.General.IsOldBCVersion, false,
                                               out chunkStringOffsetOffsets, out chunkCodeOffsetOffsets);
                    break;

                case SectionHeaders.Functions:
                    SectionWriter.WriteRefDefs(chunk, f.RefData.Functions, stringsChunkBuilder, f.General.IsOldBCVersion, true,
                                               out chunkStringOffsetOffsets, out chunkCodeOffsetOffsets);
                    chunkStringOffsetOffsets = chunkStringOffsetOffsets.Concat(SectionWriter.WriteFunctionLocals(chunk, f.FunctionLocals, stringsChunkBuilder)).ToArray();
                    break;

                case SectionHeaders.Strings:
                    var stringOffsets = stringsChunkBuilder.WriteStringsChunk(chunk);
                    stringsDataPosition = writer.Buffer.Position + stringOffsets[0] + 12;
                    // for Textures chunk up next
                    SectionWriter.Pad(chunk, 0x80, writer.Buffer.Position + 8);
                    break;

                case SectionHeaders.Textures:
                    SectionWriter.WriteTextures(chunk, f.Textures);
                    break;

                case SectionHeaders.Audio:
                    SectionWriter.WriteAudio(chunk, f.Audio, writer.Buffer.Position);
                    break;

                case SectionHeaders.Shaders:
                    chunkStringOffsetOffsets = SectionWriter.WriteShaders(chunk, f.Shaders, stringsChunkBuilder);
                    break;

                default:
                    var chunkName = chunkId.ToChunkName();
                    Console.Error.WriteLine($"Note: Don't know how to handle {chunkName}");
                    string chunkFile = null;
                    if (projFile.Has("chunks") && projFile["chunks"].IsArray)
                    {
                        foreach (JsonData jd in projFile["chunks"])
                        {
                            if (jd.IsString)
                            {
                                if (Path.GetFileNameWithoutExtension((string)jd) == chunkName)
                                {
                                    chunkFile = (string)jd;
                                    break;
                                }
                            }
                        }
                    }
                    BinBuffer chunkData;
                    if (chunkFile == null)
                    {
                        Console.Error.WriteLine($"Note: Chunk {chunkName} was not dumped, assuming it's empty");
                        chunkData = new BinBuffer();
                    }
                    else
                    {
                        Console.Error.WriteLine($"Note: Loading {chunkName} from dump");
                        try
                        {
                            chunkData = new BinBuffer(File.ReadAllBytes(Path.Combine(baseDir, chunkFile)));
                        }
                        catch (Exception e)
                        {
                            Console.Error.WriteLine($"Error loading {chunkName}, using empty");
                            Console.Error.WriteLine(e);
                            chunkData = new BinBuffer();
                        }
                    }
                    chunk = new BBData(chunkData, new int[0]);
                    break;
                }
                if (chunkStringOffsetOffsets != null)
                {
                    foreach (var offset in chunkStringOffsetOffsets)
                    {
                        stringOffsetOffsets.Add(offset + writer.Buffer.Position);
                    }
                }
                chunkStringOffsetOffsets = null;
                if (chunkTexpOffsetOffsets != null)
                {
                    foreach (var offset in chunkTexpOffsetOffsets)
                    {
                        texpOffsetOffsets.Add(offset + writer.Buffer.Position);
                    }
                }
                chunkTexpOffsetOffsets = null;
                if (chunkCodeOffsetOffsets != null)
                {
                    foreach (var offset in chunkCodeOffsetOffsets)
                    {
                        codeOffsetOffsets.Add(offset + writer.Buffer.Position);
                    }
                }
                chunkCodeOffsetOffsets = null;
                SectionWriter.WriteChunk(writer, chunkId, chunk);
            }

            writer.Buffer.Position = 4;
            writer.Buffer.Write(writer.Buffer.Size - 8);
            writer.Buffer.Position = writer.Buffer.Size;

            foreach (var stringOffset in stringOffsetOffsets)
            {
                writer.Buffer.Position = stringOffset;
                var o = writer.Buffer.ReadInt32();
                //bb.Position -= sizeof(int);
                writer.Buffer.Write(o + stringsDataPosition);
            }

            foreach (var texpOffset in texpOffsetOffsets)
            {
                writer.Buffer.Position = texpOffset;
                var o = writer.Buffer.ReadInt32();
                //bb.Position -= sizeof(int);
                writer.Buffer.Write(o + texpChunkPosition);
            }

            foreach (var codeOffset in codeOffsetOffsets)
            {
                writer.Buffer.Position = codeOffset;
                var o = writer.Buffer.ReadInt32();
                //bb.Position -= sizeof(int);
                writer.Buffer.Write(o + codeChunkPosition);
            }

            writer.Buffer.Position = 0;
            return(writer.Buffer.ReadBytes(writer.Buffer.Size));
        }
Пример #12
0
        void WriteFontKerningSection( BinaryWriter writer, List< CharacterKerningInfo > kernings )
        {
            using ( SectionWriter sectionWriter = new SectionWriter( writer, RuntimeFont.FontFile_Section_Kerning ) )
            {
                using ( Graphics g = CreateGraphics() )
                {
                    // First, figure out how many characters have kerning.
                    // Write the # of characters that have kerning.
                    writer.Write( (Int16)kernings.Count );

                    // For each one, write its kerning list.
                    foreach ( CharacterKerningInfo info in kernings )
                    {
                        // Write which character this is.
                        writer.Write( (Int16)info.Character.SudoFontIndex );

                        // Write its list of kernings.
                        writer.Write( (Int16)info.Kernings.Count );
                        for ( int i=0; i < info.Kernings.Count; i++ )
                        {
                            writer.Write( (Int16)info.Kernings[i].SecondCharacter.SudoFontIndex );
                            writer.Write( (Int16)info.Kernings[i].KernAmount );
                        }
                    }
                }
            }
        }
Пример #13
0
 void WriteFontInfoSection( BinaryWriter writer, int originalTextureWidth, int originalTextureHeight )
 {
     using ( SectionWriter sectionWriter = new SectionWriter( writer, RuntimeFont.FontFile_Section_FontInfo ) )
     {
         float heightInPixels = _currentFont.GetHeightInPixels( this );
         writer.Write( (short)heightInPixels ); // Font height.
         writer.Write( (short)originalTextureWidth );
         writer.Write( (short)originalTextureHeight );
     }
 }
Пример #14
0
        void WriteFontConfigSection( BinaryWriter writer )
        {
            byte[] bytes;

            // First, write the configuration into a MemoryStream, then into our byte[] array.
            using ( MemoryStream memStream = new MemoryStream() )
            {
                using ( StreamWriter memStreamWriter = new StreamWriter( memStream ) )
                {
                    ExportConfiguration( memStreamWriter );
                    memStreamWriter.Flush();

                    memStream.Position = 0;
                    bytes = new byte[ memStream.Length ];
                    memStream.Read( bytes, 0, bytes.Length );
                }
            }

            // Now write it to the section.
            using ( SectionWriter sectionWriter = new SectionWriter( writer, RuntimeFont.FontFile_Section_Config ) )
            {
                writer.Write( bytes );
            }
        }
Пример #15
0
        void WriteFontCharactersSection( BinaryWriter writer )
        {
            using ( SectionWriter sectionWriter = new SectionWriter( writer, RuntimeFont.FontFile_Section_Characters ) )
            {
                // Write the # of characters.
                writer.Write( (short)_finalCharacterSet.Length );

                for ( int i=0; i < _finalCharacterSet.Length; i++ )
                {
                    CharacterInfo c = _finalCharacterSet[i];

                    writer.Write( (short)c.Character );

                    // Write its location in the packed image.
                    writer.Write( (short)c.PackedX );
                    writer.Write( (short)c.PackedY );
                    writer.Write( (short)c.PackedWidth );
                    writer.Write( (short)c.PackedHeight );

                    // Write its placement offset (i.e. if you were to print this packed letter at (0,0), how offsetted would it be?)
                    writer.Write( (short)c.XOffset );
                    writer.Write( (short)c.YOffset );

                    // How far we advance X to get to the next character.
                    writer.Write( (short)c.XAdvance );
                }
            }
        }
Пример #16
0
 /// <summary>
 /// Called by content pages to create named content sections.
 /// </summary>
 /// <param name="name">The name of the section to create.</param><param name="action">The type of action to take with the new section.</param>
 public void DefineSection(string name, SectionWriter action);
 /// <summary>
 /// Defines a template section.
 /// </summary>
 /// <param name="name">The section name.</param>
 /// <param name="writer">The writer delegate.</param>
 protected virtual void DefineSection(string name, SectionWriter writer)
 {
     writer.Invoke();
 }
Пример #18
0
        public static int[] WriteCodes(BBData data, GMFile f, StringsChunkBuilder strings)
        {
            int bytecodeSize = 0;

            foreach (var ci in f.Code)
            {
                bytecodeSize += ci.Size;
            }

            Console.WriteLine($"Assembling...");

            BBData[] datas = new BBData[f.Code.Length];
            for (int i = 0; i < f.Code.Length; i++)
            {
                BBData codedata = new BBData(new BinBuffer(), new int[0]);
                WriteCodeInfo(codedata, f.Code[i], strings, f.General.BytecodeVersion);
                datas[i] = codedata;
            }

            data.Buffer.Write(datas.Length);

            var allOffs = data.OffsetOffsets.ToList();

            var offAcc = data.Buffer.Position + datas.Length * sizeof(int); // after all offsets

            if (f.General.BytecodeVersion > 0xE)
            {
                offAcc += bytecodeSize;
            }
            int[] offsets             = new int[datas.Length];
            var   stringOffsetOffsets = new int[f.Code.Length];

            for (int i = 0; i < datas.Length; i++)
            {
                allOffs.Add(data.Buffer.Position);
                data.Buffer.Write(offAcc);
                offsets[i] = offAcc;

                stringOffsetOffsets[i] = offAcc + 8;

                offAcc += datas[i].Buffer.Size;
            }

            Console.WriteLine($"Linking...");

            IList <Tuple <ReferenceSignature, uint> > functionReferences = new List <Tuple <ReferenceSignature, uint> >();
            IList <Tuple <ReferenceSignature, uint> > variableReferences = new List <Tuple <ReferenceSignature, uint> >();

            variableReferences.Add(new Tuple <ReferenceSignature, uint>(new ReferenceSignature
            {
                Name          = "prototype",
                InstanceType  = InstanceType.Self,
                VariableType  = VariableType.Normal,
                VariableIndex = 0
            }, 0xFFFFFFFF));
            variableReferences.Add(new Tuple <ReferenceSignature, uint>(new ReferenceSignature
            {
                Name          = "@@array@@",
                InstanceType  = InstanceType.Self,
                VariableType  = VariableType.Normal,
                VariableIndex = 1
            }, 0xFFFFFFFF));

            int[] bytecodeOffsets = null;
            if (f.General.BytecodeVersion > 0xE)
            {
                // In >=F bytecodes, the code comes before the info data, which
                // is why this method can't just be a call to WriteList.
                bytecodeOffsets = new int[f.Code.Length];
                for (int i = 0; i < f.Code.Length; i++)
                {
                    bytecodeOffsets[i] = data.Buffer.Position - 12;
                    AddReferencesOffset(functionReferences, f.Code[i].functionReferences, data.Buffer.Position);
                    if (f.Code[i].variableReferences.Count == 0 || f.Code[i].variableReferences[0].Item1.Name != "arguments")
                    {
                        variableReferences.Add(new Tuple <ReferenceSignature, uint>(new ReferenceSignature
                        {
                            Name          = "arguments",
                            InstanceType  = InstanceType.Local,
                            Instance      = f.Code[i].Name,
                            VariableType  = VariableType.Normal,
                            VariableIndex = -1
                        }, 0xFFFFFFFF));
                    }
                    AddReferencesOffset(variableReferences, f.Code[i].variableReferences, data.Buffer.Position);
                    WriteCodeBlock(data, f.Code[i].InstructionsCopy, f.General.BytecodeVersion);
                }
            }

            for (int i = 0; i < datas.Length; i++)
            {
                if (f.General.BytecodeVersion > 0xE)
                {
                    datas[i].Buffer.Position = (int)Marshal.OffsetOf(typeof(CodeEntryF), "BytecodeOffset");
                    datas[i].Buffer.Write(bytecodeOffsets[i] - data.Buffer.Position);
                }
                else
                {
                    AddReferencesOffset(functionReferences, f.Code[i].functionReferences, data.Buffer.Position);
                    if (f.Code[i].variableReferences.Count == 0 || f.Code[i].variableReferences[0].Item1.Name != "arguments")
                    {
                        variableReferences.Add(new Tuple <ReferenceSignature, uint>(new ReferenceSignature
                        {
                            Name          = "arguments",
                            InstanceType  = InstanceType.Local,
                            Instance      = f.Code[i].Name,
                            VariableType  = VariableType.Normal,
                            VariableIndex = -1
                        }, 0xFFFFFFFF));
                    }
                    AddReferencesOffset(variableReferences, f.Code[i].variableReferences, data.Buffer.Position);
                }
                SectionWriter.Write(data.Buffer, datas[i]);
                allOffs.AddRange(datas[i].OffsetOffsets); // updated by Write
            }

            IList <ReferenceDef> functionStartOffsetsAndCounts;

            ResolveReferenceOffsets(data, functionReferences, strings, false, out functionStartOffsetsAndCounts);

            IList <ReferenceDef> variableStartOffsetsAndCounts;

            ResolveReferenceOffsets(data, variableReferences, strings, true, out variableStartOffsetsAndCounts);

            if (f.RefData.Variables == null || f.RefData.Variables.Length == 0)
            {
                Console.Error.WriteLine("Warning: Variable definitions not pre-loaded. Linking may be inaccurate or lose information.");
            }
            else
            {
                // I tried my best at guessing what these should be, but it wasn't enough.
                // I suspect it may have to do with variable type, since getting
                // one wrong resulted in "tried to index something that isn't an
                // array" (or something to that effect).
                for (int i = 0; i < variableStartOffsetsAndCounts.Count; i++)
                {
                    var v = variableStartOffsetsAndCounts[i];
                    if (i < f.RefData.Variables.Length &&
                        v.Name == f.RefData.Variables[i].Name) // &&
                                                               //(v.InstanceType == f.RefData.Variables[i].InstanceType || v.InstanceType >= InstanceType.StackTopOrGlobal))
                    {
                        v.unknown2     = f.RefData.Variables[i].unknown2;
                        v.InstanceType = f.RefData.Variables[i].InstanceType;
                        variableStartOffsetsAndCounts[i] = v;
                    }
                }
            }

            f.RefData = new RefData
            {
                Functions = functionStartOffsetsAndCounts.ToArray(),
                Variables = variableStartOffsetsAndCounts.ToArray()
            };

            data.OffsetOffsets = allOffs.ToArray();

            return(stringOffsetOffsets);
        }