Пример #1
0
        public PssgFile(System.IO.Stream fileStream)
        {
            using (PssgBinaryReader reader = new PssgBinaryReader(new BigEndianBitConverter(), fileStream))
            {
                magic = reader.ReadPSSGString(4);
                if (magic != "PSSG")
                {
                    throw new Exception("This is not a PSSG file!");
                }
                int size = reader.ReadInt32();
                int attributeInfoCount = reader.ReadInt32();
                int nodeInfoCount = reader.ReadInt32();

                attributeInfo = new PssgAttributeInfo[attributeInfoCount];
                nodeInfo = new PssgNodeInfo[nodeInfoCount];

                for (int i = 0; i < nodeInfoCount; i++)
                {
                    nodeInfo[i] = new PssgNodeInfo(reader, this);
                }
                long positionAfterInfo = reader.BaseStream.Position;

                rootNode = new PssgNode(reader, this, null, true);
                if (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    reader.BaseStream.Position = positionAfterInfo;
                    rootNode = new PssgNode(reader, this, null, false);
                    if (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        throw new Exception("This file is improperly saved and not supported by this version of the PSSG editor." + Environment.NewLine + Environment.NewLine +
                            "Get an older version of the program if you wish to take out its contents, but put it back together using this program and the original version of the pssg file.");
                    }
                }
            }
        }
Пример #2
0
 public PssgAttributeInfo AddAttributeInfo(string name, PssgNodeInfo nodeInfo)
 {
     // For each attributeInfo in nodeInfo, the ids have to be consecutive
     if (GetAttributeInfo(name).Length > 0)
     {
         return null;
     }
     if (attributeInfo == null)
     {
         attributeInfo = new PssgAttributeInfo[1];
     }
     else
     {
         Array.Resize(ref attributeInfo, attributeInfo.Length + 1);
     }
     int newID = 0;
     List<int> currentKeys = new List<int>(nodeInfo.attributeInfo.Keys);
     if (currentKeys.Count > 0)
     {
         foreach (int k in currentKeys)
         {
             newID = Math.Max(newID, k);
         }
         newID++;
     }
     else
     {
         newID = attributeInfo.Length;
     }
     PssgAttributeInfo attrInfo = new PssgAttributeInfo(newID, name);
     if (newID == attributeInfo.Length)
     {
         attributeInfo[attrInfo.id - 1] = attrInfo;
         this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
     }
     else
     {
         for (int i = attributeInfo.Length - 2; i >= newID - 1; i--)
         {
             attributeInfo[i + 1] = attributeInfo[i];
             attributeInfo[i + 1].id = i + 2;
         }
         attributeInfo[attrInfo.id - 1] = attrInfo;
         this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
         // Fix the NodeInfos
         foreach (PssgNodeInfo nInfo in this.nodeInfo)
         {
             List<int> keys = new List<int>(nInfo.attributeInfo.Keys);
             //keys.Sort();
             if (nInfo != nodeInfo)
             {
                 for (int i = keys.Count - 1; i >= 0; i--)
                 {
                     if (keys[i] >= newID)
                     {
                         PssgAttributeInfo aInfo = attributeInfo[keys[i]];
                         nInfo.attributeInfo.Remove(keys[i]);
                         nInfo.attributeInfo.Add(keys[i] + 1, aInfo);
                     }
                 }
             }
         }
         // Edit CNode to fix CAttr.id
         rootNode.AddAttributeInfo(newID);
     }
     return attrInfo;
 }
Пример #3
0
 public PssgNodeInfo AddNodeInfo(string name)
 {
     if (GetNodeInfo(name).Length > 0)
     {
         return null;
     }
     if (nodeInfo == null)
     {
         nodeInfo = new PssgNodeInfo[1];
     }
     else
     {
         Array.Resize(ref nodeInfo, nodeInfo.Length + 1);
     }
     PssgNodeInfo nInfo = new PssgNodeInfo(nodeInfo.Length, name);
     nodeInfo[nInfo.id - 1] = nInfo;
     return nInfo;
 }