From ccc8dd5b45a3e95c232ef790f27047ad98bb3885 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 May 2021 09:45:01 -0500 Subject: add DefaultAppDirectory --- src/slskd/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 00d6d5b4..9998cd39 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -52,9 +52,9 @@ namespace slskd public static readonly string AppName = "slskd"; /// - /// The default database filename. + /// The default application data directory. /// - public static readonly string DefaultDatabaseFile = Path.Combine(AppContext.BaseDirectory, "data", $"{AppName}.db"); + public static readonly string DefaultAppDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName); /// /// The default configuration filename. -- cgit v1.2.3 From 3aee2dcd11b80f21d5845f817166cbe184abd337 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 May 2021 09:45:37 -0500 Subject: default shared, downloads and incomplete dirs to app subdirectories --- src/slskd/Program.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 9998cd39..bf864d10 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -64,7 +64,21 @@ namespace slskd /// /// The default XML documentation filename. /// - public static readonly string DefaultXmlDocumentaitonFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); + + /// + /// The default incomplete download directory. + /// + public static readonly string DefaultIncompleteDirectory = Path.Combine(DefaultAppDirectory, "incomplete"); + + /// + /// The default downloads directory. + /// + public static readonly string DefaultDownloadsDirectory = Path.Combine(DefaultAppDirectory, "downloads"); + + /// + /// The default shared directory. + /// + public static readonly string DefaultSharedDirectory = Path.Combine(DefaultAppDirectory, "shared"); /// /// The global prefix for environment variables. -- cgit v1.2.3 From c12ab7abf3a7591df11ea589e9cb8c16b65aaa3b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 May 2021 09:45:52 -0500 Subject: fix typo --- src/slskd/Program.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index bf864d10..a3b16af1 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -64,6 +64,7 @@ namespace slskd /// /// The default XML documentation filename. /// + public static readonly string DefaultXmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); /// /// The default incomplete download directory. -- cgit v1.2.3 From 5ddef023a9dbaf1ace7e534d5c45bee7094d8f16 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 May 2021 09:46:15 -0500 Subject: ensure app directory exists and is writeable --- src/slskd/Program.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index a3b16af1..e62a3529 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -213,6 +213,37 @@ namespace slskd return; } + // ensure the application directory exists and is writeable. the most comprehensive way to test this is to try + // to write a file to it. + try + { + if (!Directory.Exists(Options.Directories.App)) + { + Directory.CreateDirectory(Options.Directories.App); + } + } + catch (Exception ex) + { + Console.WriteLine($"App directory {Options.Directories.App} does not exist, and could not be created: {ex.Message}"); + } + + try + { + if (!Directory.Exists(Options.Directories.App)) + { + Directory.CreateDirectory(Options.Directories.App); + } + + var probe = Path.Combine(Options.Directories.App, "probe"); + File.WriteAllText(Path.Combine(Options.Directories.App, "probe"), string.Empty); + File.Delete(probe); + } + catch (Exception ex) + { + Console.WriteLine($"App directory {Options.Directories.App} is not writeable: {ex.Message}"); + return; + } + if (!Options.NoLogo) { PrintLogo(Version); -- cgit v1.2.3 From b564075e251b5fc4dbe2d1f801ed24523575437b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 12 May 2021 09:46:45 -0500 Subject: fix typo --- src/slskd/Program.cs | 2 +- src/slskd/Startup.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e62a3529..a9f4ef94 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index f7787409..c63699cf 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -145,13 +145,13 @@ namespace slskd Version = "v0", }); - if (File.Exists(Program.DefaultXmlDocumentaitonFile)) + if (File.Exists(Program.DefaultXmlDocumentationFile)) { - options.IncludeXmlComments(Program.DefaultXmlDocumentaitonFile); + options.IncludeXmlComments(Program.DefaultXmlDocumentationFile); } else { - logger.Warning($"Unable to find XML documentation in {Program.DefaultXmlDocumentaitonFile}, Swagger will not include metadata"); + logger.Warning($"Unable to find XML documentation in {Program.DefaultXmlDocumentationFile}, Swagger will not include metadata"); } }); } -- cgit v1.2.3 From c89ea31876643110296e7cad7c09bd8027ce4685 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 14 May 2021 12:59:50 -0500 Subject: indicate required options in help --- src/slskd/Program.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index a9f4ef94..8035c010 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -20,6 +20,7 @@ namespace slskd using System; using System.Collections.Generic; using System.ComponentModel; + using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; using System.Net; @@ -420,6 +421,7 @@ namespace slskd { var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(ArgumentAttribute)); var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); + var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); if (attribute != default) { @@ -427,9 +429,9 @@ namespace slskd var longName = (string)attribute.ConstructorArguments[1].Value; var description = descriptionAttribute?.ConstructorArguments[0].Value; - var suffix = property.PropertyType == typeof(bool) ? string.Empty : $" (default: {property.GetValue(defaults) ?? ""})"; - var item = $"{shortName}{(shortName == default ? " " : "|")}--{GetLongName(longName, property.PropertyType)}"; - var desc = $"{description}{suffix}"; + var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? ""})"; + var item = $"{(shortName == default ? " " : $"{shortName}|")}--{GetLongName(longName, property.PropertyType)}"; + var desc = $"{description}{(property.PropertyType == typeof(bool) ? string.Empty : suffix)}"; lines.Add(new(item, desc)); } else @@ -467,15 +469,16 @@ namespace slskd { var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(EnvironmentVariableAttribute)); var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); + var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); if (attribute != default) { var name = (string)attribute.ConstructorArguments[0].Value; var description = descriptionAttribute?.ConstructorArguments[0].Value; - var suffix = type == typeof(bool) ? string.Empty : $" (default: {property.GetValue(defaults) ?? ""})"; + var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? ""})"; var item = $"{prefix}{GetName(name, property.PropertyType)}"; - var desc = $"{description}{suffix}"; + var desc = $"{description} {(type == typeof(bool) ? string.Empty : suffix)}"; lines.Add(new(item, desc)); } else -- cgit v1.2.3 From 1dfcbf0975f428446951e6a03f4ac259dc0047d1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 14 May 2021 13:46:42 -0500 Subject: remove redundant space --- src/slskd/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 8035c010..d70b50c1 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -478,7 +478,7 @@ namespace slskd var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? ""})"; var item = $"{prefix}{GetName(name, property.PropertyType)}"; - var desc = $"{description} {(type == typeof(bool) ? string.Empty : suffix)}"; + var desc = $"{description}{(type == typeof(bool) ? string.Empty : suffix)}"; lines.Add(new(item, desc)); } else -- cgit v1.2.3