From 6626a23876f31671665e90f09aceb6e3af5d0272 Mon Sep 17 00:00:00 2001 From: John Cruikshank Date: Fri, 24 May 2024 00:24:19 +0000 Subject: [PATCH] Create directory if it does not exist Fixes #12 --- src/ServerManagerDiscordBot/ServerManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ServerManagerDiscordBot/ServerManager.cs b/src/ServerManagerDiscordBot/ServerManager.cs index 6b59cda..5ba28f2 100644 --- a/src/ServerManagerDiscordBot/ServerManager.cs +++ b/src/ServerManagerDiscordBot/ServerManager.cs @@ -123,7 +123,7 @@ public async Task> GetServerFilesAsync(string name, Cancel var directory = new DirectoryInfo(server.FilesPath); if (!directory.Exists) { - throw new DirectoryNotFoundException($"The `{name}` server files directory `{server.FilesPath}` does not exist."); + directory.Create(); } var files = directory.EnumerateFiles(); @@ -161,7 +161,7 @@ public async Task> GetServerGalleryFilesAsync(string name, var directory = new DirectoryInfo(server.GalleryPath); if (!directory.Exists) { - throw new DirectoryNotFoundException($"The `{name}` server gallery directory `{server.GalleryPath}` does not exist."); + directory.Create(); } var files = directory.EnumerateFiles() @@ -179,6 +179,12 @@ public async Task UploadServerGalleryFileAsync(string name, string sourceUrl, st throw new InvalidOperationException($"The `{name}` server does not support this operation."); } + var directory = new DirectoryInfo(server.GalleryPath); + if (!directory.Exists) + { + directory.Create(); + } + if (!AppSettings.GalleryFileExtensions.Contains(Path.GetExtension(fileName).Substring(1), StringComparer.OrdinalIgnoreCase)) { throw new ArgumentException($"The gallery does not support the file type `{Path.GetExtension(fileName)}`.");