Ejemplo n.º 1
0
        public Resource Deserialize(Stream inputStream)
        {
            var res = new IniResource();

            res.Load(inputStream, fileSource);
            return(res.ToResource());
        }
Ejemplo n.º 2
0
        public static IniResource FromResource(Resource res, string resName)
        {
            var result = new IniResource(res.Version);

            int i = 0;

            foreach (var data in res.GetLayers())
            {
                var handler = Handlers.Get(data);
                if (handler == null)
                {
                    continue;
                }

                // generate file names for external files
                var externalFiles = new Dictionary <string, string>();
                foreach (var key in handler.ExternalFileKeys)
                {
                    var ext = handler.GetExternalFileExtension(key, data);
                    externalFiles[key] = (ext != null) ?  $"{resName}_{i}{ext}" : null;
                }

                result.Layers.Add(new IniLayer(data, externalFiles));
                i++;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void FromResourceWorks()
        {
            var res = new Resource(3, new object[] {
                new FontLayer {
                    Data = new byte[] { 1, 2 }, Type = 0
                },
                new AnimLayer {
                    Duration = 1, Id = 2, Frames = new short[] { 3, 4, 5 }
                },
                new UnknownLayer("unknown", new byte[] { 71, 1 }),
            });

            var iniRes = IniResource.FromResource(res, "foo");

            Assert.That(iniRes.Version, Is.EqualTo(res.Version));
            Assert.That(iniRes.Layers.Count, Is.EqualTo(res.GetLayers().Count()));

            var fontLayer = iniRes.Layers.FirstOrDefault(x => x.Data is FontLayer);

            Assert.That(fontLayer, Is.Not.Null);
            Assert.That(fontLayer.ExternalFiles.Count, Is.EqualTo(1));

            var animLayer = iniRes.Layers.FirstOrDefault(x => x.Data is AnimLayer);

            Assert.That(animLayer, Is.Not.Null);

            var unknownLayer = iniRes.Layers.FirstOrDefault(x => x.Data is UnknownLayer);

            Assert.That(unknownLayer, Is.Not.Null);
        }