示例#1
0
        private PatchProfile ReadPatchProfileFromXml(string fileName)
        {
            var patch = new PatchProfile();
            var xml   = XDocument.Load(fileName);

            patch.FileName = fileName;
            var mainNode = xml.Elements().FirstOrDefault(n => n.Name == "m64tweak");

            foreach (XAttribute attr in mainNode.Attributes())
            {
                var switchExpr = attr.Name;
                switch (switchExpr)
                {
                case var @case when @case == "name":
                    patch.Name = attr.Value;
                    break;

                case var case1 when case1 == "description":
                    patch.Description = attr.Value;
                    break;

                case var case2 when case2 == "version":
                    patch.Version = new Version(attr.Value);
                    break;
                }
            }

            foreach (XElement element in mainNode.Elements())
            {
                var switchExpr1 = element.Name;
                switch (switchExpr1)
                {
                case var case3 when case3 == "name":
                    patch.Name = element.Value;
                    break;

                case var case4 when case4 == "description":
                    patch.Description = element.Value;
                    break;

                case var case5 when case5 == "patch":
                    patch.Scripts.Add(XElementToScript(element));
                    break;
                }
            }

            if (string.IsNullOrEmpty(patch.Name))
            {
                patch.Name = Path.GetFileNameWithoutExtension(fileName);
            }

            return(patch);
        }
示例#2
0
        public void Save(PatchProfile patch, string dir)
        {
            if (string.IsNullOrEmpty(patch.FileName))
            {
                patch.FileName = Path.Combine(dir, patch.Name + ".json");
            }
            else if (Path.GetExtension(patch.FileName) == ".xml")
            {
                var newFileName = Path.ChangeExtension(patch.FileName, ".json");
                File.Delete(patch.FileName);
                patch.FileName = newFileName;
            }

            File.WriteAllText(patch.FileName, JObject.FromObject(patch).ToString());
        }