diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 21:19:45 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-11-08 21:19:45 -0600 |
| commit | 45814aa89c7d56ba4f3c44583262d9ea06d932b2 (patch) | |
| tree | d33236772c77d02511f9df29058dff6c19fa88d1 /src/slskd/Program.cs | |
| parent | 7d936c12da1587961c22caf5dded805bcbba53de (diff) | |
| download | slskd-45814aa89c7d56ba4f3c44583262d9ea06d932b2.tar.gz | |
move things around, create config file if not exists
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e4c15704..3aba9ec3 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -54,19 +54,9 @@ namespace slskd public static readonly string AppName = "slskd"; /// <summary> - /// The default application data directory. - /// </summary> - public static readonly string DefaultAppDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), AppName); - - /// <summary> - /// The default incomplete download directory. - /// </summary> - public static string DefaultIncompleteDirectory => Path.Combine(AppDirectory, "incomplete"); - - /// <summary> - /// The default downloads directory. + /// The url to the issues/support site. /// </summary> - public static string DefaultDownloadsDirectory => Path.Combine(AppDirectory, "downloads"); + public static readonly string IssuesUrl = "https://github.com/slskd/slskd/issues"; /// <summary> /// The global prefix for environment variables. @@ -74,26 +64,14 @@ namespace slskd public static readonly string EnvironmentVariablePrefix = $"{AppName.ToUpperInvariant()}_"; /// <summary> - /// The url to the issues/support site. - /// </summary> - public static readonly string IssuesUrl = "https://github.com/slskd/slskd/issues"; - - /// <summary> /// The default XML documentation filename. /// </summary> public static readonly string XmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); /// <summary> - /// Occurs when a new log event is emitted. - /// </summary> - public static event EventHandler<LogRecord> LogEmitted; - - /// <summary> - /// Gets the path where application data is saved. + /// The default application data directory. /// </summary> - [Argument(default, "appdir", "path where application data is saved")] - [EnvironmentVariable("APP_DIR")] - public static string AppDirectory { get; private set; } = DefaultAppDirectory; + public static readonly string DefaultAppDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), AppName); /// <summary> /// Gets the assembly version of the application. @@ -101,7 +79,7 @@ namespace slskd /// <remarks> /// Inaccurate when running locally. /// </remarks> - public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1, 0, 0, 0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; + public static readonly Version AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1, 0, 0, 0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; /// <summary> /// Gets the informational version of the application, including the git sha at the latest commit. @@ -109,27 +87,49 @@ namespace slskd /// <remarks> /// Inaccurate when running locally. /// </remarks> - public static string InformationalVersion { get; } = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion == "1.0.0" ? "0.0.0" : Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; + public static readonly string InformationalVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion == "1.0.0" ? "0.0.0" : Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; + + /// <summary> + /// Gets the full application version, including both assembly and informational versions. + /// </summary> + public static readonly string Version = $"{AssemblyVersion} ({InformationalVersion})"; + + /// <summary> + /// Gets a value indicating whether the current version is a Canary build. + /// </summary> + public static readonly bool IsCanary = AssemblyVersion.Revision == 65534; /// <summary> /// Gets the unique Id of this application invocation. /// </summary> - public static Guid InvocationId { get; } = Guid.NewGuid(); + public static readonly Guid InvocationId = Guid.NewGuid(); /// <summary> /// Gets the Id of the current application process. /// </summary> - public static int ProcessId { get; } = Environment.ProcessId; + public static readonly int ProcessId = Environment.ProcessId; /// <summary> - /// Gets the full application version, including both assembly and informational versions. + /// Occurs when a new log event is emitted. /// </summary> - public static string Version { get; } = $"{AssemblyVersion} ({InformationalVersion})"; + public static event EventHandler<LogRecord> LogEmitted; /// <summary> - /// Gets a value indicating whether the current version is a Canary build. + /// Gets the path where application data is saved. + /// </summary> + [Argument(default, "app", "path where application data is saved")] + [EnvironmentVariable("APP_DIR")] + public static string AppDirectory { get; private set; } = DefaultAppDirectory; + + /// <summary> + /// Gets the default downloads directory. /// </summary> - public static bool IsCanary { get; } = AssemblyVersion.Revision == 65534; + public static string DefaultDownloadsDirectory => Path.Combine(AppDirectory, "downloads"); + + /// <summary> + /// Gets the default incomplete download directory. + /// </summary> + public static string DefaultIncompleteDirectory => Path.Combine(AppDirectory, "incomplete"); /// <summary> /// Gets a buffer containing the last few log events. @@ -140,7 +140,6 @@ namespace slskd private static string ConfigurationFile => Path.Combine(AppDirectory, $"{AppName}.yml"); private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup(); - [Argument('g', "generate-cert", "generate X509 certificate and password for HTTPs")] private static bool GenerateCertificate { get; set; } @@ -241,18 +240,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(AppDirectory, exampleFileName); - File.Copy(source, destination); - } - catch + // for convenience, try to copy the example configuration file to the application directory if no configuration + // file exists. if any part fails, just move on silently. + if (!IOFile.Exists(ConfigurationFile)) { - // no-op + try + { + var source = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.example.yml"); + var destination = ConfigurationFile; + IOFile.Copy(source, destination); + } + catch + { + // no-op + } } Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information()) |
