using GummingCommon; using System.IO; using System.Xml.Serialization; namespace GummingCommon { public class PaintInfoService { public BasePaintInfo PaintInfo { get; private set; } static PaintInfoService _instance; static object _lockFlg = new object(); public static PaintInfoService Instance() { if (_instance == null) { lock (_lockFlg) { if (_instance == null) { _instance = new PaintInfoService(); } } } return _instance; } private PaintInfoService() { PaintInfo = new BasePaintInfo(); } public void Save() { if (!Directory.Exists(SystemConst.SystemFolder)) { Directory.CreateDirectory(SystemConst.SystemFolder); } XmlSerializer serializer = new XmlSerializer(typeof(BasePaintInfo)); using (FileStream fs = new FileStream(SystemConst.PaintFile, FileMode.Create)) { serializer.Serialize(fs, PaintInfo); } } public void Load() { if (File.Exists(SystemConst.PaintFile)) { XmlSerializer serializer = new XmlSerializer(typeof(BasePaintInfo)); using (FileStream fs = new FileStream(SystemConst.PaintFile, FileMode.Open)) { object obj = serializer.Deserialize(fs); if (obj != null) { PaintInfo = (BasePaintInfo)obj; } } } } } }