public void     Save(SharedTable sharedStringTable, BinaryWriter writer)
        {
            writer.Write(this.assemblyPath);

            writer.Write((UInt16)this.friendAssemblies.Length);
            for (int i = 0, max = this.friendAssemblies.Length; i < max; ++i)
            {
                writer.WriteInt24(sharedStringTable.RegisterString(this.friendAssemblies[i]));
            }

            writer.Write(this.types.Length);
            for (int i = 0, max = this.types.Length; i < max; ++i)
            {
                try
                {
                    writer.WriteInt24(sharedStringTable.RegisterType(this.types[i]));
                }
                catch (Exception ex)
                {
                    Debug.LogError("Type #" + i + " failed.");
                    Debug.LogException(ex);
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        private void    ConstructDatabase(object baseStream)
        {
            try
            {
                using (FileStream fileStream = (FileStream)baseStream)
                    using (GZipStream decompressionStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        MemoryStream databaseStream = new MemoryStream(1 << 24);                    // 16MB

                        fileStream.Position = this.sharedTableOffset;

                        const int BufferSize = 1 << 16;                       // 64kB
                        byte[]    buffer     = new byte[BufferSize];
                        int       n          = decompressionStream.Read(buffer, 0, BufferSize);

                        while (n == BufferSize)
                        {
                            databaseStream.Write(buffer, 0, n);
                            n = decompressionStream.Read(buffer, 0, BufferSize);
                        }

                        if (n > 0)
                        {
                            databaseStream.Write(buffer, 0, n);
                        }
                        databaseStream.Seek(0L, SeekOrigin.Begin);

                        BinaryReader reader = new BinaryReader(databaseStream, Encoding.UTF8);

                        this.sharedTable = new SharedTable(reader);

                        List <UnityMeta> result = new List <UnityMeta>(this.metaOffsets.Length);

                        for (int i = 0, max = this.metaOffsets.Length; i < max; ++i)
                        {
                            reader.BaseStream.Position = this.metaOffsets[i];
                            result.Add(new UnityMeta(reader, this.sharedTable));
                        }

                        result.Sort((a, b) => Utility.CompareVersion(a.Version, b.Version));

                        this.unityMeta      = result.ToArray();
                        this.databaseStream = databaseStream;
                    }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                this.constructingThread = null;
            }
        }
Exemplo n.º 3
0
        public void     Save(BinaryWriter writer, SharedTable sharedStringTable)
        {
            writer.Write(this.version);

            // Write Types into the buffer to populate the string table.
            writer.Write((UInt16)this.assembliesMeta.Length);
            for (int i = 0, max = this.assembliesMeta.Length; i < max; ++i)
            {
                writer.WriteInt24(sharedStringTable.RegisterAssembly(this.assembliesMeta[i]));
            }
        }
Exemplo n.º 4
0
        /// <summary>Saves the current state of the database to <paramref name="filepath"/>.</summary>
        /// <param name="filepath"></param>
        public void     Save(string filepath)
        {
            using (MemoryStream assembliesStream = new MemoryStream(1 << 27))             // 128MB
                using (BinaryWriter assembliesWriter = new BinaryWriter(assembliesStream))
                {
                    SharedTable      sharedTable = new SharedTable();
                    List <UnityMeta> sortedMeta  = new List <UnityMeta>(this.unityMeta);
                    long[]           metaOffsets = new long[this.unityMeta.Length];

                    sortedMeta.Sort((a, b) => Utility.CompareVersion(a.Version, b.Version));

                    // Write assemblies into the buffer to populate the string table.
                    for (int i = 0, max = sortedMeta.Count; i < max; ++i)
                    {
                        metaOffsets[i] = assembliesWriter.BaseStream.Position;
                        sortedMeta[i].Save(assembliesWriter, sharedTable);
                    }

                    using (MemoryStream sharedTableStream = new MemoryStream(1 << 22))             // 4MB
                        using (BinaryWriter sharedTableWriter = new BinaryWriter(sharedTableStream))
                        {
                            sharedTable.Save(sharedTableWriter);

                            using (BinaryWriter finalWriter = new BinaryWriter(File.Open(filepath, FileMode.Create, FileAccess.Write)))
                                using (GZipStream compressionStream = new GZipStream(finalWriter.BaseStream, CompressionMode.Compress, true))
                                {
                                    finalWriter.Write(metaOffsets.Length);

                                    for (int i = 0, max = metaOffsets.Length; i < max; ++i)
                                    {
                                        finalWriter.Write(metaOffsets[i] + sharedTableStream.Length);
                                        finalWriter.Write(sortedMeta[i].Version);
                                    }

                                    sharedTableStream.WriteTo(compressionStream);
                                    assembliesStream.WriteTo(compressionStream);
                                }
                        }
                }
        }