Example #1
0
        protected override IEnumerator <DeserializeRequest> Deserialize(EasyReader input)
        {
            _query = new Query();

            _query.Name      = input.ReadString();
            _query.Subtype   = input.ReadString();
            _query.Exclusive = input.ReadBoolean();

            // Read filters
            int filterCount = input.ReadInt32();

            for (int i = 0; i < filterCount; i++)
            {
                var filter = Filter.GetFilterInstance(input.ReadUInt16());
                if (filter == null)
                {
                    continue;
                }
                filter.Deserialize(input);
                _query.AddFilter(filter);
            }

            // Carrier
            if (input.ReadBoolean())
            {
                _query.Carrier = new Carrier();
                _query.Carrier.Deserialize(input);
            }

            var complementRequest = new DeserializeRequest();

            yield return(complementRequest);

            _query.Complement = complementRequest.Result;
        }
Example #2
0
        /// <summary>
        /// Loads a package from the specified stream and returns it as a RantPackage object.
        /// </summary>
        /// <param name="source">The stream to load the package data from.</param>
        /// <returns></returns>
        public static RantPackage Load(Stream source)
        {
            using (var reader = new EasyReader(source))
            {
                string magic = Encoding.ASCII.GetString(reader.ReadBytes(4));
                if (magic != MAGIC)
                {
                    throw new InvalidDataException(GetString("err-file-corrupt"));
                }
                ushort version = reader.ReadUInt16();
                if (version != PACKAGE_FORMAT_VERSION)
                {
                    throw new InvalidDataException(GetString("err-invalid-package-version", version));
                }
                bool compress = reader.ReadBoolean();

                var package = new RantPackage();

                package.Title       = reader.ReadString();
                package.ID          = reader.ReadString();
                package.Description = reader.ReadString();
                package.Tags        = reader.ReadStringArray();
                package.Authors     = reader.ReadStringArray();
                int vmaj = reader.ReadInt32();
                int vmin = reader.ReadInt32();
                int vrev = reader.ReadInt32();
                package.Version = new RantPackageVersion(vmaj, vmin, vrev);
                int depCount = reader.ReadInt32();
                for (int i = 0; i < depCount; i++)
                {
                    var  depId         = reader.ReadString();
                    int  depVerMaj     = reader.ReadInt32();
                    int  depVerMin     = reader.ReadInt32();
                    int  depVerRev     = reader.ReadInt32();
                    bool depAllowNewer = reader.ReadBoolean();
                    package.AddDependency(new RantPackageDependency(depId, new RantPackageVersion(depVerMaj, depVerMin, depVerRev))
                    {
                        AllowNewer = depAllowNewer
                    });
                }

                int resCount = reader.ReadInt32();

                if (compress)
                {
                    using (var decompressStream = new DeflateStream(reader.BaseStream, CompressionMode.Decompress, true))
                    {
                        for (int i = 0; i < resCount; i++)
                        {
                            package._resources.Add(RantResource.DeserializeResource(new EasyReader(decompressStream, true)));
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < resCount; i++)
                    {
                        package._resources.Add(RantResource.DeserializeResource(reader));
                    }
                }

                return(package);
            }
        }