Beispiel #1
0
        public static Task <bool> PatchWorldSettings(ZipArchive archive, List <WorldSettingChange> changes, IProgress <string> log, XmlDocument patchInfo)
        {
            return(Task.Factory.StartNew(() =>
            {
                log.Report("Patche Welt Einstellungen..");

                ZipArchiveEntry entry = archive.GetEntry(ArchiveEntries.WorldSettings);
                if (entry != null)
                {
                    using (Stream stream = entry.Open())
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(stream);

                        bool hasChanges = false;
                        foreach (XmlNode node in doc.SelectNodes("root/param"))
                        {
                            string name = node.Attributes["name"].InnerText;
                            string value = node.Attributes["value"].InnerText;

                            WorldSettingChange change = changes.FirstOrDefault(m => m.Name == name);
                            if (change != null && change.Value != value)
                            {
                                hasChanges = true;

                                log.Report($"Schreibe {change.Name}..");

                                node.Attributes["value"].InnerText = change.Value;
                                AppendPatchChange(patchInfo, "WorldSettings", name, "value", change.Value);
                            }
                        }

                        if (hasChanges)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            doc.Save(stream);
                            stream.SetLength(stream.Position);
                            stream.Flush();
                        }
                        else
                        {
                            log.Report("Keine Änderungen gefunden");
                        }
                    }
                }
                else
                {
                    log.Report($"Element {ArchiveEntries.WorldSettings} nicht gefunden");
                }

                return true;
            }));
        }
        private List <WorldSettingChange> ReadWorldSettings(IProgress <string> progress, XmlDocument doc)
        {
            List <WorldSettingChange> result = new List <WorldSettingChange>();

            progress.Report("Lese Welt Einstellungen..");

            foreach (XmlNode node in doc.SelectNodes("patch/WorldSettings/change"))
            {
                WorldSettingChange change = new WorldSettingChange();
                change.Name = node.Attributes["name"].InnerText;
                //change.Type = node.Attributes["type"].InnerText;
                change.Value = node.Attributes["to"].InnerText;
                result.Add(change);
            }

            return(result);
        }