Made some minor changes and set in a widget for the web

This commit is contained in:
minster586
2026-04-12 23:45:04 -04:00
parent 79268a61ff
commit 761b382364
11 changed files with 787 additions and 21 deletions
+41
View File
@@ -0,0 +1,41 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
namespace RadioDJViewer
{
public static class EmbeddedResourceHelper
{
/// <summary>
/// Reads an embedded resource's text content by matching the resource name ending with the provided file name.
/// Example: call Read("index.html") to load a resource named "RadioDJViewer.Web.index.html" or similar.
/// </summary>
public static string Read(string fileName)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentNullException(nameof(fileName));
var asm = Assembly.GetExecutingAssembly();
var resourceName = asm.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith(fileName, StringComparison.OrdinalIgnoreCase));
if (resourceName == null)
{
var names = string.Join(", ", asm.GetManifestResourceNames());
throw new FileNotFoundException($"Embedded resource '{fileName}' not found. Available resources: {names}");
}
using (var stream = asm.GetManifestResourceStream(resourceName))
{
if (stream == null)
throw new FileNotFoundException($"Resource stream '{resourceName}' is null.");
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
}