예제 #1
0
파일: PM.cs 프로젝트: 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);
        }
예제 #2
0
파일: PM.cs 프로젝트: cdag/WMD
 public void removeModColl(ModColl mc)
 {
     if (mc.config != null)
     {
         if (mc.config.Exists)
         {
             mc.config.Delete();
         }
     }
     modCollList.Remove(mc);
     write2XML();
 }
예제 #3
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();
            }
        }
예제 #4
0
        void DGRIDV_MODS_DragDrop(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);

            //var files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                if (File.Exists(file))
                {
                    var fi = new FileInfo(file);
                    if (fi.Extension.ToLower().Equals(".dpz"))
                    {
                        var dpzEx = new DirectoryInfo(@".\DPZ-EXTRACT\");
                        if (dpzEx.Exists)
                        {
                            dpzEx.Delete(true);
                        }
                        dpzEx.Create();
                        ZipFile.ExtractToDirectory(fi.FullName, dpzEx.FullName);

                        string[] foldArr = { dpzEx.FullName + @"\WMD\", dpzEx.FullName + @"\WMDSAVE\", dpzEx.FullName + @"\WMDCONF\" };
                        string[] tgtArr  = { pm.MODDIRECTORY, PM.SAVEDIRECTORY, PM.CONFIGDIRECTORY };
                        for (int i = 0; i < foldArr.Length; i++)
                        {
                            var di = new DirectoryInfo(foldArr[i]);

                            foreach (string dirPath in Directory.GetDirectories(di.FullName, "*", SearchOption.AllDirectories))
                            {
                                Directory.CreateDirectory(dirPath.Replace(di.FullName, tgtArr[i] + "/"));
                            }
                            foreach (string newPath in Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories))
                            {
                                File.Copy(newPath, newPath.Replace(di.FullName, tgtArr[i] + "/"), true);
                            }
                        }
                        ModColl mc = pm.readXmlPackage(new FileInfo(dpzEx.FullName + @"WMF.xml"));
                        pm.addModColl(mc);
                        reinitModColl();
                        LSTB_MODCOLL.Focus();
                        dpzEx.Delete(true);
                    }
                    else
                    {
                        int    stri     = fi.DirectoryName.Length;
                        string namefile = fi.FullName.Substring(stri + 1, fi.FullName.Length - stri - 1);
                        File.Copy(file, pm.MODDIRECTORY + "/" + namefile, true);
                    }
                }
                else if (Directory.Exists(file))
                {
                    var di = new DirectoryInfo(file);

                    //int stri = di.DirectoryName.Length;
                    //string namefile = fi.FullName.Substring(stri + 1, fi.FullName.Length - stri - 1);
                    Directory.CreateDirectory(pm.MODDIRECTORY + "/" + di.Name);
                    foreach (string dirPath in Directory.GetDirectories(di.FullName, "*", SearchOption.AllDirectories))
                    {
                        Directory.CreateDirectory(dirPath.Replace(di.FullName, pm.MODDIRECTORY + "/" + di.Name));
                    }
                    foreach (string newPath in Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories))
                    {
                        File.Copy(newPath, newPath.Replace(di.FullName, pm.MODDIRECTORY + "/" + di.Name), true);
                    }
                    //File.Copy(file, PM.MODDIRECTORY + "/" + namefile, true);
                }
            }
            DGRIDV_MODS.DataSource = new ModList();
        }
예제 #5
0
파일: PM.cs 프로젝트: 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);
        }
예제 #6
0
파일: PM.cs 프로젝트: cdag/WMD
 public void addModColl(ModColl mc)
 {
     modCollList.Add(mc);
     write2XML();
 }