From 09a78d9da1267f6d71d543f57e7f65ea7a55ebd0 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 5 Jul 2026 16:24:58 -0500 Subject: [PATCH] Fix enumeration of script snippets --- LANCommander.Server.Services/ScriptService.cs | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/LANCommander.Server.Services/ScriptService.cs b/LANCommander.Server.Services/ScriptService.cs index 6fa2a65d..57630138 100644 --- a/LANCommander.Server.Services/ScriptService.cs +++ b/LANCommander.Server.Services/ScriptService.cs @@ -101,29 +101,22 @@ namespace LANCommander.Server.Services public IEnumerable GetSnippets() { - var storagePath = settingsProvider.CurrentValue.Server.Scripts.Snippets.StoragePath; - - if (string.IsNullOrWhiteSpace(storagePath)) - { - // Set default storage path - storagePath = AppPaths.GetConfigPath("Snippets"); - - settingsProvider.Update(s => - { - s.Server.Scripts.Snippets.StoragePath = storagePath; - }); - } - + var storagePath = GetSnippetsStoragePath(); + var files = Directory.GetFiles(storagePath, "*.ps1", SearchOption.AllDirectories); return files.Select(f => { - var split = f.Substring(storagePath.Length).TrimStart('/').Split(Path.DirectorySeparatorChar); + var relative = Path.GetRelativePath(storagePath, f); + + var split = relative.Split( + new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, + StringSplitOptions.RemoveEmptyEntries); return new Snippet { Name = Path.GetFileNameWithoutExtension(f), - Group = split[1], + Group = split.Length > 1 ? split[0] : string.Empty, Content = File.ReadAllText(f) }; });