예제 #1
0
        public static PatchDirectory FromXml(PatchList list, PatchDirectory parent, XmlNode node)
        {
            var name = node.Attributes["Name"];
            var removeUnpatchedFiles = node.Attributes["RemoveUnpatchedFiles"];

            if (name != null)
            {
                var directory = new PatchDirectory(parent, name.Value);

                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name == "Directory")
                    {
                        directory.Subdirectories.AddLast(PatchDirectory.FromXml(list, directory, child));
                    }
                    else if (child.Name == "File")
                    {
                        directory.Files.AddLast(PatchFile.FromXml(directory, child));
                    }
                }

                if (removeUnpatchedFiles != null &&
                    removeUnpatchedFiles.Value == "false")
                {
                    directory.RemoveUnpatchedFiles = true;
                    list.IgnoredDirectories.Add(directory.RelativePhysicalPath.ToLower());
                }

                return(directory);
            }

            return(null);
        }
예제 #2
0
 public PatchFile(PatchDirectory directory, string name, uint crc, string patchurl)
 {
     Directory = directory;
     Name      = name;
     Crc       = crc;
     PatchUrl  = patchurl;
 }
예제 #3
0
 public PatchDirectory(PatchDirectory parent, string name)
 {
     Parent               = parent;
     Name                 = name;
     Subdirectories       = new LinkedList <PatchDirectory>();
     Files                = new LinkedList <PatchFile>();
     RemoveUnpatchedFiles = true;
 }
예제 #4
0
        private void HashTreeWalkDirectory(PatchDirectory directory, Dictionary <string, PatchFile> output)
        {
            foreach (PatchDirectory dir in directory.Subdirectories)
            {
                HashTreeWalkDirectory(dir, output);
            }

            foreach (PatchFile file in directory.Files)
            {
                output.Add(file.RelativePhysicalPath.ToLower(), file);
            }
        }
예제 #5
0
        public PatchList(uint patchercrc)
        {
            PatcherCrc = patchercrc;

            /*ConfigMode = PatchListMode.Partial;
             * Config = new PatchDirectory(null, "config");
             * ConfigHashTree = new Dictionary<string, PatchFile>();*/

            JarModsMode     = PatchListMode.Identical;
            JarMods         = new PatchDirectory(null, "jarmods");
            JarModsHashTree = new Dictionary <string, PatchFile>();

            ModsMode     = PatchListMode.Identical;
            Mods         = new PatchDirectory(null, "mods");
            ModsHashTree = new Dictionary <string, PatchFile>();

            FlanMode     = PatchListMode.Identical;
            FlanMods     = new PatchDirectory(null, "Flan");
            FlanHashTree = new Dictionary <string, PatchFile>();

            FinalActions       = new LinkedList <FileAction>();
            IgnoredDirectories = new HashSet <string>();
        }
예제 #6
0
        public static PatchFile FromXml(PatchDirectory directory, XmlNode node)
        {
            var name     = node.Attributes["Name"];
            var crc      = node.Attributes["Crc"];
            var patchurl = node.Attributes["PatchUrl"];

            uint _crc;

            if (name != null &&
                crc != null &&
                patchurl != null &&
                uint.TryParse(crc.Value, out _crc))
            {
                string url = patchurl.Value
                             .Replace("{PatchUrl}", Program.PatchUrl)
                             .Replace("{Name}", name.Value)
                             .Replace("{Crc}", crc.Value);

                return(new PatchFile(directory, name.Value, _crc, url));
            }

            return(null);
        }
예제 #7
0
        public static PatchList FromXml(XmlNode root)
        {
            var list = new PatchList(0);

            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name == "Patcher")
                {
                    uint         _crc;
                    XmlAttribute crc = node.Attributes["Crc"];
                    if (crc != null &&
                        uint.TryParse(crc.Value, out _crc))
                    {
                        list.PatcherCrc = _crc;

                        if (_crc != Program.ExecutableCrc)
                        {
                            if (MessageBox.Show(
                                    "A newer version of the MCPatcher is available, do you want to go to the website to download?\n" +
                                    "If you click No, MCPatcher will continue but may or may not be stable.",
                                    "MCPatcher", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                            {
                                Process.Start(Program.PatchUrl);
                                Environment.Exit(0);
                            }
                        }
                    }
                }

                /*if (node.Name == "Config")
                 * {
                 *  XmlAttribute _mode = node.Attributes["Mode"];
                 *  PatchListMode mode = PatchListMode.Partial;
                 *  if (_mode != null &&
                 *      Enum.TryParse(_mode.Value, out mode))
                 *  {
                 *      list.ConfigMode = mode;
                 *      foreach (XmlNode child in node.ChildNodes)
                 *      {
                 *          if (child.Name == "File")
                 *          {
                 *              list.Config.Files.AddLast(PatchFile.FromXml(list.Config, child));
                 *          }
                 *          else if (child.Name == "Directory")
                 *          {
                 *              list.Config.Subdirectories.AddLast(PatchDirectory.FromXml(list, list.Config, child));
                 *          }
                 *      }
                 *  }
                 * }
                 * else */
                if (node.Name == "JarMods")
                {
                    XmlAttribute  _mode = node.Attributes["Mode"];
                    PatchListMode mode  = PatchListMode.Partial;
                    if (_mode != null &&
                        Enum.TryParse(_mode.Value, out mode))
                    {
                        list.JarModsMode = mode;
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            if (child.Name == "File")
                            {
                                list.JarMods.Files.AddLast(PatchFile.FromXml(list.JarMods, child));
                            }
                            else if (child.Name == "Directory")
                            {
                                list.JarMods.Subdirectories.AddLast(PatchDirectory.FromXml(list, list.JarMods, child));
                            }
                        }
                    }
                }
                else if (node.Name == "Mods")
                {
                    XmlAttribute  _mode = node.Attributes["Mode"];
                    PatchListMode mode  = PatchListMode.Partial;
                    if (_mode != null &&
                        Enum.TryParse(_mode.Value, out mode))
                    {
                        list.ModsMode = mode;
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            if (child.Name == "File")
                            {
                                list.Mods.Files.AddLast(PatchFile.FromXml(list.Mods, child));
                            }
                            else if (child.Name == "Directory")
                            {
                                list.Mods.Subdirectories.AddLast(PatchDirectory.FromXml(list, list.Mods, child));
                            }
                        }
                    }
                }
                else if (node.Name == "Flan")
                {
                    var _mode = node.Attributes["Mode"];
                    var mode  = PatchListMode.Partial;
                    if (_mode != null &&
                        Enum.TryParse(_mode.Value, out mode))
                    {
                        list.FlanMode = mode;
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            if (child.Name == "File")
                            {
                                list.FlanMods.Files.AddLast(PatchFile.FromXml(list.FlanMods, child));
                            }
                            else if (child.Name == "Directory")
                            {
                                list.FlanMods.Subdirectories.AddLast(PatchDirectory.FromXml(list, list.FlanMods, child));
                            }
                        }
                    }
                }
            }

            list.CreateVirtualHashTree();
            return(list);
        }