Esempio n. 1
0
File: Skin.cs Progetto: bdach/osu
        protected Skin(SkinInfo skin, IStorageResourceProvider resources, [CanBeNull] Stream configurationStream = null)
        {
            SkinInfo       = skin.ToLive();
            this.resources = resources;

            configurationStream ??= getConfigurationStream();

            if (configurationStream != null)
            {
                // stream will be closed after use by LineBufferedReader.
                ParseConfigurationStream(configurationStream);
            }
            else
            {
                Configuration = new SkinConfiguration();
            }

            // skininfo files may be null for default skin.
            SkinInfo.PerformRead(s =>
            {
                // we may want to move this to some kind of async operation in the future.
                foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
                {
                    string filename = $"{skinnableTarget}.json";

                    // skininfo files may be null for default skin.
                    var fileInfo = s.Files.FirstOrDefault(f => f.Filename == filename);

                    if (fileInfo == null)
                    {
                        continue;
                    }

                    byte[] bytes = resources?.Files.Get(fileInfo.File.GetStoragePath());

                    if (bytes == null)
                    {
                        continue;
                    }

                    try
                    {
                        string jsonContent      = Encoding.UTF8.GetString(bytes);
                        var deserializedContent = JsonConvert.DeserializeObject <IEnumerable <SkinnableInfo> >(jsonContent);

                        if (deserializedContent == null)
                        {
                            continue;
                        }

                        DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Failed to load skin configuration.");
                    }
                }
            });
        }
Esempio n. 2
0
        protected Skin(SkinInfo skin, IStorageResourceProvider?resources, IResourceStore <byte[]>?storage = null, string configurationFilename = @"skin.ini")
        {
            if (resources != null)
            {
                SkinInfo = skin.ToLive(resources.RealmAccess);

                storage ??= realmBackedStorage = new RealmBackedResourceStore <SkinInfo>(SkinInfo, resources.Files, resources.RealmAccess);

                (storage as ResourceStore <byte[]>)?.AddExtension("ogg");

                var samples = resources.AudioManager?.GetSampleStore(storage);
                if (samples != null)
                {
                    samples.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
                }

                Samples  = samples;
                Textures = new TextureStore(resources.CreateTextureLoaderStore(storage));
            }
            else
            {
                // Generally only used for tests.
                SkinInfo = skin.ToLiveUnmanaged();
            }

            var configurationStream = storage?.GetStream(configurationFilename);

            if (configurationStream != null)
            {
                // stream will be closed after use by LineBufferedReader.
                ParseConfigurationStream(configurationStream);
                Debug.Assert(Configuration != null);
            }
            else
            {
                Configuration = new SkinConfiguration();
            }

            // skininfo files may be null for default skin.
            foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
            {
                string filename = $"{skinnableTarget}.json";

                byte[]? bytes = storage?.Get(filename);

                if (bytes == null)
                {
                    continue;
                }

                try
                {
                    string jsonContent         = Encoding.UTF8.GetString(bytes);
                    var    deserializedContent = JsonConvert.DeserializeObject <IEnumerable <SkinnableInfo> >(jsonContent);

                    if (deserializedContent == null)
                    {
                        continue;
                    }

                    DrawableComponentInfo[skinnableTarget] = deserializedContent.ToArray();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Failed to load skin configuration.");
                }
            }
        }