diff --git a/ErsatzTV.Application/Graphics/Commands/RefreshGraphicsElementsHandler.cs b/ErsatzTV.Application/Graphics/Commands/RefreshGraphicsElementsHandler.cs index d94891eb3..b30ebd18d 100644 --- a/ErsatzTV.Application/Graphics/Commands/RefreshGraphicsElementsHandler.cs +++ b/ErsatzTV.Application/Graphics/Commands/RefreshGraphicsElementsHandler.cs @@ -24,7 +24,7 @@ public class RefreshGraphicsElementsHandler( .ToListAsync(cancellationToken); var missing = allExisting - .Where(e => !localFileSystem.FileExists(e.Path) || Path.GetExtension(e.Path) != ".yml") + .Where(e => !localFileSystem.FileExists(e.Path) || (Path.GetExtension(e.Path) != ".yml" && Path.GetExtension(e.Path) != ".yaml")) .ToList(); foreach (GraphicsElement existing in missing) @@ -42,7 +42,7 @@ public class RefreshGraphicsElementsHandler( } // add new text elements - var newTextPaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsTextTemplatesFolder, "*.yml") + var newTextPaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsTextTemplatesFolder, "*.yml", "*.yaml") .Where(f => allExisting.All(e => e.Path != f)) .ToList(); @@ -62,7 +62,7 @@ public class RefreshGraphicsElementsHandler( } // add new image elements - var newImagePaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsImageTemplatesFolder, "*.yml") + var newImagePaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsImageTemplatesFolder, "*.yml", "*.yaml") .Where(f => allExisting.All(e => e.Path != f)) .ToList(); @@ -82,7 +82,7 @@ public class RefreshGraphicsElementsHandler( } // add new motion elements - var newMotionPaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsMotionTemplatesFolder, "*.yml") + var newMotionPaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsMotionTemplatesFolder, "*.yml", "*.yaml") .Where(f => allExisting.All(e => e.Path != f)) .ToList(); @@ -102,7 +102,7 @@ public class RefreshGraphicsElementsHandler( } // add new subtitle elements - var newSubtitlePaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsSubtitleTemplatesFolder, "*.yml") + var newSubtitlePaths = localFileSystem.ListFiles(FileSystemLayout.GraphicsElementsSubtitleTemplatesFolder, "*.yml", "*.yaml") .Where(f => allExisting.All(e => e.Path != f)) .ToList(); diff --git a/ErsatzTV.Core/Interfaces/Metadata/ILocalFileSystem.cs b/ErsatzTV.Core/Interfaces/Metadata/ILocalFileSystem.cs index 8e33c707d..ba4f8e027 100644 --- a/ErsatzTV.Core/Interfaces/Metadata/ILocalFileSystem.cs +++ b/ErsatzTV.Core/Interfaces/Metadata/ILocalFileSystem.cs @@ -10,6 +10,7 @@ public interface ILocalFileSystem IEnumerable ListSubdirectories(string folder); IEnumerable ListFiles(string folder); IEnumerable ListFiles(string folder, string searchPattern); + IEnumerable ListFiles(string folder, params string[] searchPatterns); bool FileExists(string path); bool FolderExists(string folder); Task> CopyFile(string source, string destination); diff --git a/ErsatzTV.Core/Metadata/LocalFileSystem.cs b/ErsatzTV.Core/Metadata/LocalFileSystem.cs index 839126b7a..40c819c8c 100644 --- a/ErsatzTV.Core/Metadata/LocalFileSystem.cs +++ b/ErsatzTV.Core/Metadata/LocalFileSystem.cs @@ -109,6 +109,32 @@ public class LocalFileSystem(IClient client, ILogger logger) : return new List(); } + public IEnumerable ListFiles(string folder, params string[] searchPatterns) + { + if (folder is not null && Directory.Exists(folder)) + { + try + { + return searchPatterns + .SelectMany(searchPattern => + Directory.EnumerateFiles(folder, searchPattern, SearchOption.TopDirectoryOnly) + .Where(path => !Path.GetFileName(path).StartsWith("._", StringComparison.OrdinalIgnoreCase))) + .Distinct(); + } + catch (UnauthorizedAccessException) + { + logger.LogWarning("Unauthorized access exception listing files in folder {Folder}", folder); + } + catch (Exception ex) + { + // do nothing + client.Notify(ex); + } + } + + return new List(); + } + public bool FileExists(string path) => File.Exists(path); public bool FolderExists(string folder) => Directory.Exists(folder);