Example #1
0
        public static IPackage LoadPackage(string filename)
        {
            var fs = File.OpenRead(filename);
            var s  = new BinaryFileHelper(fs);

            try
            {
                if (s.ReadString() != "HuiDesktopPackage")
                {
                    throw new InvalidDataException();
                }
                var version = s.ReadByte();
                switch (version)
                {
                case 3:
                    return(new V3Package(fs));

                case 4:
                    return(new V4Package(fs));

                default:
                    throw new NotSupportedException();
                }
            }
            catch (EndOfStreamException)
            {
                throw new InvalidDataException();
            }
        }
Example #2
0
        public void Export(Stream stream)
        {
            var writer = new BinaryFileHelper(stream);

            writer.WriteString("HuiDesktopPackage");
            writer.WriteByte(4);
            //writer = new BinaryFileHelper(new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionLevel.Optimal));
            using (writer = new BinaryFileHelper(new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionLevel.Optimal)))
            {
                writer.WriteString(strongName);
                writer.WriteString(friendlyName);
                writer.WriteString(description);

                writer.WriteUnsignedInt(startupInfos.Count);
                foreach (var i in startupInfos)
                {
                    writer.WriteString(i.name);
                    writer.WriteString(i.url);
                    writer.WriteUnsignedInt(i.dependencies.Count);
                    foreach (var ii in i.dependencies)
                    {
                        writer.WriteString(ii);
                    }
                }

                writer.WriteUnsignedInt(files.Count);
                foreach (var i in files)
                {
                    writer.WriteString(i.Key);
                    writer.WriteUnsignedInt((int)i.Value.Length);
                    i.Value.Position = 0;
                    writer.CopyFrom(i.Value);
                }
            }
        }
Example #3
0
        public V4Package(Stream stream)
        {
            var reader = new BinaryFileHelper(new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Decompress));

            //var reader = new BinaryFileHelper(stream);
            strongName   = reader.ReadString();
            friendlyName = reader.ReadString();
            description  = reader.ReadString();

            for (int i = reader.ReadUnsignedInt(); i > 0; --i)
            {
                var name = reader.ReadString();
                var url  = reader.ReadString();
                var d    = new List <string>();
                for (int ii = reader.ReadUnsignedInt(); ii > 0; --ii)
                {
                    d.Add(reader.ReadString());
                }
                startupInfos.Add(new StartupInfo
                {
                    dependencies = d,
                    name         = name,
                    url          = url,
                    fromPackage  = this
                });
            }

            for (int i = reader.ReadUnsignedInt(); i > 0; --i)
            {
                string name   = reader.ReadString();
                int    length = reader.ReadUnsignedInt();
                var    mem    = new MemoryStream();
                reader.CopyTo(mem, length);
                files[name] = mem;
            }
        }