protected override string GetFolderNameRow(FolderInfo dir, int level) { int heading = (level + 1).Between(1, 6); string folderInfoText = string.Empty; if (!dir.IsEmpty) { folderInfoText = dir.Size.ToSizeString(config.BinaryUnits) + " ("; if (dir.TotalFileCount > 0) { folderInfoText += dir.TotalFileCount + " file" + (dir.TotalFileCount > 1 ? "s" : ""); } if (dir.TotalFolderCount > 0) { if (dir.TotalFileCount > 0) { folderInfoText += ", "; } folderInfoText += dir.TotalFolderCount + " folder" + (dir.TotalFolderCount > 1 ? "s" : ""); } folderInfoText += ")"; folderInfoText = " " + HtmlHelper.Tag("span", folderInfoText, "", "class=\"folderinfo\""); } return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(dir.FolderName) + folderInfoText + HtmlHelper.EndTag("h" + heading); }
protected override void IndexFolder(FolderInfo dir, int level) { sbContent.AppendLine(GetFolderNameRow(dir, level)); foreach (FolderInfo subdir in dir.Folders) { if (config.AddEmptyLineAfterFolders) { sbContent.AppendLine(); } IndexFolder(subdir, level + 1); } if (dir.Files.Count > 0) { if (config.AddEmptyLineAfterFolders) { sbContent.AppendLine(); } foreach (FileInfo fi in dir.Files) { sbContent.AppendLine(GetFileNameRow(fi, level + 1)); } } }
protected override void IndexFolder(FolderInfo dir, int level = 0) { xmlWriter.WriteStartElement("Folder"); if (config.UseAttribute) { xmlWriter.WriteAttributeString("Name", dir.FolderName); if (!dir.IsEmpty) xmlWriter.WriteAttributeString("Size", dir.Size.ToSizeString(config.BinaryUnits)); } else { xmlWriter.WriteElementString("Name", dir.FolderName); if (!dir.IsEmpty) xmlWriter.WriteElementString("Size", dir.Size.ToSizeString(config.BinaryUnits)); } if (dir.Files.Count > 0) { xmlWriter.WriteStartElement("Files"); foreach (FileInfo fi in dir.Files) { xmlWriter.WriteStartElement("File"); if (config.UseAttribute) { xmlWriter.WriteAttributeString("Name", fi.Name); xmlWriter.WriteAttributeString("Size", fi.Length.ToSizeString(config.BinaryUnits)); } else { xmlWriter.WriteElementString("Name", fi.Name); xmlWriter.WriteElementString("Size", fi.Length.ToSizeString(config.BinaryUnits)); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } if (dir.Folders.Count > 0) { xmlWriter.WriteStartElement("Folders"); foreach (FolderInfo subdir in dir.Folders) { IndexFolder(subdir); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); }
protected override void IndexFolder(FolderInfo dir, int level) { sbContent.AppendLine(GetFolderNameRow(dir, level)); string divClass = level > 0 ? "FolderBorder" : "MainFolderBorder"; sbContent.AppendLine(HtmlHelper.StartTag("div", "", "class=\"" + divClass + "\"")); if (dir.Files.Count > 0) { sbContent.AppendLine(HtmlHelper.StartTag("ul")); foreach (FileInfo fi in dir.Files) { sbContent.AppendLine(GetFileNameRow(fi, level)); } sbContent.AppendLine(HtmlHelper.EndTag("ul")); } foreach (FolderInfo subdir in dir.Folders) { IndexFolder(subdir, level + 1); } sbContent.AppendLine(HtmlHelper.EndTag("div")); }
protected FolderInfo GetFolderInfo(string folderPath, int level = 0) { FolderInfo folderInfo = new FolderInfo(folderPath); if (config.MaxDepthLevel == 0 || level < config.MaxDepthLevel) { try { DirectoryInfo currentDirectoryInfo = new DirectoryInfo(folderPath); foreach (DirectoryInfo directoryInfo in currentDirectoryInfo.GetDirectories()) { if (config.SkipHiddenFolders && directoryInfo.Attributes.HasFlag(FileAttributes.Hidden)) { continue; } FolderInfo subFolderInfo = GetFolderInfo(directoryInfo.FullName, level + 1); folderInfo.Folders.Add(subFolderInfo); subFolderInfo.Parent = folderInfo; } foreach (FileInfo fileInfo in currentDirectoryInfo.GetFiles()) { if (config.SkipHiddenFiles && fileInfo.Attributes.HasFlag(FileAttributes.Hidden)) { continue; } folderInfo.Files.Add(fileInfo); } folderInfo.Files.Sort((x, y) => x.Name.CompareTo(y.Name)); } catch (UnauthorizedAccessException) { } } return folderInfo; }
protected abstract void IndexFolder(FolderInfo dir, int level = 0);
protected virtual string GetFolderNameRow(FolderInfo dir, int level = 0) { string text = string.Format("{0}{1}", config.IndentationText.Repeat(level), dir.FolderName); if (dir.Size > 0) { text += string.Format(" [{0}]", dir.Size.ToSizeString(config.BinaryUnits)); } return text; }