예제 #1
0
        /// <summary>
        /// Write the file.
        /// </summary>
        /// <param name="writeMode">Write mode.</param>
        /// <param name="bw">The writer.</param>
        public void Write(WriteMode writeMode, BinaryDataWriter bw)
        {
            //Set write mode.
            this.writeMode = writeMode;

            //Init file.
            FileWriter FileWriter = new FileWriter();

            FileWriter.InitFile(bw, writeMode, "GRP", Version > new FileWriter.Version(1, 0, 0) ? 3 : 2, Version);

            //Info block.
            FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_Info, "INFO");

            //Reference table to group items.
            FileWriter.InitReferenceTable(bw, SoundFiles.Count, "FileRefs");

            //Write each sound thing.
            for (int i = 0; i < SoundFiles.Count; i++)
            {
                //Null.
                if (SoundFiles[i] == null)
                {
                    FileWriter.AddReferenceTableNullReference("FileRefs");
                }

                //Exists.
                else
                {
                    //Add reference.
                    FileWriter.AddReferenceTableReference(bw, ReferenceTypes.GRP_Info_Item, "FileRefs");

                    //Write data.
                    bw.Write((uint)SoundFiles[i].FileId);
                    FileWriter.InitSizedReference(bw, "FileRef" + i);
                }
            }

            //Align.
            FileWriter.Align(bw, 0x20);

            //Close reference table.
            FileWriter.CloseReferenceTable(bw, "FileRefs");

            //Close info block.
            FileWriter.CloseBlock(bw);

            //File block.
            FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_File, "FILE");

            //Align to 0x20 bytes.
            FileWriter.Align(bw, 0x20);

            //Write each file and align.
            for (int i = 0; i < SoundFiles.Count; i++)
            {
                //Null.
                if (SoundFiles[i] == null)
                {
                    FileWriter.CloseSizedNullReference(bw, "FileRef" + i);
                }

                //Not null.
                else
                {
                    //If the file is embedded.
                    if (SoundFiles[i].Embed)
                    {
                        //Keep track of position.
                        long pos = bw.Position;

                        //Write file.
                        FileWriter.WriteFile(bw, SoundFiles[i].File, 0x20, writeMode);

                        //Close reference.
                        FileWriter.CloseSizedReference(bw, ReferenceTypes.General, (uint)(bw.Position - pos), "FileRef" + i);
                    }

                    //Don't write data.
                    else
                    {
                        FileWriter.CloseSizedNullReference(bw, "FileRef" + i);
                    }
                }
            }

            //Close file block.
            FileWriter.CloseBlock(bw);

            //Extra info exists if the version is greater than one.
            if (Version > new FileWriter.Version(1, 0, 0))
            {
                //Extra info block.
                FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_Infx, "INFX");

                //Ex table.
                FileWriter.InitReferenceTable(bw, ExtraInfo.Count, "Ex");

                //Write each info entry.
                for (int i = 0; i < ExtraInfo.Count; i++)
                {
                    //Null.
                    if (ExtraInfo[i] == null)
                    {
                        FileWriter.AddReferenceTableNullReference("Ex");
                    }

                    //Not null.
                    else
                    {
                        //Add reference.
                        FileWriter.AddReferenceTableReference(bw, ReferenceTypes.GRP_Infx_Item, "Ex");

                        //Write the data.
                        InfoExEntry e     = ExtraInfo[i];
                        UInt32      flags = 0;
                        switch (e.LoadFlags)
                        {
                        case InfoExEntry.ELoadFlags.All:
                            flags = 0xFFFFFFFF;
                            break;

                        case InfoExEntry.ELoadFlags.Bank:
                            flags = 0b100;
                            break;

                        case InfoExEntry.ELoadFlags.BankAndWarc:
                            flags = 0b1100;
                            break;

                        case InfoExEntry.ELoadFlags.Seq:
                            flags = 0b1;
                            break;

                        case InfoExEntry.ELoadFlags.SeqAndBank:
                            flags = 0b101;
                            break;

                        case InfoExEntry.ELoadFlags.SeqAndWarc:
                            flags = 0b1100;
                            break;

                        case InfoExEntry.ELoadFlags.Warc:
                            flags = 0b1000;
                            break;

                        case InfoExEntry.ELoadFlags.Wsd:
                            flags = 0b10;
                            break;
                        }

                        //Get type.
                        byte type = 0;
                        switch (e.ItemType)
                        {
                        case InfoExEntry.EItemType.Bank:
                            type = SoundTypes.Bank;
                            break;

                        case InfoExEntry.EItemType.Sound:
                            type = SoundTypes.Sound;
                            break;

                        case InfoExEntry.EItemType.SequenceSetOrWaveData:
                            type = SoundTypes.SoundGroup;
                            break;

                        case InfoExEntry.EItemType.WaveArchive:
                            type = SoundTypes.WaveArchive;
                            break;
                        }

                        //Item id.
                        Id id = new Id(type, (uint)e.ItemIndex);
                        id.Write(ref bw);

                        //Write flags.
                        bw.Write(flags);
                    }
                }

                //Close Ex table.
                FileWriter.CloseReferenceTable(bw, "Ex");

                //Close extra info block.
                FileWriter.CloseBlock(bw);
            }

            //Close file.
            FileWriter.CloseFile(bw);
        }