2022-09-14 05:25:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml.Serialization;
|
2022-10-02 05:42:07 +00:00
|
|
|
|
using UnityEngine;
|
2022-09-14 05:25:58 +00:00
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
2022-09-15 05:17:44 +00:00
|
|
|
|
public static class XmlUtility
|
2022-09-14 05:25:58 +00:00
|
|
|
|
{
|
2022-09-15 05:17:44 +00:00
|
|
|
|
public static T ReadXML<T>(string path)
|
2022-09-14 05:25:58 +00:00
|
|
|
|
{
|
2022-10-02 05:42:07 +00:00
|
|
|
|
Debug.Log("Reading data from " + path);
|
|
|
|
|
|
2022-09-14 05:25:58 +00:00
|
|
|
|
using (StreamReader stringReader = new StreamReader(path))
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
2022-10-02 05:42:07 +00:00
|
|
|
|
var data = (T)serializer.Deserialize(stringReader);
|
2022-09-14 05:25:58 +00:00
|
|
|
|
|
2022-10-02 05:42:07 +00:00
|
|
|
|
Debug.Log("Read successful");
|
|
|
|
|
return data;
|
2022-09-14 05:25:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 21:15:25 +00:00
|
|
|
|
public static void WriteXML<T>(T obj, string path)
|
2022-09-14 05:25:58 +00:00
|
|
|
|
{
|
2022-09-21 21:15:25 +00:00
|
|
|
|
if (obj == null || path == null || path == "")
|
2022-09-14 05:25:58 +00:00
|
|
|
|
{ return; }
|
|
|
|
|
|
2022-10-02 05:42:07 +00:00
|
|
|
|
Debug.Log("Saving data to " + path);
|
|
|
|
|
|
2022-09-21 21:15:25 +00:00
|
|
|
|
XmlSerializer writer = new XmlSerializer(typeof(T));
|
2022-09-14 05:25:58 +00:00
|
|
|
|
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
|
|
|
|
|
nameSpaces.Add("", "");
|
|
|
|
|
|
|
|
|
|
FileStream file = File.Create(path);
|
2022-09-21 21:15:25 +00:00
|
|
|
|
writer.Serialize(file, obj, nameSpaces);
|
2022-09-14 05:25:58 +00:00
|
|
|
|
file.Close();
|
2022-10-02 05:42:07 +00:00
|
|
|
|
|
|
|
|
|
Debug.Log("Saving successful");
|
2022-09-14 05:25:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|