using System.Collections.Generic;
using UnityEngine;
public class XmlManager
{
/// <summary>XML로 해당 path 경로에 classForSave 함수를 저장합니다.
public static T XMLSerialize<T>(T classForSave, string path)
{
System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(T));
using (System.IO.TextWriter tw = new System.IO.StreamWriter(path))
{
sr.Serialize(tw, classForSave);
tw.Close();
return classForSave;
}
}
/// <summary>XML로 해당 path 경로에서 classForCopy 함수를 불러옵니다.
public static T XMLDeserialize<T>(string path)
{
System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(T));
using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open))
{
T t = (T)sr.Deserialize(fs);
fs.Close();
return t;
}
}
public static bool IsExist(string path)
{
if (System.IO.File.Exists(path))
return true;
else
return false;
}
/// <summary>pattern(정규식)과 일치하는 파일이 있는지 검사합니다.</summary>
public static bool IsMatchExist(string path, string pattern)
{
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);
string[] files = System.IO.Directory.GetFiles(path);
foreach(var file in files)
{
if (rgx.IsMatch(file))
{
return true;
}
}
return false;
}
}