Move database connection string operations local

In line with framework changes in
https://github.com/ppy/osu-framework/pull/4793.
This commit is contained in:
Dean Herbert 2021-09-27 17:32:40 +09:00
parent 7f45bd27f2
commit d4310f5d9a
3 changed files with 7 additions and 9 deletions

View File

@ -13,6 +13,7 @@ using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using SharpCompress.Compressors;
@ -160,7 +161,7 @@ namespace osu.Game.Beatmaps
try
{
using (var db = new SqliteConnection(storage.GetDatabaseConnectionString("online")))
using (var db = new SqliteConnection(DatabaseContextFactory.CreateDatabaseConnectionString("online.db", storage)))
{
db.Open();

View File

@ -13,7 +13,7 @@ namespace osu.Game.Database
{
private readonly Storage storage;
private const string database_name = @"client";
private const string database_name = @"client.db";
private ThreadLocal<OsuDbContext> threadContexts;
@ -139,7 +139,7 @@ namespace osu.Game.Database
threadContexts = new ThreadLocal<OsuDbContext>(CreateContext, true);
}
protected virtual OsuDbContext CreateContext() => new OsuDbContext(storage.GetDatabaseConnectionString(database_name))
protected virtual OsuDbContext CreateContext() => new OsuDbContext(CreateDatabaseConnectionString(database_name, storage))
{
Database = { AutoTransactionsEnabled = false }
};
@ -152,7 +152,7 @@ namespace osu.Game.Database
try
{
storage.DeleteDatabase(database_name);
storage.Delete(database_name);
}
catch
{
@ -171,5 +171,7 @@ namespace osu.Game.Database
recycleThreadContexts();
}
public static string CreateDatabaseConnectionString(string filename, Storage storage) => string.Concat("Data Source=", storage.GetFullPath($@"{filename}", true));
}
}

View File

@ -70,11 +70,6 @@ namespace osu.Game.IO
public override Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate) =>
UnderlyingStorage.GetStream(MutatePath(path), access, mode);
public override string GetDatabaseConnectionString(string name) =>
UnderlyingStorage.GetDatabaseConnectionString(MutatePath(name));
public override void DeleteDatabase(string name) => UnderlyingStorage.DeleteDatabase(MutatePath(name));
public override void OpenPathInNativeExplorer(string path) => UnderlyingStorage.OpenPathInNativeExplorer(MutatePath(path));
public override Storage GetStorageForDirectory(string path)