Inheritance: ImportEntry
Esempio n. 1
0
        private void LoadXMLOnClick(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect     = false;
            dialog.Title           = "Choose xml file to open";
            dialog.CheckFileExists = true;
            dialog.Filter          = "xml files (*.xml)|*.xml";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (!File.Exists(dialog.FileName))
                {
                    return;
                }
                XmlDocument dom = new XmlDocument();
                dom.Load(dialog.FileName);

                importlist.Clear();
                OutputBox.Clear();
                if (dom.SelectSingleNode("MassImport") == null)
                {
                    OutputBox.AppendText("Invalid XML" + Environment.NewLine);
                    return;
                }

                int currboxlen = 0;
                foreach (XmlNode xNode in dom.SelectSingleNode("MassImport"))
                {
                    if (xNode.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    ImportEntry entry;
                    switch (xNode.Name.ToLower())
                    {
                    case "item": entry = new ImportEntryItem(); break;

                    case "landtile": entry = new ImportEntryLandTile(); break;

                    case "texture": entry = new ImportEntryTexture(); break;

                    case "gump": entry = new ImportEntryGump(); break;

                    case "tiledataland": entry = new ImportEntryTileDataLand(); break;

                    case "tiledataitem": entry = new ImportEntryTileDataItem(); break;

                    case "hue": entry = new ImportEntryHue(); break;

                    default: entry = new ImportEntryInvalid(); break;
                    }

                    entry.File = xNode.Attributes["file"].InnerText;
                    if (!String.IsNullOrEmpty(entry.File))
                    {
                        entry.File = Path.GetFullPath(entry.File);
                    }

                    int temp;
                    if (FiddlerControls.Utils.ConvertStringToInt(xNode.Attributes["index"].InnerText, out temp))
                    {
                        entry.Index = temp;
                    }
                    else
                    {
                        entry.Index = -1;
                    }
                    entry.Remove = bool.Parse(xNode.Attributes["remove"].InnerText);
                    entry.Valid  = true;

                    string message = entry.Test();

                    if (entry.Valid)
                    {
                        importlist.Add(entry);
                        OutputBox.AppendText(message + Environment.NewLine);
                    }
                    else
                    {
                        OutputBox.AppendText(message + Environment.NewLine);
                        OutputBox.Select(currboxlen, message.Length);
                        OutputBox.SelectionColor = Color.Red;
                    }
                    currboxlen += message.Length;
                    Application.DoEvents();
                }
                OutputBox.AppendText("------------------------------------------------" + Environment.NewLine);
                OutputBox.AppendText(importlist.Count + " valid entries found" + Environment.NewLine);
                if (importlist.Count > 0)
                {
                    button3.Enabled = true;
                }
            }
            dialog.Dispose();
        }
Esempio n. 2
0
        private void LoadXMLOnClick(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Title = "Choose xml file to open";
            dialog.CheckFileExists = true;
            dialog.Filter = "xml files (*.xml)|*.xml";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (!File.Exists(dialog.FileName))
                    return;
                XmlDocument dom = new XmlDocument();
                dom.Load(dialog.FileName);

                importlist.Clear();
                OutputBox.Clear();
                if (dom.SelectSingleNode("MassImport") == null)
                {
                    OutputBox.AppendText("Invalid XML" + Environment.NewLine);
                    return;
                }

                int currboxlen=0;
                foreach (XmlNode xNode in dom.SelectSingleNode("MassImport"))
                {
                    if (xNode.NodeType == XmlNodeType.Comment)
                        continue;

                    ImportEntry entry;
                    switch (xNode.Name.ToLower())
                    {
                        case "item": entry = new ImportEntryItem(); break;
                        case "landtile": entry = new ImportEntryLandTile(); break;
                        case "texture": entry = new ImportEntryTexture(); break;
                        case "gump": entry = new ImportEntryGump(); break;
                        case "tiledataland": entry = new ImportEntryTileDataLand(); break;
                        case "tiledataitem": entry = new ImportEntryTileDataItem(); break;
                        case "hue": entry = new ImportEntryHue(); break;
                        default: entry = new ImportEntryInvalid(); break;
                    }

                    entry.File = xNode.Attributes["file"].InnerText;
                    if (!String.IsNullOrEmpty(entry.File))
                        entry.File = Path.GetFullPath(entry.File);

                    int temp;
                    if (FiddlerControls.Utils.ConvertStringToInt(xNode.Attributes["index"].InnerText, out temp))
                        entry.Index = temp;
                    else
                        entry.Index = -1;
                    entry.Remove = bool.Parse(xNode.Attributes["remove"].InnerText);
                    entry.Valid = true;

                    string message = entry.Test();

                    if (entry.Valid)
                    {
                        importlist.Add(entry);
                        OutputBox.AppendText(message + Environment.NewLine);
                    }
                    else
                    {
                        OutputBox.AppendText(message + Environment.NewLine);
                        OutputBox.Select(currboxlen, message.Length);
                        OutputBox.SelectionColor = Color.Red;
                    }
                    currboxlen += message.Length;
                    Application.DoEvents();
                }
                OutputBox.AppendText("------------------------------------------------" + Environment.NewLine);
                OutputBox.AppendText(importlist.Count + " valid entries found" + Environment.NewLine);
                if (importlist.Count > 0)
                    button3.Enabled = true;
            }
            dialog.Dispose();
        }