Update UI

This commit is contained in:
Black_Betty committed 2026-10-04 22:56:54 +02:00
1 parent abab3612f2
commit a3b41679c9
6 files changed
+417 -315

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
namespace TapeCatalog.Methods
{
/// <summary>
/// Helpers to read XML files and produce a compact summary used by the UI.
/// </summary>
public static class Xml
{
public static List<TapeCatalog.FileEntry> ParseSummary(string filePath)
{
var result = new List<TapeCatalog.FileEntry>();
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
return result;
try
{
var doc = XDocument.Load(filePath);
var root = doc.Root;
if (root == null) return result;
if (string.Equals(root.Name.LocalName, "Files", StringComparison.OrdinalIgnoreCase))
{
foreach (var fe in root.Elements("File"))
{
try
{
var fn = fe.Element("Filename")?.Value ?? string.Empty;
var fd = fe.Element("FileDir")?.Value ?? string.Empty;
var st = fe.Element("Status")?.Value ?? string.Empty;
result.Add(new TapeCatalog.FileEntry { Filename = fn, FileDir = fd, Status = st });
}
catch
{
// ignore malformed entries
}
}
}
else if (string.Equals(root.Name.LocalName, "TapeEntries", StringComparison.OrdinalIgnoreCase))
{
foreach (var entry in root.Elements("Entry"))
{
try
{
var fn = entry.Element("Filename")?.Value ?? string.Empty;
var med = entry.Element("Medium")?.Value ?? string.Empty;
var mod = entry.Element("Modified")?.Value ?? string.Empty;
result.Add(new TapeCatalog.FileEntry { Filename = fn, FileDir = med, Status = mod });
}
catch
{
// ignore malformed entries
}
}
}
}
catch
{
// ignore parse errors and return empty list
}
return result;
}
public static string[] GetXmlFiles(string xmlDirectory)
{
if (string.IsNullOrWhiteSpace(xmlDirectory) || !Directory.Exists(xmlDirectory))
return Array.Empty<string>();
try
{
return Directory.GetFiles(xmlDirectory, "*.xml", SearchOption.TopDirectoryOnly);
}
catch
{
return Array.Empty<string>();
}
}
}
}