From c62bb64823237ea7b413ff6e0b734e0eca30a870 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 7 Nov 2021 19:36:27 -0600 Subject: copy example config to app dir --- src/slskd/Program.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index db0f58b5..f649ce40 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 @@ -61,7 +61,7 @@ namespace slskd /// /// The default configuration filename. /// - public static readonly string DefaultConfigurationFile = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.yml"); + public static readonly string DefaultConfigurationFile = Path.Combine(DefaultAppDirectory, $"{AppName}.yml"); /// /// The default incomplete download directory. @@ -230,9 +230,7 @@ namespace slskd try { VerifyDirectory(OptionsAtStartup.Directories.App, createIfMissing: true, verifyWriteable: true); - VerifyDirectory(Path.Combine(OptionsAtStartup.Directories.App, "config"), createIfMissing: true, verifyWriteable: true); VerifyDirectory(Path.Combine(OptionsAtStartup.Directories.App, "data"), createIfMissing: true, verifyWriteable: true); - VerifyDirectory(Path.Combine(OptionsAtStartup.Directories.App, "files"), createIfMissing: true, verifyWriteable: true); VerifyDirectory(OptionsAtStartup.Directories.Incomplete, createIfMissing: true, verifyWriteable: true); VerifyDirectory(OptionsAtStartup.Directories.Downloads, createIfMissing: true, verifyWriteable: true); @@ -243,6 +241,20 @@ namespace slskd return; } + try + { + // for convenience, try to copy the example configuration file to the application directory + // if any part fails, just move on silently. + var exampleFileName = $"{AppName}.example.yml"; + var source = Path.Combine(AppContext.BaseDirectory, "config", exampleFileName); + var destination = Path.Combine(OptionsAtStartup.Directories.App, exampleFileName); + File.Copy(source, destination); + } + catch + { + // no-op + } + Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information()) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System.Net.Http.HttpClient", OptionsAtStartup.Debug ? LogEventLevel.Warning : LogEventLevel.Fatal) -- cgit v1.2.3