public void LoadImageAndAtlas() { try { XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlas)); using (FileStream stream = new FileStream(atlasXMLPath, FileMode.Open)) { TextureAtlas textureAtlas = serializer.Deserialize(stream) as TextureAtlas; CurrentTextureAtlas = new TextureAtlasViewModel(textureAtlas, imagePath); this.eventAggregator.Publish(new ImageLoadedEvent() { Image = CurrentTextureAtlas.Image }); } } catch (Exception ex) { String debugMe = String.Empty; } }
public void LoadFile() { FileInfo info = new FileInfo(filePath); TextureAtlas textureAtlas = null; String atlasPath = String.Empty; if (info.Extension.ToLower().Contains("xml")) atlasPath = filePath; else { atlasPath = filePath.Replace(info.Extension, ".xml"); //We're loading an image. Look for the corresponding atlas in the same directory. if (!File.Exists(atlasPath)) { //Prompt for the atlas creation CreateAtlasPromptViewModel vm = new CreateAtlasPromptViewModel(info.Name); bool? rtn = windowManager.ShowDialog(vm); if (rtn == true) { //Create an empty atlas file with the same name as the image in the same directory textureAtlas = new TextureAtlas(); textureAtlas.ImagePath = info.Name; //Relative try { using (FileStream stream = new FileStream(atlasPath, FileMode.OpenOrCreate)) { XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlas)); serializer.Serialize(stream, textureAtlas); } } catch (Exception ex) { String debugMe = String.Empty; return; } } else return; } } //Try to deserialize the atlas path //Check for the image path //Load image using (FileStream stream = new FileStream(atlasPath, FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlas)); textureAtlas = serializer.Deserialize(stream) as TextureAtlas; } String imagePath = textureAtlas.ImagePath; if(!Path.IsPathRooted(imagePath)) imagePath = String.Format(@"{0}/{1}", info.Directory, imagePath); TextureAtlasViewModel textureAtlasViewModel = new TextureAtlasViewModel(textureAtlas, imagePath); FilePath = String.Empty; this.eventAggregator.Publish(new Events.AtlasLoadedEvent() { Atlas = textureAtlasViewModel }); }