From 2b307601cd37a58e79090517bdb385bce98ff3ef Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 20 Dec 2021 09:03:45 -0600 Subject: fix initialization issues --- src/slskd/Program.cs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 66729556..29477120 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -101,22 +101,22 @@ namespace slskd /// /// Gets the semantic application version. /// - public static string SemanticVersion => InformationalVersion.Split('-').First(); + public static string SemanticVersion { get; } = InformationalVersion.Split('-').First(); /// /// Gets the full application version, including both assembly and informational versions. /// - public static string FullVersion => $"{SemanticVersion} ({InformationalVersion})"; + public static string FullVersion { get; } = $"{SemanticVersion} ({InformationalVersion})"; /// /// Gets a value indicating whether the current version is a Canary build. /// - public static bool IsCanary => AssemblyVersion.Revision == 65534; + public static bool IsCanary { get; } = AssemblyVersion.Revision == 65534; /// /// Gets a value indicating whether the current version is a Development build. /// - public static bool IsDevelopment => new Version(0, 0, 0, 0) == AssemblyVersion; + public static bool IsDevelopment { get; } = new Version(0, 0, 0, 0) == AssemblyVersion; /// /// Gets the path where application data is saved. @@ -135,17 +135,17 @@ namespace slskd /// /// Gets the default fully qualified path to the configuration file. /// - public static string DefaultConfigurationFile => Path.Combine(AppDirectory, $"{AppName}.yml"); + public static string DefaultConfigurationFile { get; private set; } /// /// Gets the default downloads directory. /// - public static string DefaultDownloadsDirectory => Path.Combine(AppDirectory, "downloads"); + public static string DefaultDownloadsDirectory { get; private set; } /// /// Gets the default incomplete download directory. /// - public static string DefaultIncompleteDirectory => Path.Combine(AppDirectory, "incomplete"); + public static string DefaultIncompleteDirectory { get; private set; } /// /// Gets a buffer containing the last few log events. @@ -181,9 +181,6 @@ namespace slskd EnvironmentVariables.Populate(prefix: EnvironmentVariablePrefix); Arguments.Populate(clearExistingValues: false); - AppDirectory ??= DefaultAppDirectory; - ConfigurationFile ??= DefaultConfigurationFile; - if (ShowVersion) { Console.WriteLine(FullVersion); @@ -216,7 +213,19 @@ namespace slskd return; } - // the application isn't being run in command mode. verify (create if needed) default application + // the application isn't being run in command mode. derive the application directory value + // and defaults that are dependent upon it + AppDirectory ??= DefaultAppDirectory; + + DefaultConfigurationFile = Path.Combine(AppDirectory, $"{AppName}.yml"); + DefaultDownloadsDirectory = Path.Combine(AppDirectory, "downloads"); + DefaultIncompleteDirectory = Path.Combine(AppDirectory, "incomplete"); + + // the location of the configuration file might have been overriden by command line or envar. + // if not, set it to the default. + ConfigurationFile ??= DefaultConfigurationFile; + + // verify(create if needed) default application // directories. if the downloads or complete directories are overridden in config, those will be // validated after the config is loaded. try -- cgit v1.2.3