static void Main() { AnimationXML = new XmlData.RootNode(); LogForm = null; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainWindow()); }
/// <summary> /// Convert the Xml to a DOT and returns the result as string. /// </summary> /// <param name="model">The root node of xml file.</param> /// <returns></returns> static public string ProcessXml(XmlData.RootNode model) { var animations = model.Animations; if (model.Animations == null) { Console.WriteLine("No animations found exiting."); return(null); } animationTitle = model.Header.Title; return(ProcessAnimations(model.Animations.Animation)); }
public async void AnalyseXMLFile() { checkBox2.CheckState = CheckState.Indeterminate; checkBox2.Tag = 1; XmlClass = new Xml(); XmlAni = new Animations(XmlClass); try { XmlSerializer mySerializer = new XmlSerializer(typeof(XmlData.RootNode)); using (MemoryStream stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream)) { await writer.WriteAsync(XmlContent); writer.Flush(); stream.Position = 0; XmlNode = (XmlData.RootNode)mySerializer.Deserialize(stream); } } MemoryStream imageStream = null; imageStream = new MemoryStream(Convert.FromBase64String(XmlNode.Image.Png)); var image = new Bitmap(imageStream); // no longer need stream imageStream.Close(); XmlClass.spriteWidth = image.Width / XmlNode.Image.TilesX; XmlClass.spriteHeight = image.Height / XmlNode.Image.TilesY; XmlClass.sprites = BuildSprites(image, XmlClass.spriteWidth, XmlClass.spriteHeight); image.Dispose(); XmlClass.bitmapIcon = new MemoryStream(Convert.FromBase64String(XmlNode.Header.Icon)); checkBox2.CheckState = CheckState.Checked; checkBox2.Tag = 2; label3.Text = "XML IS VALID"; } catch (Exception ex) { label3.Text = "FAILED: " + ex.Message; } AnalyseXMLError(); if (checkBox2.CheckState == CheckState.Checked) { await AnalyseAnimations(); } }
private async void OpenXMLFile() { checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; label2.Text = "-"; label3.Text = "-"; label4.Text = "-"; checkBox1.Tag = 0; checkBox2.Tag = 0; checkBox3.Tag = 0; textBox1.Visible = false; timer1.Enabled = false; XmlClass = null; XmlAni = null; XmlNode = null; XmlContent = ""; checkBox1.CheckState = CheckState.Indeterminate; checkBox1.Tag = 1; int bytesRead = 0; byte[] buffer = new byte[1024 * 64]; try { using (var fs = File.OpenRead(XmlFileName)) { do { bytesRead = await fs.ReadAsync(buffer, 0, 1024 * 64); XmlContent += Encoding.UTF8.GetString(buffer, 0, bytesRead); } while (bytesRead > 0); fs.Close(); } checkBox1.CheckState = CheckState.Checked; checkBox1.Tag = 2; label2.Text = "SUCCESS"; } catch (Exception ex) { label2.Text = "FAILED: " + ex.Message; } if (checkBox1.CheckState == CheckState.Checked) { AnalyseXMLFile(); } }
/// <summary> /// This function will load the XML. If something can't be loaded as expected, the default XML will be loaded. /// </summary> /// <returns>true, if the XML was loaded successfully.</returns> public bool readXML() { bool bError = false; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(XmlData.RootNode)); // To read the file, create a FileStream. MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); // Try to load local XML try { writer.Write(Program.MyData.GetXml()); AnimationXMLString = Program.MyData.GetXml(); //writer.Write(Properties.Resources.animations); writer.Flush(); stream.Position = 0; // Call the Deserialize method and cast to the object type. AnimationXML = (XmlData.RootNode)mySerializer.Deserialize(stream); stream.Close(); Program.MyData.SetImages(AnimationXML.Image.Png); Program.MyData.SetIcon(AnimationXML.Header.Icon); } catch (Exception ex) { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.warning, "User XML error: " + ex.ToString()); if (Program.MyData.GetXml().Length > 100) { MessageBox.Show("Error parsing animation XML:" + ex.ToString(), "XML error", MessageBoxButtons.OK, MessageBoxIcon.Error); } stream.Flush(); stream.Position = 0; writer.Write(Properties.Resources.animations); writer.Flush(); AnimationXMLString = Properties.Resources.animations; stream.Position = 0; // Call the Deserialize method and cast to the object type. AnimationXML = (XmlData.RootNode)mySerializer.Deserialize(stream); Program.MyData.SetXml(Properties.Resources.animations, "esheep64"); Program.MyData.SetImages(AnimationXML.Image.Png); Program.MyData.SetIcon(AnimationXML.Header.Icon); } finally { // if the images were loaded from external make some memory available. // don't need it again as its in Properties.Settings.Default.Images AnimationXML.Image.Png = string.Empty; // don't need it again as its in Properties.Settings.Default.Icon AnimationXML.Header.Icon = string.Empty; try { readImages(); if (AnimationXML.Header.Petname.Length > 16) { AnimationXML.Header.Petname = AnimationXML.Header.Petname.Substring(0, 16); } } catch (Exception ex) { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.error, "Error reading XML: " + ex.Message); bError = true; } } if (bError) { MessageBox.Show("Error, can't load animations file. The original pet will be loaded", "XML error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(!bError); }