Mateiral Pair에서 check된 항목 load/save/remove

Compatibility Map에 적용
This commit is contained in:
2017-08-13 04:18:50 +09:00
parent b906236fef
commit bef2551cc6
12 changed files with 833 additions and 73 deletions

182
Config.cs
View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace friction
{
public static class Config
public class Config
{
public struct RANGE
{
@@ -17,8 +17,9 @@ namespace friction
public float m_fHigh;
}
static string m_strPath = "";
private static Config m_instance = null;
string m_strPath = "";
public static readonly RANGE TEMP_ALL = new RANGE { m_fLow = -100.0f, m_fHigh = 100.0f };
public static readonly RANGE TEMP_LOW = new RANGE { m_fLow = -100.0f, m_fHigh = 0.0f };
@@ -29,12 +30,29 @@ namespace friction
public static readonly RANGE HUMID_LOW = new RANGE { m_fLow = 0.0f, m_fHigh = 60.0f };
public static readonly RANGE HUMID_HIGH = new RANGE { m_fLow = 60.0f, m_fHigh = 100.0f };
static Config()
public class CheckedMaterial
{
public List<string> m_Springs = new List<string>();
public List<string> m_Tables = new List<string>();
}
public static void Init()
public Dictionary<string, CheckedMaterial> m_CheckedMaterial = new Dictionary<string, CheckedMaterial>();
public string m_strCurMaterial = "";
private Config()
{
}
public static Config GetInstance()
{
if (m_instance == null)
m_instance = new Config();
return m_instance;
}
public void Init()
{
string strPrjName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
string strFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), strPrjName);
@@ -50,16 +68,60 @@ namespace friction
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
private static void Load()
private CheckedMaterial LoadCheckedMaterial(string section)
{
CheckedMaterial cm = new CheckedMaterial();
StringBuilder temp = new StringBuilder(10240);
int iRes = GetPrivateProfileString(section, "checked-spring", "", temp, 10240, m_strPath);
if(temp.Length > 0)
{
string[] astrToken = temp.ToString().Split(',');
cm.m_Springs = astrToken.ToList();
}
iRes = GetPrivateProfileString(section, "checked-table", "", temp, 10240, m_strPath);
if (temp.Length > 0)
{
string[] astrToken = temp.ToString().Split(',');
cm.m_Tables = astrToken.ToList();
}
return cm;
}
public bool HasPref(string strName)
{
foreach(var pair in m_CheckedMaterial)
{
if (pair.Key == strName)
return true;
}
return false;
}
public void InsertPref(string strName)
{
m_CheckedMaterial.Add(strName, new CheckedMaterial());
}
public void RemovePref(string strName)
{
m_CheckedMaterial.Remove(strName);
WritePrivateProfileString(strName, null, null, m_strPath);
}
private void Load()
{
StringBuilder temp = new StringBuilder(10240);
int iRes = GetPrivateProfileString("Option", "recent", "", temp, 10240, m_strPath);
if(temp.Length > 0)
{
string[] astrList = temp.ToString().Split(new string[] { "//" }, StringSplitOptions.None);
string[] astrList = temp.ToString().Split(',');
foreach (string strFile in astrList)
OPTION.AddRecentFile(strFile);
OPTION.GetInstance().AddRecentFile(strFile);
}
iRes = GetPrivateProfileString("Option", "bound", "", temp, 10240, m_strPath);
@@ -74,30 +136,82 @@ namespace friction
int.TryParse(astrBound[2], out iTop);
int.TryParse(astrBound[3], out iHeight);
OPTION.WindowBound = new Rectangle(iLeft, iTop, iWidth, iHeight);
OPTION.GetInstance().WindowBound = new Rectangle(iLeft, iTop, iWidth, iHeight);
}
iRes = GetPrivateProfileString("Option", "checked-column", "", temp, 10240, m_strPath);
if (temp.Length > 0)
{
string[] astrBound = temp.ToString().Split(',');
OPTION.CheckedColumns = astrBound.ToList();
OPTION.GetInstance().CheckedColumns = astrBound.ToList();
}
iRes = GetPrivateProfileString("Option", "unchecked-column", "", temp, 10240, m_strPath);
if (temp.Length > 0)
{
string[] astrBound = temp.ToString().Split(',');
OPTION.UncheckedColumns = astrBound.ToList();
OPTION.GetInstance().UncheckedColumns = astrBound.ToList();
}
iRes = GetPrivateProfileString("Option", "conf-names", "", temp, 10240, m_strPath);
if (temp.Length > 0)
{
m_CheckedMaterial.Clear();
string[] astrSections = temp.ToString().Split(',');
foreach(string section in astrSections)
{
CheckedMaterial cm = LoadCheckedMaterial(section);
m_CheckedMaterial.Add(section, cm);
}
}
iRes = GetPrivateProfileString("Option", "current-conf", "", temp, 10240, m_strPath);
if (temp.Length > 0)
{
m_strCurMaterial = temp.ToString();
}
if(m_CheckedMaterial.Count == 0)
{
m_strCurMaterial = "Default";
m_CheckedMaterial.Add(m_strCurMaterial, new CheckedMaterial());
}
}
public static void Save()
public void Save()
{
WritePrivateProfileString("Option", "recent", OPTION.GetRecentAll(), m_strPath);
WritePrivateProfileString("Option", "bound", OPTION.WindowBoundStr(), m_strPath);
WritePrivateProfileString("Option", "checked-column", OPTION.CheckedColumnsStr(), m_strPath);
WritePrivateProfileString("Option", "unchecked-column", OPTION.UncheckedColumnsStr(), m_strPath);
WritePrivateProfileString("Option", "recent", OPTION.GetInstance().GetRecentAll(), m_strPath);
WritePrivateProfileString("Option", "bound", OPTION.GetInstance().WindowBoundStr(), m_strPath);
WritePrivateProfileString("Option", "checked-column", OPTION.GetInstance().CheckedColumnsStr(), m_strPath);
WritePrivateProfileString("Option", "unchecked-column", OPTION.GetInstance().UncheckedColumnsStr(), m_strPath);
foreach(var pair in m_CheckedMaterial)
{
WritePrivateProfileString(pair.Key, "checked-spring", string.Join(",", pair.Value.m_Springs.ToArray()), m_strPath);
WritePrivateProfileString(pair.Key, "checked-table", string.Join(",", pair.Value.m_Tables.ToArray()), m_strPath);
}
WritePrivateProfileString("Option", "conf-names", string.Join(",", m_CheckedMaterial.Keys.ToArray()), m_strPath);
WritePrivateProfileString("Option", "current-conf", m_strCurMaterial, m_strPath);
}
public void SetSpringChecked(List<string> CheckedItems)
{
m_CheckedMaterial[m_strCurMaterial].m_Springs = CheckedItems;
}
public List<string> GetSpringChecked()
{
return m_CheckedMaterial[m_strCurMaterial].m_Springs;
}
public void SetTableChecked(List<string> CheckedItems)
{
m_CheckedMaterial[m_strCurMaterial].m_Tables = CheckedItems;
}
public List<string> GetTableChecked()
{
return m_CheckedMaterial[m_strCurMaterial].m_Tables;
}
@@ -113,14 +227,24 @@ namespace friction
}
public static class OPTION
public class OPTION
{
public static List<string> m_RecentList = new List<string>();
public static Rectangle WindowBound { set; get; }
public static List<string> CheckedColumns { set; get; }
public static List<string> UncheckedColumns { set; get; }
private static OPTION m_instance = null;
public static void AddRecentFile(string strPath)
public List<string> m_RecentList = new List<string>();
public Rectangle WindowBound { set; get; }
public List<string> CheckedColumns { set; get; }
public List<string> UncheckedColumns { set; get; }
public static OPTION GetInstance()
{
if (m_instance == null)
m_instance = new OPTION();
return m_instance;
}
public void AddRecentFile(string strPath)
{
if(m_RecentList.Find(s => s==strPath) != null)
m_RecentList.Remove(strPath);
@@ -128,17 +252,17 @@ namespace friction
m_RecentList.Add(strPath);
}
public static string GetRecentAll()
public string GetRecentAll()
{
return string.Join("//", m_RecentList);
}
public static string WindowBoundStr()
public string WindowBoundStr()
{
return string.Format("{0}, {1}, {2}, {3}", WindowBound.Left, WindowBound.Width, WindowBound.Top, WindowBound.Height);
}
public static string CheckedColumnsStr()
public string CheckedColumnsStr()
{
string strResult = "";
if(CheckedColumns != null)
@@ -154,7 +278,7 @@ namespace friction
return strResult;
}
public static string UncheckedColumnsStr()
public string UncheckedColumnsStr()
{
string strResult = "";
@@ -173,7 +297,7 @@ namespace friction
}
public static class ANALYSIS
public class ANALYSIS
{
public enum RISK
{
@@ -211,8 +335,6 @@ namespace friction
else
return DEPENDANCY.HIGH;
}
}
}
}