public static void WriteConfigTo(string filePath, IniConfig config) { StringBuilder configSB = new StringBuilder(); configSB.AppendLine(INI_HEAD_CONTENT); dynamic dynamicConfig = config.AsDynamic(); Dictionary <string, IniGroup> groupDic = dynamicConfig.groupDic; if (groupDic != null && groupDic.Count > 0) { foreach (var kvp in groupDic) { IniGroup group = kvp.Value; configSB.AppendLine($"#{group.Name}|{group.Comment}"); dynamic dynamicGroup = group.AsDynamic(); Dictionary <string, IniData> dataDic = dynamicGroup.dataDic; foreach (var kvp2 in dataDic) { IniData data = kvp2.Value; configSB.AppendLine($"-{data.Key}|{data.Value}|{data.Comment}|{string.Join(",", data.OptionValues)}"); } } configSB.AppendLine(); } File.WriteAllText(filePath, configSB.ToString()); }
public bool SaveFile() { //bool returned indicates the success of the save process try { FileStream strm = new FileStream(fileName, FileMode.Create, FileAccess.Write); StreamWriter W = new StreamWriter(strm); if (iniGroupNames.Count > 0) { for (int i = 0; i <= iniGroupNames.Count - 1; i++) { IniGroup grp = iniGroups[i]; if (grp.getCount() > 0) { //only save this group if it has content W.WriteLine("[" + iniGroupNames[i] + "]"); for (int k = 0; k <= grp.getCount() - 1; k++) { W.WriteLine((grp.getKey(k) + "=") + grp.getValue(k)); } W.WriteLine(" "); } } } W.Close(); strm.Close(); return(true); } catch { return(false); } }
private void DrawData(IniGroup group, IniData data) { string value = data.Value; EditorGUILayout.BeginHorizontal(); { if (data.OptionValues != null && data.OptionValues.Length > 0) { value = EGUILayout.StringPopup(new GUIContent(data.Key, data.Comment), data.Value, data.OptionValues); } else { value = EditorGUILayout.TextField(new GUIContent(data.Key, data.Comment), data.Value); } if (GUILayout.Button(Contents.DeleteContent, GUILayout.Width(20))) { deleteData = new DeleteData() { groupName = group.Name, dataKey = data.Key }; } } EditorGUILayout.EndHorizontal(); if (data.Value != value) { data.Value = value; } }
private void DrawGroup(IniGroup group) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { EditorGUILayout.LabelField(new GUIContent(group.Name, group.Comment)); GUILayout.FlexibleSpace(); if (GUILayout.Button(Contents.DeleteGroupContent, EditorStyles.toolbarButton, GUILayout.Width(80))) { deleteData = new DeleteData() { groupName = group.Name }; } if (GUILayout.Button(Contents.AddDataContent, EditorStyles.toolbarButton, GUILayout.Width(80))) { PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero), new CreateIniDataContent(group, (groupName, dataKey) => { Repaint(); })); } } EditorGUILayout.EndHorizontal(); foreach (var dKVP in group.AsDynamic().dataDic) { if (string.IsNullOrEmpty(searchText) || dKVP.Key.ToLower().IndexOf(searchText) >= 0) { DrawData(group, dKVP.Value); } } } EditorGUILayout.EndVertical(); }
public CreateIniDataContent(IniGroup group, Action <string, string> callback) : base() { this.group = group; onCreatedCallback = callback; }