Esempio n. 1
0
        private ContentTree ReadContentTree()
        {
            Stream stream;

            if (DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
            {
                stream = DualityApp.SystemBackend.FileSystem.OpenFile(path, FileAccessMode.Read);
            }
            else
            {
                stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            using (stream)
                using (BinaryReader r = new BinaryReader(stream, Encoding.UTF8, true)) {
                    uint signature = r.ReadUInt32();
                    if (signature != 0x5A616544u)
                    {
                        throw new FileLoadException("Invalid CompressedContent file signature");
                    }
                    byte version = r.ReadByte();
                    if (version > 1)
                    {
                        throw new FileLoadException("Unknown CompressedContent version");
                    }

                    long dataOffset = r.ReadUInt32() + 4 + 1 + 4;

                    ContentTree tree = new ContentTree();
                    ReadContentTreeSection(tree.Root, r, dataOffset);
                    return(tree);
                }
        }
Esempio n. 2
0
        public static void Create(string path, ContentTree tree, Func <string, ResourceFlags, ResourceFlags> resourceFlagsModifier = null)
        {
            using (MemoryStream tableStream = new MemoryStream())
                using (MemoryStream dataStream = new MemoryStream()) {
                    WriteContentTreeSection(tree.Root, tableStream, dataStream, resourceFlagsModifier);

                    Stream stream;
                    if (DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
                    {
                        stream = DualityApp.SystemBackend.FileSystem.CreateFile(path);
                    }
                    else
                    {
                        stream = File.Create(path);
                    }

                    using (stream) {
                        using (BinaryWriter w = new BinaryWriter(stream, Encoding.UTF8, true)) {
                            w.Write((uint)0x5A616544u); // Signature
                            w.Write((byte)1);           // Version
                            w.Write((uint)tableStream.Position);
                        }

                        tableStream.Position = 0;
                        tableStream.CopyTo(stream);

                        dataStream.Position = 0;
                        dataStream.CopyTo(stream);
                    }
                }
        }
Esempio n. 3
0
 public void MergeWith(ContentTree tree)
 {
     foreach (KeyValuePair <string, Node> pair in tree.GetNodeListing())
     {
         Node node = AddNodeByPath(pair.Key);
         if (pair.Value.Source != null)
         {
             node.Source = pair.Value.Source;
         }
     }
 }
Esempio n. 4
0
        public CompressedContent(string path)
        {
            this.path = path;

            this.tree = ReadContentTree();
        }