public AvaloniaResources(AssemblyDefinition asm, string projectDir) { _asm = asm; _embedded = ((EmbeddedResource)asm.MainModule.Resources.FirstOrDefault(r => r.ResourceType == ResourceType.Embedded && r.Name == "!AvaloniaResources")); if (_embedded == null) { return; } using (var stream = _embedded.GetResourceStream()) { var br = new BinaryReader(stream); var index = AvaloniaResourcesIndexReaderWriter.Read(new MemoryStream(br.ReadBytes(br.ReadInt32()))); var baseOffset = stream.Position; foreach (var e in index) { stream.Position = e.Offset + baseOffset; _resources[e.Path] = new AvaloniaResource(this, projectDir, e.Path, br.ReadBytes(e.Size)); } } }
public AssemblyDescriptor(Assembly assembly) { Assembly = assembly; if (assembly != null) { Resources = assembly.GetManifestResourceNames() .ToDictionary(n => n, n => (IAssetDescriptor) new AssemblyResourceDescriptor(assembly, n)); Name = assembly.GetName().Name; using (var resources = assembly.GetManifestResourceStream(AvaloniaResourceName)) { if (resources != null) { Resources.Remove(AvaloniaResourceName); var indexLength = new BinaryReader(resources).ReadInt32(); var index = AvaloniaResourcesIndexReaderWriter.Read(new SlicedStream(resources, 4, indexLength)); var baseOffset = indexLength + 4; AvaloniaResources = index.ToDictionary(r => "/" + r.Path !.TrimStart('/'), r => (IAssetDescriptor) new AvaloniaResourceDescriptor(assembly, baseOffset + r.Offset, r.Size)); } } } }