aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-29 06:58:40 -0500
committerGitHub <noreply@github.com>2021-07-29 06:58:40 -0500
commitf22fff743ffcff1f71fccf738793255c5070ece7 (patch)
treeaf3c12d1180acff4ff5a8fb0af8632eb93d0e1e3 /src/slskd/Program.cs
parent69d29c1eaa03992cf786d1d9b1ec1935dd85ef42 (diff)
parentc643d91c7feb9ab360539c17380e24673f0a102b (diff)
downloadslskd-f22fff743ffcff1f71fccf738793255c5070ece7.tar.gz
Merge pull request #132 from slskd/shares
Allow multiple shared directories
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index b5275756..fa1be786 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -212,19 +212,6 @@ namespace slskd
return;
}
- try
- {
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.App);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Incomplete);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Downloads);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Shared, verifyWriteable: false);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Filesystem exception: {ex.Message}");
- return;
- }
-
Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information())
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("slskd.API.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Information)
@@ -249,6 +236,26 @@ namespace slskd
var logger = Log.ForContext(typeof(Program));
+ try
+ {
+ VerifyDirectory(OptionsAtStartup.Directories.App, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(OptionsAtStartup.Directories.Incomplete, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(OptionsAtStartup.Directories.Downloads, createIfMissing: true, verifyWriteable: true);
+
+ foreach (var share in OptionsAtStartup.Directories.Shared)
+ {
+ if (!VerifyDirectory(share, createIfMissing: false, verifyWriteable: false))
+ {
+ logger.Warning("Shared directory {Directory} does not exist", share);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.Error(ex, "Filesystem exception: {Message}", ex.Message);
+ return;
+ }
+
if (!OptionsAtStartup.NoLogo)
{
PrintLogo(Version);
@@ -505,19 +512,26 @@ namespace slskd
Console.WriteLine(banner);
}
- private static void VerifyOrCreateDirectory(string directory, bool verifyWriteable = true)
+ private static bool VerifyDirectory(string directory, bool createIfMissing = true, bool verifyWriteable = true)
{
- try
+ if (!Directory.Exists(directory))
{
- if (!Directory.Exists(directory))
+ if (createIfMissing)
+ {
+ try
+ {
+ Directory.CreateDirectory(directory);
+ }
+ catch (Exception ex)
+ {
+ throw new IOException($"Directory {directory} does not exist, and could not be created: {ex.Message}", ex);
+ }
+ }
+ else
{
- Directory.CreateDirectory(directory);
+ return false;
}
}
- catch (Exception ex)
- {
- throw new IOException($"Directory {directory} does not exist, and could not be created: {ex.Message}", ex);
- }
if (verifyWriteable)
{
@@ -533,6 +547,8 @@ namespace slskd
throw new IOException($"Directory {directory} is not writeable: {ex.Message}", ex);
}
}
+
+ return true;
}
}
} \ No newline at end of file