private void OpenImportStream(Stream stream, string fullPath, TextureFormatMode mode) { TextureFormatSerializer curSerializer = null; MetadataReader reader = null; if (mode == TextureFormatMode.Format) { curSerializer = TextureFormatSerializerProvider.FromStream(stream); } else if (mode == TextureFormatMode.Metadata) { reader = XmlMetadataReader.Create(stream); curSerializer = TextureFormatSerializerProvider.FromMetadata(reader); } else { curSerializer = TextureFormatSerializerProvider.FromStream(stream); mode = TextureFormatMode.Format; if (curSerializer == null) { reader = XmlMetadataReader.Create(stream); curSerializer = TextureFormatSerializerProvider.FromMetadata(reader); mode = TextureFormatMode.Metadata; } } if (curSerializer == null) { MessageBox.Show("Unsupported file format!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (reader != null) { reader.Dispose(); } return; } switch (mode) { case TextureFormatMode.Format: SetTexture(curSerializer.Open(stream)); break; case TextureFormatMode.Metadata: SetTexture(curSerializer.Import(reader, Path.GetDirectoryName(fullPath))); break; default: throw new ArgumentException("Should never happen!"); } if (reader != null) { reader.Dispose(); } SetFilename(Path.GetFileName(fullPath)); serializer = curSerializer; }
public void import(string path) { using (Stream s = File.Open(path, FileMode.Open)) { using (MetadataReader reader = XmlMetadataReader.Create(s)) { Texture = serializer.Import(reader, path); } } }