Exemple #1
0
        private void ReadBundleListing(string nameOfBundle)
        {
            int num;

            if (!this.json.Read())
            {
                throw new JsonException("End of stream unexpected");
            }
            if (this.json.Token != JsonToken.ObjectStart)
            {
                throw new JsonException(string.Concat("Expected object start for bundle name (property) ", nameOfBundle));
            }
            this.item.Name       = nameOfBundle;
            this.item.ByteLength = -1;
            while (true)
            {
                if (!this.json.Read())
                {
                    throw new JsonException("Unexpected end of stream");
                }
                if (this.json.Token == JsonToken.ObjectEnd)
                {
                    if (string.IsNullOrEmpty(this.item.Path))
                    {
                        throw new JsonException(string.Concat("Path to bundle not defined for bundle listing ", nameOfBundle));
                    }
                    if (this.item.ByteLength == -1)
                    {
                        throw new JsonException(string.Concat("There was no size property for bundle listing ", nameOfBundle));
                    }
                    ContentType contentType = this.item.ContentType;
                    if (contentType != ContentType.Assets)
                    {
                        if (contentType != ContentType.Scenes)
                        {
                            throw new JsonException(string.Concat(new object[] { "The content ", this.item.ContentType, " was not handled for bundle listing ", nameOfBundle }));
                        }
                        if (this.item.TypeOfAssets != null)
                        {
                            throw new JsonException(string.Concat("There should not have been a type property for scene bundle listing ", nameOfBundle));
                        }
                    }
                    else if (this.item.TypeOfAssets == null)
                    {
                        throw new JsonException(string.Concat("There was no valid type property for asset bundle listing ", nameOfBundle));
                    }
                    return;
                }
                if (this.json.Token != JsonToken.PropertyName)
                {
                    throw new JsonException(string.Concat("Unexpected token in json : JsonToken.", this.json.Token));
                }
                bool   flag     = false;
                string asString = this.json.Value.AsString;
                if (asString == null)
                {
                    break;
                }
                if (Reader.< > f__switch$map4 == null)
                {
                    Dictionary <string, int> strs = new Dictionary <string, int>(5)
                    {
                        { "type", 0 },
                        { "size", 1 },
                        { "content", 2 },
                        { "filename", 3 },
                        { "url", 4 }
                    };
                    Reader.< > f__switch$map4 = strs;
                }
                if (!Reader.< > f__switch$map4.TryGetValue(asString, out num))
                {
                    break;
                }
                switch (num)
                {
                case 0:
                {
                    if (!this.json.Read())
                    {
                        throw new JsonException("Unexpected end of stream at type");
                    }
                    switch (this.json.Token)
                    {
                    case JsonToken.String:
                    {
                        try
                        {
                            this.item.TypeOfAssets = Reader.ParseType(this.json.Value.AsString);
                        }
                        catch (TypeLoadException typeLoadException)
                        {
                            throw new JsonException(this.json.Value.AsString, typeLoadException);
                        }
                        break;
                    }

                    case JsonToken.Boolean:
                    {
                        throw new JsonException(string.Concat("the type property expects only null or string. got : ", this.json.Token));
                    }

                    case JsonToken.Null:
                    {
                        this.item.TypeOfAssets = null;
                        break;
                    }

                    default:
                    {
                        throw new JsonException(string.Concat("the type property expects only null or string. got : ", this.json.Token));
                    }
                    }
                    break;
                }

                case 1:
                {
                    if (!this.json.Read())
                    {
                        throw new JsonException("Unexpected end of stream at size");
                    }
                    switch (this.json.Token)
                    {
                    case JsonToken.Int:
                    case JsonToken.Float:
                    {
                        this.item.ByteLength = this.json.Value.AsInt;
                        break;
                    }

                    case JsonToken.Reserved:
                    {
                        throw new JsonException(string.Concat("the size property expects a number. got : ", this.json.Token));
                    }

                    default:
                    {
                        throw new JsonException(string.Concat("the size property expects a number. got : ", this.json.Token));
                    }
                    }
                    break;
                }

                case 2:
                {
                    if (!this.json.Read())
                    {
                        throw new JsonException("Unexpected end of stream at content");
                    }
                    switch (this.json.Token)
                    {
                    case JsonToken.Int:
                    {
                        this.item.ContentType = (ContentType)((byte)this.json.Value.AsInt);
                        break;
                    }

                    case JsonToken.Reserved:
                    case JsonToken.Float:
                    {
                        throw new JsonException(string.Concat("the content property expects a string or int. got : ", this.json.Token));
                    }

                    case JsonToken.String:
                    {
                        try
                        {
                            this.item.ContentType = (ContentType)((byte)Enum.Parse(typeof(ContentType), this.json.Value.AsString, true));
                        }
                        catch (ArgumentException argumentException)
                        {
                            throw new JsonException(this.json.Value.AsString, argumentException);
                        }
                        catch (OverflowException overflowException)
                        {
                            throw new JsonException(this.json.Value.AsString, overflowException);
                        }
                        break;
                    }

                    default:
                    {
                        throw new JsonException(string.Concat("the content property expects a string or int. got : ", this.json.Token));
                    }
                    }
                    break;
                }

                case 3:
                {
                    if (!this.json.Read())
                    {
                        throw new JsonException("Unexpected end of stream at filename");
                    }
                    if (this.json.Token != JsonToken.String)
                    {
                        throw new JsonException(string.Concat("the filename property expects a string. got : ", this.json.Token));
                    }
                    if (!flag)
                    {
                        try
                        {
                            this.item.Path = this.PathToBundle(this.json.Value.AsString);
                        }
                        catch (Exception exception)
                        {
                            throw new JsonException(this.json.Value.AsString, exception);
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                case 4:
                {
                    if (!this.json.Read())
                    {
                        throw new JsonException("Unexpected end of stream at url");
                    }
                    if (this.json.Token != JsonToken.String)
                    {
                        throw new JsonException(string.Concat("the url property expects a string. got : ", this.json.Token));
                    }
                    try
                    {
                        this.item.Path = this.json.Value.AsString;
                    }
                    catch (Exception exception1)
                    {
                        throw new JsonException(this.json.Value.AsString, exception1);
                    }
                    flag = true;
                    break;
                }

                default:
                {
                    throw new JsonException(string.Concat("Unhandled property named ", this.json.Value.AsString));
                }
                }
            }
            throw new JsonException(string.Concat("Unhandled property named ", this.json.Value.AsString));
        }