Пример #1
0
        public override void Export(DesignData design)
        {
            string filename = GetExportFileName(design.Name);

            if (filename.Length > 0)
            {
                if (!design.IsLoaded)
                {
                    design.Load();
                }

                BinaryFileWriter writer = new BinaryFileWriter(File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.None));

                writer.WriteShort(EXPORT_VERSION);
                writer.WriteString(design.Name);
                writer.WriteString(design.Category);
                writer.WriteString(design.Subsection);
                writer.WriteInt(design.Width);
                writer.WriteInt(design.Height);
                writer.WriteInt(design.UserWidth);
                writer.WriteInt(design.UserHeight);

                // item count
                writer.WriteInt(design.Items.Count);

                for (int i = 0; i < design.Items.Count; ++i)
                {
                    DesignItem item = design.Items[i];

                    writer.WriteShort(item.ItemID);
                    writer.WriteShort((short)item.X);
                    writer.WriteShort((short)item.Y);
                    writer.WriteShort((short)item.Z);
                    writer.WriteShort(item.Level);
                    writer.WriteShort(item.Hue);
                }

                writer.Close();
            }
        }
Пример #2
0
        private static void WriteHeaderFile()
        {
            BinaryFileWriter writer = new BinaryFileWriter(File.Open(TMP_INDEX_FILE, FileMode.Create, FileAccess.Write, FileShare.None));

            writer.WriteInt(m_DesignHeaders.Count);          // count
            writer.WriteInt(INDEX_FILE_VERSION);             // file version

            for (int i = 0; i < m_DesignHeaders.Count; ++i)
            {
                DesignData header = (DesignData)m_DesignHeaders[i];

                writer.WriteString(header.Name);
                writer.WriteString(header.Category);
                writer.WriteString(header.Subsection);
                writer.WriteInt(header.Width);
                writer.WriteInt(header.Height);
                writer.WriteInt(header.UserWidth);
                writer.WriteInt(header.UserHeight);
                writer.WriteLong(header.FilePosition);
                writer.WriteInt(header.RecordCount);
            }

            writer.Close();
        }
Пример #3
0
        private static void WriteBinFile()
        {
            bool             fileExists = File.Exists(BIN_FILE);
            BinaryFileWriter binWriter  = new BinaryFileWriter(File.Open(TMP_BIN_FILE, FileMode.Create, FileAccess.Write, FileShare.None));

            if (fileExists)
            {
                BinaryFileReader oldBinReader = new BinaryFileReader(File.Open(BIN_FILE, FileMode.Open, FileAccess.Read, FileShare.None));
                WriteSavedComponentData(oldBinReader, binWriter);
                oldBinReader.Close();
            }

            foreach (DesignData unsavedDesign in m_UnsavedDesigns)
            {
                unsavedDesign.FilePosition = binWriter.Position;
                unsavedDesign.RecordCount  = unsavedDesign.Items.Count;
                WriteUpdatedDesignComponentData(unsavedDesign.Items, binWriter);
                m_DesignHeaders.Add(unsavedDesign);
            }

            m_UnsavedDesigns.Clear();

            binWriter.Close();
        }
Пример #4
0
        private static void WriteSavedComponentData(DesignData header, BinaryFileReader oldFileReader, BinaryFileWriter writer)
        {
            int count = header.RecordCount;

            for (int j = 0; j < count; ++j)
            {
                int ver = oldFileReader.ReadInt();

                switch (ver)
                {
                case 0:
                    writer.WriteInt(ver);                             // version
                    writer.WriteInt(oldFileReader.ReadInt());         // index
                    writer.WriteInt(oldFileReader.ReadInt());         // x
                    writer.WriteInt(oldFileReader.ReadInt());         // y
                    writer.WriteInt(oldFileReader.ReadInt());         // z
                    writer.WriteInt(oldFileReader.ReadInt());         // level
                    break;

                case 1:
                    writer.WriteInt(ver);                             // version
                    writer.WriteInt(oldFileReader.ReadInt());         // index
                    writer.WriteInt(oldFileReader.ReadInt());         // x
                    writer.WriteInt(oldFileReader.ReadInt());         // y
                    writer.WriteInt(oldFileReader.ReadInt());         // z
                    writer.WriteInt(oldFileReader.ReadInt());         // level
                    writer.WriteInt(oldFileReader.ReadInt());         // hue
                    break;
                }
            }
        }
Пример #5
0
 private static void WriteUpdatedDesignComponentData(DesignItemCol designItems, BinaryFileWriter binWriter)
 {
     for (int i = 0; i < designItems.Count; ++i)
     {
         binWriter.WriteInt(COMPONENT_VERSION);
         binWriter.WriteInt(designItems[i].ItemID);
         binWriter.WriteInt(designItems[i].X);
         binWriter.WriteInt(designItems[i].Y);
         binWriter.WriteInt(designItems[i].Z);
         binWriter.WriteInt(designItems[i].Level);                 // level
         binWriter.WriteInt(designItems[i].Hue);
     }
 }