private void save(bool withFormat = false) { sort(); StringBuilder builder = new StringBuilder(); builder.Append("{"); if (property.Count > 0) { foreach (var pair in property) { builder.Append($"\"{pair.Key}\":\"{pair.Value}\""); } } if (group.Count > 0) { if (property.Count > 0) { builder.Append(","); } builder.Append("\"group\":{"); for (int i = 0; i < group.Count; i++) { FTagGroup group = this.group.ElementAt(i).Value; builder.Append(group.ToString()); if (i != dic.Count - 1) { builder.Append(','); } } builder.Append("}"); } if (dic.Count > 0) { if (property.Count > 0 || group.Count > 0) { builder.Append(","); } builder.Append("\"tags\":{"); for (int i = 0; i < dic.Count; i++) { FTagObject obj = dic.ElementAt(i).Value; builder.Append(obj.ToString()); if (i != dic.Count - 1) { builder.Append(','); } } builder.Append("}"); } builder.Append("}"); File.WriteAllText(path, builder.ToString()); }
/// <summary> /// Extraction ftag. /// </summary> /// <param name="dic"></param> /// <param name="group"></param> /// <param name="to_path"></param> /// <returns></returns> static public FTagStream Extraction( Dictionary <string, FTagObject> dic, Dictionary <string, FTagGroup> group, string folder_path, string to_subpath) { Dictionary <string, FTagObject> dicc = new Dictionary <string, FTagObject>(); Dictionary <string, FTagGroup> groupc = new Dictionary <string, FTagGroup>(); if (!to_subpath.EndsWith("\\") || !to_subpath.EndsWith("/")) { to_subpath += "/"; } to_subpath = to_subpath.Replace("\\", "/"); foreach (var pair in dic) { if (pair.Key.StartsWith(to_subpath)) { FTagObject tmpobj = new FTagObject( pair.Key.Substring(to_subpath.Length), pair.Value.Tags, pair.Value.Descript); dicc.Add(pair.Key.Substring(to_subpath.Length), tmpobj); foreach (var tag1 in pair.Value.Tags) { foreach (var g in group) { foreach (var tag2 in g.Value.Tags) { if (tag1 == tag2) { if (!groupc.ContainsKey(g.Key)) { groupc.Add(g.Key, g.Value); break; } } } } } } } return(new FTagStream(folder_path + to_subpath, dicc, groupc)); }
/// <summary> /// Move tags and file. /// </summary> /// <param name="source"></param> /// <param name="target"></param> static public void Move( ref Dictionary <string, FTagObject> dic, List <FTagObject> source, string path, string subpath) { if (!subpath.EndsWith("\\")) { subpath += "\\"; } subpath = subpath.Replace('/', '\\'); for (int i = 0; i < source.Count; i++) { string oldPath = path + source[i].SubPath; string oldsubpath = source[i].SubPath; string newPath = path + subpath + Path.GetFileName(source[i].SubPath); string newsubpath = (subpath + Path.GetFileName(source[i].SubPath)).Replace('\\', '/'); if (oldPath == newPath) { continue; } new FileInfo(newPath).Directory.Create(); try { File.Move(oldPath, newPath); FTagObject tmp = dic[oldsubpath]; tmp.SubPath = newsubpath; dic.Remove(oldsubpath); dic.Add(newsubpath, tmp); } catch { // If source and also target have same object, // then move function throw by already exist. // This path can not be filtered by compare path. [old == new] // So, skip this step. } } }