aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 541f0f00..371f60bd 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -45,7 +45,6 @@ namespace slskd
using Microsoft.Extensions.FileProviders.Physical;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
- using Prometheus;
using Prometheus.DotNetRuntime;
using Prometheus.SystemMetrics;
using Serilog;
@@ -161,6 +160,16 @@ namespace slskd
public static string ConfigurationFile { get; private set; } = null;
/// <summary>
+ /// Gets the connection strings for application databases.
+ /// </summary>
+ public static ConnectionStrings ConnectionStrings { get; private set; } = null;
+
+ /// <summary>
+ /// Gets the path where persistent data is saved.
+ /// </summary>
+ public static string DataDirectory { get; private set; } = null;
+
+ /// <summary>
/// Gets the default fully qualified path to the configuration file.
/// </summary>
public static string DefaultConfigurationFile { get; private set; }
@@ -247,6 +256,15 @@ namespace slskd
// and defaults that are dependent upon it
AppDirectory ??= DefaultAppDirectory;
+ DataDirectory = Path.Combine(AppDirectory, "data");
+
+ ConnectionStrings = new()
+ {
+ Search = $"Data Source={Path.Combine(DataDirectory, "search.db")};Cache=shared;Pooling=True;",
+ Transfers = $"Data Source={Path.Combine(DataDirectory, "transfers.db")};Cache=shared;Pooling=True;",
+ Shares = $"Data Source={Path.Combine(DataDirectory, "shares.db")};Cache=shared",
+ };
+
DefaultConfigurationFile = Path.Combine(AppDirectory, $"{AppName}.yml");
DefaultDownloadsDirectory = Path.Combine(AppDirectory, "downloads");
DefaultIncompleteDirectory = Path.Combine(AppDirectory, "incomplete");
@@ -260,7 +278,7 @@ namespace slskd
try
{
VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true);
- VerifyDirectory(Path.Combine(AppDirectory, "data"), createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(DataDirectory, createIfMissing: true, verifyWriteable: true);
VerifyDirectory(DefaultDownloadsDirectory, createIfMissing: true, verifyWriteable: true);
VerifyDirectory(DefaultIncompleteDirectory, createIfMissing: true, verifyWriteable: true);
}
@@ -449,8 +467,8 @@ namespace slskd
ConfigureSQLite();
- services.AddDbContext<SearchDbContext>("search.db");
- services.AddDbContext<TransfersDbContext>("transfers.db");
+ services.AddDbContext<SearchDbContext>(ConnectionStrings.Search);
+ services.AddDbContext<TransfersDbContext>(ConnectionStrings.Transfers);
services.AddSingleton<IBrowseTracker, BrowseTracker>();
services.AddSingleton<IConversationTracker, ConversationTracker>();
@@ -512,7 +530,7 @@ namespace slskd
using var runtimeMetrics = DotNetRuntimeStatsBuilder.Default().StartCollecting();
services.AddDataProtection()
- .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(AppDirectory, "data", ".DataProtection-Keys")));
+ .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(DataDirectory, ".DataProtection-Keys")));
var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(OptionsAtStartup.Web.Authentication.Jwt.Key));
@@ -838,7 +856,7 @@ namespace slskd
commandLine: Environment.CommandLine);
}
- private static IServiceCollection AddDbContext<T>(this IServiceCollection services, string filename)
+ private static IServiceCollection AddDbContext<T>(this IServiceCollection services, string connectionString)
where T : DbContext
{
Log.Debug("Initializing database context {Name}", typeof(T).Name);
@@ -847,7 +865,7 @@ namespace slskd
{
services.AddDbContextFactory<T>(options =>
{
- options.UseSqlite($"Data Source={Path.Combine(AppDirectory, "data", filename)};Cache=shared;Pooling=True;");
+ options.UseSqlite(connectionString);
if (OptionsAtStartup.Debug && OptionsAtStartup.Flags.LogSQL)
{