1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 12:02:54 +08:00

Merge pull request #14859 from peppy/local-database-strings

Move database connection string operations local
This commit is contained in:
Dean Herbert 2021-09-27 21:46:52 +09:00 committed by GitHub
commit dc24fd7e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 13 deletions

View File

@ -52,7 +52,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.918.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.924.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.927.0" />
</ItemGroup>
<ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->

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)

View File

@ -36,7 +36,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Realm" Version="10.5.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.924.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.927.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.918.0" />
<PackageReference Include="Sentry" Version="3.9.0" />
<PackageReference Include="SharpCompress" Version="0.29.0" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.924.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.927.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.918.0" />
</ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2021.924.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.927.0" />
<PackageReference Include="SharpCompress" Version="0.28.3" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="SharpRaven" Version="2.4.0" />