Esempio n. 1
0
        private bool WriteATO1(BinaryWriterX bw)
        {
            bool result = false;

            try
            {
                bw.WriteASCII(ATO1.Identifier);
                bw.Write(ATO1.SectionSize);
                bw.Write(ATO1.Padding1);
                bw.Write(ATO1.Unknown2);

                result = true;
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Esempio n. 2
0
        private bool WriteTXT2(BinaryWriterX bw)
        {
            bool result = false;

            try
            {
                // Calculate Section Size
                UInt32 newSize = (UInt32)(TXT2.NumberOfStrings * sizeof(UInt32) + sizeof(UInt32));

                for (int i = 0; i < TXT2.NumberOfStrings; i++)
                {
                    newSize += (UInt32)((String)TXT2.Strings[i]).Value.Length;
                }

                bw.WriteASCII(TXT2.Identifier);
                bw.Write(newSize);
                bw.Write(TXT2.Padding1);
                long startOfStrings = bw.BaseStream.Position;
                bw.Write(TXT2.NumberOfStrings);

                List <UInt32> offsets       = new List <UInt32>();
                UInt32        offsetsLength = TXT2.NumberOfStrings * sizeof(UInt32) + sizeof(UInt32);
                UInt32        runningTotal  = 0;
                for (int i = 0; i < TXT2.NumberOfStrings; i++)
                {
                    offsets.Add(offsetsLength + runningTotal);
                    runningTotal += (UInt32)((String)TXT2.Strings[i]).Value.Length;
                }
                for (int i = 0; i < TXT2.NumberOfStrings; i++)
                {
                    bw.Write(offsets[i]);
                }
                for (int i = 0; i < TXT2.NumberOfStrings; i++)
                {
                    for (int j = 0; j < TXT2.Strings.Count; j++)
                    {
                        TXT2.OriginalStrings[i] = TXT2.Strings[i];
                    }

                    if (Header.EncodingByte == EncodingByte.UTF8)
                    {
                        bw.Write(((String)TXT2.Strings[i]).Value);
                    }
                    else
                    {
                        if (Header.ByteOrderMark[0] == 0xFF)
                        {
                            bw.Write(((String)TXT2.Strings[i]).Value);
                        }
                        else
                        {
                            for (int j = 0; j < ((String)TXT2.Strings[i]).Value.Length; j += 2)
                            {
                                bw.Write(((String)TXT2.Strings[i]).Value[j + 1]);
                                bw.Write(((String)TXT2.Strings[i]).Value[j]);
                            }
                        }
                    }
                }

                PaddingWrite(bw);

                result = true;
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Esempio n. 3
0
        private bool WriteLBL1(BinaryWriterX bw)
        {
            bool result = false;

            try
            {
                // Calculate Section Size
                UInt32 newSize = sizeof(UInt32);

                foreach (Group grp in LBL1.Groups)
                {
                    newSize += (UInt32)(sizeof(UInt32) + sizeof(UInt32));
                }

                foreach (Label lbl in LBL1.Labels)
                {
                    newSize += (UInt32)(sizeof(byte) + lbl.Name.Length + sizeof(UInt32));
                }

                // Calculate Group Offsets
                UInt32 offsetsLength = LBL1.NumberOfGroups * sizeof(UInt32) * 2 + sizeof(UInt32);
                UInt32 runningTotal  = 0;
                for (int i = 0; i < LBL1.Groups.Count; i++)
                {
                    LBL1.Groups[i].Offset = offsetsLength + runningTotal;
                    foreach (Label lbl in LBL1.Labels)
                    {
                        if (lbl.Checksum == i)
                        {
                            runningTotal += (UInt32)(sizeof(byte) + lbl.Name.Length + sizeof(UInt32));
                        }
                    }
                }

                // Write
                bw.WriteASCII(LBL1.Identifier);
                bw.Write(newSize);
                bw.Write(LBL1.Padding1);
                bw.Write(LBL1.NumberOfGroups);

                foreach (Group grp in LBL1.Groups)
                {
                    bw.Write(grp.NumberOfLabels);
                    bw.Write(grp.Offset);
                }

                foreach (Group grp in LBL1.Groups)
                {
                    foreach (Label lbl in LBL1.Labels)
                    {
                        if (lbl.Checksum == LBL1.Groups.IndexOf(grp))
                        {
                            bw.Write(Convert.ToByte(lbl.Length));
                            bw.WriteASCII(lbl.Name);
                            bw.Write(lbl.Index);
                        }
                    }
                }

                PaddingWrite(bw);

                result = true;
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Esempio n. 4
0
        // Saving
        public bool Save()
        {
            bool result = false;

            try
            {
                FileStream    fs = System.IO.File.Create(File.FullName);
                BinaryWriterX bw = new BinaryWriterX(fs);

                // Byte Order
                bw.ByteOrder = Header.ByteOrderMark[0] > Header.ByteOrderMark[1] ? ByteOrder.LittleEndian : ByteOrder.BigEndian;

                // Header
                bw.WriteASCII(Header.Identifier);
                bw.Write(Header.ByteOrderMark);
                bw.Write(Header.Unknown1);
                bw.Write((byte)Header.EncodingByte);
                bw.Write(Header.Unknown2);
                bw.Write(Header.NumberOfSections);
                bw.Write(Header.Unknown3);
                bw.Write(Header.FileSize);
                bw.Write(Header.Unknown4);

                foreach (string section in SectionOrder)
                {
                    if (section == "LBL1")
                    {
                        WriteLBL1(bw);
                    }
                    else if (section == "NLI1")
                    {
                        WriteNLI1(bw);
                    }
                    else if (section == "ATO1")
                    {
                        WriteATO1(bw);
                    }
                    else if (section == "ATR1")
                    {
                        WriteATR1(bw);
                    }
                    else if (section == "TSY1")
                    {
                        WriteTSY1(bw);
                    }
                    else if (section == "TXT2")
                    {
                        WriteTXT2(bw);
                    }
                }

                // Update FileSize
                long fileSize = bw.BaseStream.Position;
                bw.BaseStream.Seek(Header.FileSizeOffset, SeekOrigin.Begin);
                bw.Write((UInt32)fileSize);

                bw.Close();
            }
            catch (Exception)
            { }

            return(result);
        }