private static int GetEntriesRecursive(List <FlatFSEntry> result, string fn, DirectoryInfo root) { int count = 0; foreach (var x in root.GetFileSystemInfos()) { if ((x.Attributes & FileAttributes.Directory) != 0) { if (x.Name == "." || x.Name == "..") { continue; } FlatFSEntry fse = new FlatFSEntry() { Attributes = (int)x.Attributes, FileTime = x.LastWriteTimeUtc.Ticks, FullName = fn + x.Name + "/", Length = -1, }; int loc = result.Count; result.Add(fse); int cc = 0; if (x.Name != ".versionr") { cc = GetEntriesRecursive(result, fse.FullName, new DirectoryInfo(fn + x.Name)); } fse.ChildCount = cc; result[loc] = fse; count += 1 + cc; } else { FlatFSEntry fse = new FlatFSEntry() { Attributes = (int)x.Attributes, FileTime = x.LastWriteTimeUtc.Ticks, FullName = fn + x.Name, Length = new FileInfo(fn + x.Name).Length, }; result.Add(fse); count++; } } return(count); }
public static List <FlatFSEntry> GetFlatEntries(string root) { List <FlatFSEntry> entries = new List <FlatFSEntry>(); if (root.EndsWith("/")) { root = root.Substring(0, root.Length - 1); } scandirs(root, (string name, long size, long timestamp, int attribs) => { if (size == -1) { entries.Add(new FlatFSEntry() { FullName = name + '/', ChildCount = 0, Attributes = 0, FileTime = UnixTimeEpoch.Ticks + (timestamp * TimeSpan.TicksPerSecond), Length = -1, }); } else if (size == -2) { FlatFSEntry fs = entries[entries.Count - attribs - 1]; fs.ChildCount = attribs; entries[entries.Count - attribs - 1] = fs; } else { entries.Add(new FlatFSEntry() { FullName = name, ChildCount = 0, Attributes = 0, FileTime = UnixTimeEpoch.Ticks + (timestamp * TimeSpan.TicksPerSecond), Length = size, }); } }); return(entries); }