Inheritance: EndianBinaryWriter
Beispiel #1
0
        public void WritePssg(Stream fileStream)
        {
            using (PssgBinaryWriter writer = new PssgBinaryWriter(EndianBitConverter.Big, fileStream, true))
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    // make all ids -1
                    PssgSchema.ClearSchemaIds();

                    // Get the counts, and update ids of the nodes/attributes used in this file
                    GetNodeAttributeNameCount(this, out var nodeNameCount, out var attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);

                    // Update ids again to make sequential and save ones used in this file
                    PssgSchema.SaveToPssg(writer);

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }

                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);
            }
Beispiel #2
0
        public void WritePssg(Stream fileStream, bool close)
        {
            PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream);

            try
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    int nodeNameCount      = 0;
                    int attributeNameCount = 0;
                    PssgSchema.ClearSchemaIds(); // make all ids -1
                    RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);
                    PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }
                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);

                if (close)
                {
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                throw ex;
            }
        }
        public static void SaveToPssg(PssgBinaryWriter writer)
        {
            // Update Ids to make sequential, and Unique
            int currentId     = 0;
            int currentAttrId = 0;

            // Minimizing the attributes to unique names only seems to crash the game
            //Dictionary<string, int> unique = new Dictionary<string, int>();

            foreach (KeyValuePair <string, Node> entry in entries)
            {
                if (entry.Value.Id > 0)
                {
                    entry.Value.Id = ++currentId;
                    writer.Write(entry.Value.Id);
                    writer.WritePSSGString((string)entry.Key);

                    int pos            = (int)writer.BaseStream.Position;
                    int attributeCount = 0;
                    writer.Write(0); // attributeCount

                    foreach (Attribute attrEntry in entry.Value.Attributes)
                    {
                        if (attrEntry.Id > 0)
                        {
                            attrEntry.Id = ++currentAttrId;
                            writer.Write(attrEntry.Id);
                            writer.WritePSSGString(attrEntry.Name);
                            ++attributeCount;
                        }
                    }

                    writer.Seek(pos, SeekOrigin.Begin);
                    writer.Write(attributeCount);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
Beispiel #4
0
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(size);
     writer.Write(attributeSize);
     if (Attributes != null)
     {
         foreach (PssgAttribute attr in Attributes)
         {
             attr.Write(writer);
         }
     }
     if (this.IsDataNode)
     {
         writer.WriteObject(data);
     }
     else
     {
         foreach (PssgNode node in ChildNodes)
         {
             node.Write(writer);
         }
     }
 }
 private void exportNodeDataToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SaveFileDialog dialog = new SaveFileDialog();
     dialog.Filter = "Bin files|*.bin|All files|*.*";
     dialog.Title = "Select the byte data save location and file name";
     dialog.DefaultExt = "bin";
     dialog.FileName = "nodeData.bin";
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             PssgNode node = ((PssgNode)treeView.SelectedNode.Tag);
             using (PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), File.Open(dialog.FileName, FileMode.Create)))
             {
                 writer.WriteObject(node.Value);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Could not export data!" + Environment.NewLine + Environment.NewLine +
                 ex.Message, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        public void WritePssg(Stream fileStream, bool close)
        {
            PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream);
            try
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    int nodeNameCount = 0;
                    int attributeNameCount = 0;
                    PssgSchema.ClearSchemaIds(); // make all ids -1
                    RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);
                    PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }
                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);

                if (close)
                {
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                throw ex;
            }
        }
Beispiel #7
0
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(size);
     writer.Write(attributeSize);
     if (Attributes != null)
     {
         foreach (PssgAttribute attr in Attributes)
         {
             attr.Write(writer);
         }
     }
     if (this.IsDataNode)
     {
         writer.WriteObject(data);
     }
     else
     {
         foreach (PssgNode node in ChildNodes)
         {
             node.Write(writer);
         }
     }
 }
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(this.size);
     writer.WriteObject(this.data);
 }
Beispiel #9
0
        public static void SaveToPssg(PssgBinaryWriter writer)
        {
            // Update Ids to make sequential, and Unique
            int currentId = 0;
            int currentAttrId = 0;
            // Minimizing the attributes to unique names only seems to crash the game
            //Dictionary<string, int> unique = new Dictionary<string, int>();

            foreach (KeyValuePair<string, Node> entry in entries)
            {
                if (entry.Value.Id > 0)
                {
                    entry.Value.Id = ++currentId;
                    writer.Write(entry.Value.Id);
                    writer.WritePSSGString((string)entry.Key);

                    int pos = (int)writer.BaseStream.Position;
                    int attributeCount = 0;
                    writer.Write(0); // attributeCount

                    foreach (Attribute attrEntry in entry.Value.Attributes)
                    {
                        if (attrEntry.Id > 0)
                        {
                            attrEntry.Id = ++currentAttrId;
                            writer.Write(attrEntry.Id);
                            writer.WritePSSGString(attrEntry.Name);
                            ++attributeCount;
                        }
                    }

                    writer.Seek(pos, SeekOrigin.Begin);
                    writer.Write(attributeCount);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(this.size);
     writer.WriteObject(this.data);
 }