133 lines
3.4 KiB
C#
133 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PluginCommon
|
|
{
|
|
|
|
public class Settings
|
|
{
|
|
public bool SelectCustomIP = false;
|
|
public List<string> IPs = new List<string>();
|
|
|
|
public bool SelectCustomPort = false;
|
|
public List<string> Ports = new List<string>();
|
|
}
|
|
|
|
public class SettingsManager
|
|
{
|
|
private static SettingsManager instance;
|
|
private Settings m_setting = new Settings();
|
|
|
|
|
|
public static SettingsManager getInstance()
|
|
{
|
|
if (instance == null)
|
|
instance = new SettingsManager();
|
|
return instance;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
m_setting.IPs.Clear();
|
|
m_setting.Ports.Clear();
|
|
m_setting.SelectCustomIP = false;
|
|
m_setting.SelectCustomPort = false;
|
|
}
|
|
|
|
public void AddIP(string ip)
|
|
{
|
|
m_setting.IPs.Remove(ip);
|
|
m_setting.IPs.Insert(0, ip);
|
|
}
|
|
|
|
public void AddPort(string port)
|
|
{
|
|
m_setting.Ports.Remove(port);
|
|
m_setting.Ports.Insert(0, port);
|
|
}
|
|
|
|
public List<string> GetIPs()
|
|
{
|
|
return m_setting.IPs;
|
|
}
|
|
|
|
public List<string> GetPorts()
|
|
{
|
|
return m_setting.Ports;
|
|
}
|
|
|
|
public bool SelectedCustomIP
|
|
{
|
|
get { return m_setting.SelectCustomIP; }
|
|
set { m_setting.SelectCustomIP = value; }
|
|
}
|
|
|
|
public bool SelectedCustomPort
|
|
{
|
|
get { return m_setting.SelectCustomPort; }
|
|
set { m_setting.SelectCustomPort = value; }
|
|
}
|
|
|
|
private SettingsManager()
|
|
{
|
|
Load();
|
|
}
|
|
|
|
public static string PathName
|
|
{
|
|
get
|
|
{
|
|
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
return path + Path.DirectorySeparatorChar + Application.ProductName + "_settings.xml";
|
|
}
|
|
}
|
|
|
|
public bool Load()
|
|
{
|
|
TextReader reader = null;
|
|
try
|
|
{
|
|
XmlSerializer serializerReader = new XmlSerializer(typeof(Settings));
|
|
FileStream fs = new FileStream(PathName, FileMode.OpenOrCreate);
|
|
reader = new StreamReader(fs);
|
|
|
|
m_setting = (Settings)serializerReader.Deserialize(reader);
|
|
|
|
reader.Close();
|
|
return true;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
string str = ex.Message;
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
if (reader != null)
|
|
reader.Close();
|
|
}
|
|
}
|
|
|
|
public bool Save()
|
|
{
|
|
try
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
|
|
TextWriter writer = new StreamWriter(PathName);
|
|
serializer.Serialize(writer, m_setting);
|
|
writer.Close();
|
|
return true;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
string str = ex.Message;
|
|
MessageUtils.ShowMessage(str);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|