Ejemplo n.º 1
0
Archivo: PM.cs Proyecto: cdag/WMD
        public ModColl readXmlPackage(FileInfo fi)
        {
            ModColl nmc    = null;
            var     reader = new XmlTextReader(fi.FullName);

            if (fi.Exists)
            {
                try
                {
                    while (reader.Read())
                    {
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Wadpack"))
                        {
                            nmc = new ModColl(reader.GetAttribute("name"), reader.GetAttribute("srcPrt"));
                            bool quit = false;
                            while (quit == false)
                            {
                                reader.Read();
                                switch (reader.NodeType)
                                {
                                case XmlNodeType.EndElement:     //Display the end of the element.
                                    if (reader.Name == "Wadpack")
                                    {
                                        quit = true;
                                    }
                                    break;

                                case XmlNodeType.Element:     //Display the text in each element.
                                    if (reader.Name == "Wad")
                                    {
                                        string attr = "0";
                                        if (reader.HasAttributes)
                                        {
                                            attr = reader.GetAttribute("loadorder");
                                        }
                                        reader.Read();
                                        nmc.Add(new Mod(true, attr, new FileInfo(MODDIRECTORY + reader.Value.ToString())));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    reader.Close();
                    fi.Delete();
                }
                catch (XmlException e)
                {
                    reader.Close();
                    fi.Delete();
                }
            }

            return(nmc);
        }
Ejemplo n.º 2
0
        void validateNewModColl()
        {
            if (TXTBX__MODCOLL_NAME.Text.Equals(pm.txt("[none]")))
            {
                return;
            }
            if (string.IsNullOrEmpty(TXTBX__MODCOLL_NAME.Text))
            {
                return;
            }

            var q = (from item in pm.getModColllist()
                     where item.name.Equals(TXTBX__MODCOLL_NAME.Text)
                     select item);

            if (q.Count() > 0)
            {
                pm.removeModColl(q.First());
            }

            string srcPrt = "";

            if (CHKBX_ASSOC_SRCPRT.Checked == true)
            {
                if (!string.IsNullOrEmpty(pm.SrcPrt))
                {
                    srcPrt = pm.SrcPrt;
                }
            }
            var mc = new ModColl(TXTBX__MODCOLL_NAME.Text, srcPrt);

            foreach (DataGridViewRow r in DGRIDV_MODS.Rows)
            {
                if ((bool)r.Cells[0].Value)
                {
                    mc.Add(new Mod((bool)r.Cells[0].Value, (int)r.Cells[1].Value, pm.MODDIRECTORY, r.Cells[2].Value.ToString()));
                }
            }
            if (mc.Count != 0)
            {
                pm.addModColl(mc);
                reinitModColl();
                LSTB_MODCOLL.Focus();
            }
        }
Ejemplo n.º 3
0
Archivo: PM.cs Proyecto: cdag/WMD
        List <ModColl> read2XML()
        {
            var fi   = new FileInfo(FILENAME);
            var nlmc = new List <ModColl>();

            nlmc.Add(new ModColl("[none]", ""));
            var reader = new XmlTextReader(FILENAME);

            stopAskingVar  = false;
            disableConfirm = false;
            if (fi.Exists)
            {
                try
                {
                    while (reader.Read())
                    {
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Var"))
                        {
                            stopAskingVar = (reader.GetAttribute("stopasking").Equals("1"));
                            customModDir  = reader.GetAttribute("customModDir");
                        }
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Confirm"))
                        {
                            disableConfirm = (reader.GetAttribute("disabled").Equals("1"));
                        }
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "SrcPrt"))
                        {
                            srcPrt = reader.GetAttribute("link");
                        }
                        bool quit = false;
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Wadpack"))
                        {
                            var nmc = new ModColl(reader.GetAttribute("name"), reader.GetAttribute("srcPrt"));

                            while (quit == false)
                            {
                                reader.Read();
                                switch (reader.NodeType)
                                {
                                case XmlNodeType.EndElement:     //Display the end of the element.
                                    if (reader.Name == "Wadpack")
                                    {
                                        quit = true;
                                        nlmc.Add(nmc);
                                    }
                                    break;

                                case XmlNodeType.Element:     //Display the text in each element.
                                    if (reader.Name == "Wad")
                                    {
                                        try
                                        {
                                            string attr = "0";
                                            if (reader.HasAttributes)
                                            {
                                                attr = reader.GetAttribute("loadorder");
                                            }
                                            reader.Read();
                                            var fiWad = new FileInfo(reader.Value);
                                            if (!fiWad.Exists)
                                            {
                                                System.Console.WriteLine("1");
                                                fiWad = new FileInfo(reader.Value.Replace(".\\WMD", MODDIRECTORY));
                                            }
                                            if (!fiWad.Exists)
                                            {
                                                if (!reader.Value.StartsWith(".", System.StringComparison.Ordinal))
                                                {
                                                    System.Console.WriteLine("2");
                                                    fiWad = new FileInfo(MODDIRECTORY + "\\" + reader.Value);
                                                }
                                            }
                                            if (!fiWad.Exists)
                                            {
                                                break;
                                            }
                                            System.Console.WriteLine(fiWad.FullName);
                                            nmc.Add(new Mod(true, attr, fiWad));
                                        }
                                        catch { }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    reader.Close();
                }
                catch (XmlException)
                {
                    reader.Close();
                    fi.Delete();
                }
            }

            return(nlmc);
        }