From 989c6a0ecd32bc14eeda3e9d41da78a7916456b9 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:26:08 +0530 Subject: [PATCH 01/10] crate logic for hdf5 plugin --- .../QuickLook.Plugin.Hdf5Viewer/Plugin.cs | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs new file mode 100644 index 000000000..6aefe419f --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs @@ -0,0 +1,106 @@ +using QuickLook.Common.Plugin; +using System; +using System.IO; +using System.Linq; +using System.Windows; + +namespace QuickLook.Plugin.Hdf5Viewer; + +public sealed class Plugin : IViewer +{ + private static readonly byte[] Hdf5Signature = { 0x89, 0x48, 0x44, 0x46, 0x0D, 0x0A, 0x1A, 0x0A }; + private static readonly string[] SupportedExtensions = { ".h5", ".hdf5", ".hdf", ".he5" }; + private Hdf5TextPanel _panel; + + public int Priority => 0; + + public void Init() + { + } + + public bool CanHandle(string path) + { + if (Directory.Exists(path)) + return false; + + var extension = Path.GetExtension(path); + if (!SupportedExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) + return false; + + return HasHdf5Signature(path); + } + + public void Prepare(string path, ContextObject context) + { + context.PreferredSize = new Size { Width = 1100, Height = 760 }; + } + + public void View(string path, ContextObject context) + { + _panel = new Hdf5TextPanel(); + context.ViewerContent = _panel; + context.Title = Path.GetFileName(path); + + try + { + _panel.SetText(Hdf5SummaryBuilder.Build(path)); + } + catch (Exception ex) + { + _panel.SetText( + $"Failed to open HDF5 file.{Environment.NewLine}{Environment.NewLine}" + + $"{ex.GetType().Name}: {ex.Message}"); + } + finally + { + context.IsBusy = false; + } + } + + public void Cleanup() + { + GC.SuppressFinalize(this); + _panel = null; + } + + private static bool HasHdf5Signature(string path) + { + var probes = new long[12]; + probes[0] = 0; + + for (var i = 1; i < probes.Length; i++) + probes[i] = 512L << (i - 1); + + try + { + using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + if (stream.Length < Hdf5Signature.Length) + return false; + + var header = new byte[Hdf5Signature.Length]; + + foreach (var offset in probes) + { + if (offset + Hdf5Signature.Length > stream.Length) + break; + + stream.Position = offset; + + var read = stream.Read(header, 0, header.Length); + if (read != header.Length) + continue; + + if (header.SequenceEqual(Hdf5Signature)) + return true; + } + } + } + catch + { + return false; + } + + return false; + } +} From fd909ec4402fa93218878aa49b43830b19b14531 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:26:13 +0530 Subject: [PATCH 02/10] update sln file --- QuickLook.sln | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/QuickLook.sln b/QuickLook.sln index a3cb7eaea..dd9b2ccfb 100644 --- a/QuickLook.sln +++ b/QuickLook.sln @@ -58,6 +58,7 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "QuickLook.Installer", "Quic {B4F7C88D-C79D-49E7-A1FB-FB69CF72585F} = {B4F7C88D-C79D-49E7-A1FB-FB69CF72585F} {311E6E78-3A5B-4E51-802A-5755BD5F9F97} = {311E6E78-3A5B-4E51-802A-5755BD5F9F97} {B0054A16-472E-44AC-BA40-349303E524FF} = {B0054A16-472E-44AC-BA40-349303E524FF} + {69D60E22-9190-4433-9A6E-1D889CF5CA52} = {69D60E22-9190-4433-9A6E-1D889CF5CA52} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuickLook.Native64", "QuickLook.Native\QuickLook.Native64\QuickLook.Native64.vcxproj", "{794E4DCF-F715-4836-9D30-ABD296586D23}" @@ -92,6 +93,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.MediaInfoV EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.InsvBlocker", "QuickLook.Plugin\QuickLook.Plugin.InsvBlocker\QuickLook.Plugin.InsvBlocker.csproj", "{A1B2C3D4-E5F6-4A5B-9C8D-7E6F5A4B3C2D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.Hdf5Viewer", "QuickLook.Plugin\QuickLook.Plugin.Hdf5Viewer\QuickLook.Plugin.Hdf5Viewer.csproj", "{69D60E22-9190-4433-9A6E-1D889CF5CA52}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -300,6 +303,14 @@ Global {A1B2C3D4-E5F6-4A5B-9C8D-7E6F5A4B3C2D}.Release|Any CPU.Build.0 = Release|Any CPU {A1B2C3D4-E5F6-4A5B-9C8D-7E6F5A4B3C2D}.Release|x64.ActiveCfg = Release|Any CPU {A1B2C3D4-E5F6-4A5B-9C8D-7E6F5A4B3C2D}.Release|x64.Build.0 = Release|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Debug|x64.ActiveCfg = Debug|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Debug|x64.Build.0 = Debug|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Release|Any CPU.Build.0 = Release|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Release|x64.ActiveCfg = Release|Any CPU + {69D60E22-9190-4433-9A6E-1D889CF5CA52}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -327,6 +338,7 @@ Global {311E6E78-3A5B-4E51-802A-5755BD5F9F97} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} {B0054A16-472E-44AC-BA40-349303E524FF} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} {A1B2C3D4-E5F6-4A5B-9C8D-7E6F5A4B3C2D} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} + {69D60E22-9190-4433-9A6E-1D889CF5CA52} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D3761C32-8C5F-498A-892B-3B0882994B62} From d5322d6c4c8c7723f61b510901b653b6c3457d33 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:26:31 +0530 Subject: [PATCH 03/10] update slnx to include hdf5 viewer --- QuickLook.slnx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QuickLook.slnx b/QuickLook.slnx index cf08c3890..293e98b1b 100644 --- a/QuickLook.slnx +++ b/QuickLook.slnx @@ -17,6 +17,7 @@ + @@ -48,6 +49,7 @@ + From f73dff1499f82ef5f715ddeeda2c4ac813771acc Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:26:43 +0530 Subject: [PATCH 04/10] update csproj --- .../QuickLook.Plugin.Hdf5Viewer.csproj | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj new file mode 100644 index 000000000..f80c26b24 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj @@ -0,0 +1,75 @@ + + + + Library + net462 + QuickLook.Plugin.Hdf5Viewer + QuickLook.Plugin.Hdf5Viewer + 512 + false + true + latest + false + false + false + MinimumRecommendedRules.ruleset + {69D60E22-9190-4433-9A6E-1D889CF5CA52} + + + + true + full + false + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.Hdf5Viewer\ + DEBUG;TRACE + AnyCPU + prompt + + + + pdbonly + true + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.Hdf5Viewer\ + TRACE + AnyCPU + prompt + + + + true + full + false + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.Hdf5Viewer\ + DEBUG;TRACE + x86 + prompt + + + + pdbonly + true + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.Hdf5Viewer\ + TRACE + x86 + prompt + + + + + + + + + {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} + QuickLook.Common + False + + + + + + Properties\GitVersion.cs + + + + From 8dcb280519222b96b2abc2ebd300c7a201c21a0f Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:26:52 +0530 Subject: [PATCH 05/10] create hdf5 text panel --- .../Hdf5TextPanel.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5TextPanel.cs diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5TextPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5TextPanel.cs new file mode 100644 index 000000000..ad5564a30 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5TextPanel.cs @@ -0,0 +1,32 @@ +using System.Windows.Controls; +using System.Windows.Media; + +namespace QuickLook.Plugin.Hdf5Viewer; + +public sealed class Hdf5TextPanel : UserControl +{ + private readonly TextBox _textBox; + + public Hdf5TextPanel() + { + _textBox = new TextBox + { + IsReadOnly = true, + TextWrapping = System.Windows.TextWrapping.NoWrap, + VerticalScrollBarVisibility = ScrollBarVisibility.Auto, + HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, + FontFamily = new FontFamily("Consolas"), + FontSize = 13, + BorderThickness = new System.Windows.Thickness(0), + Padding = new System.Windows.Thickness(12, 8, 12, 8) + }; + + Content = _textBox; + } + + public void SetText(string text) + { + _textBox.Text = text ?? string.Empty; + _textBox.CaretIndex = 0; + } +} From a76470a2384f01941157626574761d027fac7937 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:27:10 +0530 Subject: [PATCH 06/10] create summery builder for hdf5 plugin viewer --- .../Hdf5SummaryBuilder.cs | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs new file mode 100644 index 000000000..de446dbf1 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs @@ -0,0 +1,139 @@ +using HDF5.NET; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace QuickLook.Plugin.Hdf5Viewer; + +internal static class Hdf5SummaryBuilder +{ + private const int MaxDepth = 16; + private const int MaxChildrenPerGroup = 250; + private const int MaxAttributesPerObject = 20; + + public static string Build(string path) + { + var sb = new StringBuilder(32 * 1024); + + using (var file = H5File.OpenRead(path)) + { + sb.AppendLine("HDF5 structure summary"); + sb.AppendLine(); + + AppendObject(file, sb, depth: 0); + } + + return sb.ToString(); + } + + private static void AppendObject(H5Object h5Object, StringBuilder sb, int depth) + { + if (depth > MaxDepth) + { + sb.AppendLine($"{Indent(depth)}... depth limit reached"); + return; + } + + switch (h5Object) + { + case H5Group group: + AppendGroup(group, sb, depth); + return; + case H5Dataset dataset: + AppendDataset(dataset, sb, depth); + return; + case H5CommitedDatatype committedDatatype: + sb.AppendLine($"{Indent(depth)}[DATATYPE] {SafeName(committedDatatype.Name)}"); + return; + case H5UnresolvedLink unresolvedLink: + sb.AppendLine($"{Indent(depth)}[UNRESOLVED] {SafeName(unresolvedLink.Name)}"); + return; + default: + sb.AppendLine($"{Indent(depth)}[{h5Object.GetType().Name}] {SafeName(h5Object.Name)}"); + return; + } + } + + private static void AppendGroup(H5Group group, StringBuilder sb, int depth) + { + sb.AppendLine($"{Indent(depth)}[GROUP] {SafeName(group.Name)}"); + AppendAttributes(group, sb, depth + 1); + + var children = SafeReadChildren(group).ToList(); + var visibleChildren = children.Take(MaxChildrenPerGroup).ToList(); + + foreach (var child in visibleChildren) + AppendObject(child, sb, depth + 1); + + if (children.Count > MaxChildrenPerGroup) + sb.AppendLine($"{Indent(depth + 1)}... {children.Count - MaxChildrenPerGroup} more children"); + } + + private static void AppendDataset(H5Dataset dataset, StringBuilder sb, int depth) + { + var dimensions = string.Join(" x ", dataset.Space.Dimensions.Select(d => d.ToString())); + var shape = string.IsNullOrWhiteSpace(dimensions) ? "scalar" : dimensions; + + sb.AppendLine( + $"{Indent(depth)}[DATASET] {SafeName(dataset.Name)} | " + + $"shape={shape}, dtype={dataset.Type.Class}, itemSize={dataset.Type.Size}B, layout={dataset.Layout.Class}"); + + AppendAttributes(dataset, sb, depth + 1); + } + + private static void AppendAttributes(H5AttributableObject attributable, StringBuilder sb, int depth) + { + List attributes; + + try + { + attributes = attributable.Attributes.ToList(); + } + catch (Exception ex) + { + sb.AppendLine($"{Indent(depth)}@attributes: "); + return; + } + + if (!attributes.Any()) + return; + + var visible = attributes.Take(MaxAttributesPerObject).ToList(); + + foreach (var attribute in visible) + { + var dimensions = string.Join(" x ", attribute.Space.Dimensions.Select(d => d.ToString())); + var shape = string.IsNullOrWhiteSpace(dimensions) ? "scalar" : dimensions; + + sb.AppendLine( + $"{Indent(depth)}@{SafeName(attribute.Name)} " + + $"(type={attribute.Type.Class}, shape={shape}, itemSize={attribute.Type.Size}B)"); + } + + if (attributes.Count > MaxAttributesPerObject) + sb.AppendLine($"{Indent(depth)}... {attributes.Count - MaxAttributesPerObject} more attributes"); + } + + private static IEnumerable SafeReadChildren(H5Group group) + { + try + { + return group.Children; + } + catch + { + return Array.Empty(); + } + } + + private static string SafeName(string name) + { + return string.IsNullOrEmpty(name) ? "/" : name; + } + + private static string Indent(int level) + { + return new string(' ', level * 2); + } +} From ae4d4fca3f07527694b7c8032313be7c447176e3 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:57:37 +0530 Subject: [PATCH 07/10] Update Hdf5SummaryBuilder.cs --- .../Hdf5SummaryBuilder.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs index de446dbf1..837d9db5b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs @@ -84,11 +84,27 @@ private static void AppendDataset(H5Dataset dataset, StringBuilder sb, int depth private static void AppendAttributes(H5AttributableObject attributable, StringBuilder sb, int depth) { - List attributes; + var visible = new List(MaxAttributesPerObject); + var hasMoreAttributes = false; try { - attributes = attributable.Attributes.ToList(); + var count = 0; + + foreach (var attribute in attributable.Attributes) + { + count++; + + if (count <= MaxAttributesPerObject) + { + visible.Add(attribute); + } + else + { + hasMoreAttributes = true; + break; + } + } } catch (Exception ex) { @@ -96,11 +112,9 @@ private static void AppendAttributes(H5AttributableObject attributable, StringBu return; } - if (!attributes.Any()) + if (visible.Count == 0) return; - var visible = attributes.Take(MaxAttributesPerObject).ToList(); - foreach (var attribute in visible) { var dimensions = string.Join(" x ", attribute.Space.Dimensions.Select(d => d.ToString())); @@ -111,8 +125,8 @@ private static void AppendAttributes(H5AttributableObject attributable, StringBu $"(type={attribute.Type.Class}, shape={shape}, itemSize={attribute.Type.Size}B)"); } - if (attributes.Count > MaxAttributesPerObject) - sb.AppendLine($"{Indent(depth)}... {attributes.Count - MaxAttributesPerObject} more attributes"); + if (hasMoreAttributes) + sb.AppendLine($"{Indent(depth)}... more attributes"); } private static IEnumerable SafeReadChildren(H5Group group) From 14c4b6f440a3be4d8931405c04600e272c509954 Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sat, 28 Feb 2026 13:57:55 +0530 Subject: [PATCH 08/10] Update Plugin.cs the previous and this commit basically fixed the issues reported by sourceery-ai on the pr --- .../QuickLook.Plugin.Hdf5Viewer/Plugin.cs | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs index 6aefe419f..70ac4e10b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Plugin.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows; namespace QuickLook.Plugin.Hdf5Viewer; @@ -10,6 +11,7 @@ public sealed class Plugin : IViewer { private static readonly byte[] Hdf5Signature = { 0x89, 0x48, 0x44, 0x46, 0x0D, 0x0A, 0x1A, 0x0A }; private static readonly string[] SupportedExtensions = { ".h5", ".hdf5", ".hdf", ".he5" }; + private static readonly long[] SignatureProbeOffsets = { 0, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288 }; private Hdf5TextPanel _panel; public int Priority => 0; @@ -40,37 +42,38 @@ public void View(string path, ContextObject context) _panel = new Hdf5TextPanel(); context.ViewerContent = _panel; context.Title = Path.GetFileName(path); + context.IsBusy = true; - try - { - _panel.SetText(Hdf5SummaryBuilder.Build(path)); - } - catch (Exception ex) + var panel = _panel; + + Task.Run(() => { - _panel.SetText( - $"Failed to open HDF5 file.{Environment.NewLine}{Environment.NewLine}" + - $"{ex.GetType().Name}: {ex.Message}"); - } - finally + try + { + return Hdf5SummaryBuilder.Build(path); + } + catch (Exception ex) + { + return + $"Failed to open HDF5 file.{Environment.NewLine}{Environment.NewLine}" + + $"{ex.GetType().Name}: {ex.Message}"; + } + }).ContinueWith(t => { + if (panel is not null) + panel.SetText(t.Result); + context.IsBusy = false; - } + }, TaskScheduler.FromCurrentSynchronizationContext()); } public void Cleanup() { - GC.SuppressFinalize(this); _panel = null; } private static bool HasHdf5Signature(string path) { - var probes = new long[12]; - probes[0] = 0; - - for (var i = 1; i < probes.Length; i++) - probes[i] = 512L << (i - 1); - try { using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) @@ -80,7 +83,7 @@ private static bool HasHdf5Signature(string path) var header = new byte[Hdf5Signature.Length]; - foreach (var offset in probes) + foreach (var offset in SignatureProbeOffsets) { if (offset + Hdf5Signature.Length > stream.Length) break; From 3394d53c7727a69807822139679624eaebd62e0f Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sun, 1 Mar 2026 11:37:50 +0530 Subject: [PATCH 09/10] update summery builder to use PureHDF --- .../Hdf5SummaryBuilder.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs index 837d9db5b..ebe840b85 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/Hdf5SummaryBuilder.cs @@ -1,4 +1,4 @@ -using HDF5.NET; +using PureHDF; using System; using System.Collections.Generic; using System.Linq; @@ -15,19 +15,15 @@ internal static class Hdf5SummaryBuilder public static string Build(string path) { var sb = new StringBuilder(32 * 1024); - - using (var file = H5File.OpenRead(path)) - { - sb.AppendLine("HDF5 structure summary"); - sb.AppendLine(); - - AppendObject(file, sb, depth: 0); - } + var file = H5File.OpenRead(path); + sb.AppendLine("HDF5 structure summary"); + sb.AppendLine(); + AppendObject(file, sb, depth: 0); return sb.ToString(); } - private static void AppendObject(H5Object h5Object, StringBuilder sb, int depth) + private static void AppendObject(object h5Object, StringBuilder sb, int depth) { if (depth > MaxDepth) { @@ -37,25 +33,25 @@ private static void AppendObject(H5Object h5Object, StringBuilder sb, int depth) switch (h5Object) { - case H5Group group: + case IH5Group group: AppendGroup(group, sb, depth); return; - case H5Dataset dataset: + case IH5Dataset dataset: AppendDataset(dataset, sb, depth); return; - case H5CommitedDatatype committedDatatype: + case IH5CommitedDatatype committedDatatype: sb.AppendLine($"{Indent(depth)}[DATATYPE] {SafeName(committedDatatype.Name)}"); return; - case H5UnresolvedLink unresolvedLink: + case IH5UnresolvedLink unresolvedLink: sb.AppendLine($"{Indent(depth)}[UNRESOLVED] {SafeName(unresolvedLink.Name)}"); return; default: - sb.AppendLine($"{Indent(depth)}[{h5Object.GetType().Name}] {SafeName(h5Object.Name)}"); + sb.AppendLine($"{Indent(depth)}[{h5Object.GetType().Name}] {SafeName(TryGetName(h5Object))}"); return; } } - private static void AppendGroup(H5Group group, StringBuilder sb, int depth) + private static void AppendGroup(IH5Group group, StringBuilder sb, int depth) { sb.AppendLine($"{Indent(depth)}[GROUP] {SafeName(group.Name)}"); AppendAttributes(group, sb, depth + 1); @@ -70,7 +66,7 @@ private static void AppendGroup(H5Group group, StringBuilder sb, int depth) sb.AppendLine($"{Indent(depth + 1)}... {children.Count - MaxChildrenPerGroup} more children"); } - private static void AppendDataset(H5Dataset dataset, StringBuilder sb, int depth) + private static void AppendDataset(IH5Dataset dataset, StringBuilder sb, int depth) { var dimensions = string.Join(" x ", dataset.Space.Dimensions.Select(d => d.ToString())); var shape = string.IsNullOrWhiteSpace(dimensions) ? "scalar" : dimensions; @@ -82,16 +78,16 @@ private static void AppendDataset(H5Dataset dataset, StringBuilder sb, int depth AppendAttributes(dataset, sb, depth + 1); } - private static void AppendAttributes(H5AttributableObject attributable, StringBuilder sb, int depth) + private static void AppendAttributes(IH5Object attributable, StringBuilder sb, int depth) { - var visible = new List(MaxAttributesPerObject); + var visible = new List(MaxAttributesPerObject); var hasMoreAttributes = false; try { var count = 0; - foreach (var attribute in attributable.Attributes) + foreach (var attribute in attributable.Attributes()) { count++; @@ -129,15 +125,15 @@ private static void AppendAttributes(H5AttributableObject attributable, StringBu sb.AppendLine($"{Indent(depth)}... more attributes"); } - private static IEnumerable SafeReadChildren(H5Group group) + private static IEnumerable SafeReadChildren(IH5Group group) { try { - return group.Children; + return group.Children(); } catch { - return Array.Empty(); + return Array.Empty(); } } @@ -150,4 +146,15 @@ private static string Indent(int level) { return new string(' ', level * 2); } + + private static string TryGetName(object h5Object) + { + if (h5Object is IH5Object namedObject) + return namedObject.Name; + + if (h5Object is IH5UnresolvedLink unresolvedLink) + return unresolvedLink.Name; + + return string.Empty; + } } From e91c3465e483979aea2eed23432c88bc0ed83b6c Mon Sep 17 00:00:00 2001 From: Aarav Maloo Date: Sun, 1 Mar 2026 11:38:02 +0530 Subject: [PATCH 10/10] update csproj. raplced hdf5 net to purehdf --- .../QuickLook.Plugin.Hdf5Viewer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj index f80c26b24..bf448516a 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.Hdf5Viewer/QuickLook.Plugin.Hdf5Viewer.csproj @@ -55,7 +55,7 @@ - +