nodes, string filePath, CancellationToken ct)
{
var html = BuildHtml(nodes);
- await System.IO.File.WriteAllTextAsync(filePath, html, System.Text.Encoding.UTF8, ct);
+ await File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct);
}
+
+ // ── Private rendering ────────────────────────────────────────────────────
+
+ private void RenderNode(StringBuilder sb, StorageNode node)
+ {
+ bool hasChildren = node.Children.Count > 0;
+ int myIdx = hasChildren ? ++_togIdx : 0;
+
+ string nameCell = hasChildren
+ ? $"{HtmlEncode(node.Name)}"
+ : $"{HtmlEncode(node.Name)}";
+
+ string lastMod = node.LastModified.HasValue
+ ? node.LastModified.Value.ToString("yyyy-MM-dd")
+ : string.Empty;
+
+ sb.AppendLine($"""
+
+ | {nameCell} |
+ {HtmlEncode(node.SiteTitle)} |
+ {node.TotalFileCount:N0} |
+ {FormatSize(node.TotalSizeBytes)} |
+ {FormatSize(node.VersionSizeBytes)} |
+ {lastMod} |
+
+ """);
+
+ if (hasChildren)
+ {
+ sb.AppendLine($"");
+ sb.AppendLine("");
+ foreach (var child in node.Children)
+ {
+ RenderChildNode(sb, child);
+ }
+ sb.AppendLine(" ");
+ sb.AppendLine(" |
");
+ }
+ }
+
+ private void RenderChildNode(StringBuilder sb, StorageNode node)
+ {
+ bool hasChildren = node.Children.Count > 0;
+ int myIdx = hasChildren ? ++_togIdx : 0;
+
+ string indent = $"margin-left:{(node.IndentLevel + 1) * 16}px";
+ string nameCell = hasChildren
+ ? $"{HtmlEncode(node.Name)}"
+ : $"{HtmlEncode(node.Name)}";
+
+ string lastMod = node.LastModified.HasValue
+ ? node.LastModified.Value.ToString("yyyy-MM-dd")
+ : string.Empty;
+
+ sb.AppendLine($"""
+
+ | {nameCell} |
+ {HtmlEncode(node.SiteTitle)} |
+ {node.TotalFileCount:N0} |
+ {FormatSize(node.TotalSizeBytes)} |
+ {FormatSize(node.VersionSizeBytes)} |
+ {lastMod} |
+
+ """);
+
+ if (hasChildren)
+ {
+ sb.AppendLine($"");
+ sb.AppendLine("");
+ foreach (var child in node.Children)
+ {
+ RenderChildNode(sb, child);
+ }
+ sb.AppendLine(" ");
+ sb.AppendLine(" |
");
+ }
+ }
+
+ private static string FormatSize(long bytes)
+ {
+ if (bytes >= 1_073_741_824L) return $"{bytes / 1_073_741_824.0:F2} GB";
+ if (bytes >= 1_048_576L) return $"{bytes / 1_048_576.0:F2} MB";
+ if (bytes >= 1024L) return $"{bytes / 1024.0:F2} KB";
+ return $"{bytes} B";
+ }
+
+ private static string HtmlEncode(string value)
+ => System.Net.WebUtility.HtmlEncode(value ?? string.Empty);
}