Skip to content

Commit

Permalink
Create directory if it does not exist
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
cruikshj committed May 24, 2024
1 parent 7299564 commit 6626a23
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ServerManagerDiscordBot/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task<IEnumerable<FileInfo>> 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();
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<IEnumerable<FileInfo>> 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()
Expand All @@ -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)}`.");
Expand Down

0 comments on commit 6626a23

Please sign in to comment.