diff --git a/osu-framework b/osu-framework index 383a8da7bc..26f3091dca 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 383a8da7bc45af498288b4b72c72a048a0996e74 +Subproject commit 26f3091dcaf47e3b355b7f7ad83b292621d7d6b5 diff --git a/osu.Desktop.Deploy/Program.cs b/osu.Desktop.Deploy/Program.cs index 785f915a3e..385bc444d1 100644 --- a/osu.Desktop.Deploy/Program.cs +++ b/osu.Desktop.Deploy/Program.cs @@ -7,7 +7,6 @@ using System.Configuration; using System.Diagnostics; using System.IO; using System.Linq; -using System.Net; using Newtonsoft.Json; using osu.Framework.IO.Network; using FileWebRequest = osu.Framework.IO.Network.FileWebRequest; @@ -391,8 +390,8 @@ namespace osu.Desktop.Deploy public static void AuthenticatedBlockingPerform(this WebRequest r) { - r.AddHeader("Authorization", $"token {GitHubAccessToken}"); - r.BlockingPerform(); + r.Headers.Add("Authorization", $"token {GitHubAccessToken}"); + r.Perform(); } } @@ -402,12 +401,7 @@ namespace osu.Desktop.Deploy { } - protected override HttpWebRequest CreateWebRequest(string requestString = null) - { - var req = base.CreateWebRequest(requestString); - req.Accept = "application/octet-stream"; - return req; - } + protected override string Accept => "application/octet-stream"; } internal class ReleaseLine diff --git a/osu.Desktop/app.config b/osu.Desktop/app.config index 0841541f3d..ea1576b3d8 100644 --- a/osu.Desktop/app.config +++ b/osu.Desktop/app.config @@ -12,8 +12,32 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index ab64fa7ede..91c0da6f65 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -133,30 +133,42 @@ - ..\packages\squirrel.windows.1.7.8\lib\Net45\NuGet.Squirrel.dll + $(SolutionDir)\packages\squirrel.windows.1.7.8\lib\Net45\NuGet.Squirrel.dll True - ..\packages\OpenTK.3.0.0-git00009\lib\net20\OpenTK.dll + $(SolutionDir)\packages\OpenTK.3.0.0-git00009\lib\net20\OpenTK.dll True - ..\packages\SharpCompress.0.18.1\lib\net45\SharpCompress.dll + $(SolutionDir)\packages\SharpCompress.0.18.1\lib\net45\SharpCompress.dll True $(SolutionDir)\packages\Splat.2.0.0\lib\Net45\Splat.dll True + + $(SolutionDir)\packages\SQLitePCLRaw.bundle_green.1.1.8\lib\net45\SQLitePCLRaw.batteries_green.dll + + + $(SolutionDir)\packages\SQLitePCLRaw.bundle_green.1.1.8\lib\net45\SQLitePCLRaw.batteries_v2.dll + + + $(SolutionDir)\packages\SQLitePCLRaw.core.1.1.8\lib\net45\SQLitePCLRaw.core.dll + + + $(SolutionDir)\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.1.8\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll + - ..\packages\squirrel.windows.1.7.8\lib\Net45\Squirrel.dll + $(SolutionDir)\packages\squirrel.windows.1.7.8\lib\Net45\Squirrel.dll True - ../packages/System.ValueTuple.4.4.0/lib/net461/System.ValueTuple.dll + $(SolutionDir)\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll True @@ -262,4 +274,15 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/osu.Desktop/packages.config b/osu.Desktop/packages.config index 80eb533644..6b6361b578 100644 --- a/osu.Desktop/packages.config +++ b/osu.Desktop/packages.config @@ -1,14 +1,20 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index b99e2808ce..77a1688730 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -20,7 +20,7 @@ namespace osu.Game.Tests.Beatmaps.IO { private const string osz_path = @"../../../osu-resources/osu.Game.Resources/Beatmaps/241526 Soleily - Renatus.osz"; - //[Test] + [Test] public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. @@ -40,14 +40,16 @@ namespace osu.Game.Tests.Beatmaps.IO } } - //[Test] + [Test] + [NonParallelizable] + [Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")] public void TestImportOverIPC() { using (HeadlessGameHost host = new HeadlessGameHost("host", true)) using (HeadlessGameHost client = new HeadlessGameHost("client", true)) { Assert.IsTrue(host.IsPrimaryInstance); - Assert.IsTrue(!client.IsPrimaryInstance); + Assert.IsFalse(client.IsPrimaryInstance); var osu = loadOsu(host); @@ -65,7 +67,7 @@ namespace osu.Game.Tests.Beatmaps.IO } } - //[Test] + [Test] public void TestImportWhenFileOpen() { using (HeadlessGameHost host = new HeadlessGameHost("TestImportWhenFileOpen")) @@ -100,6 +102,10 @@ namespace osu.Game.Tests.Beatmaps.IO waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time"); + // this is a temporary workaround for database transaction clashes. + // see https://github.com/aspnet/EntityFrameworkCore/issues/9994 for more information. + Thread.Sleep(1000); + return osu; } diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 47dbc72837..55c3e192e3 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -184,7 +184,7 @@ namespace osu.Game.Beatmaps { var context = importContext.Value; - using (var transaction = context.Database.BeginTransaction()) + using (var transaction = context.BeginTransaction()) { // create local stores so we can isolate and thread safely, and share a context/transaction. var iFiles = new FileStore(() => context, storage); @@ -198,7 +198,7 @@ namespace osu.Game.Beatmaps context.SaveChanges(); } - transaction.Commit(); + context.SaveChanges(transaction); return set; } } @@ -295,7 +295,7 @@ namespace osu.Game.Beatmaps { var context = importContext.Value; - using (var transaction = context.Database.BeginTransaction()) + using (var transaction = context.BeginTransaction()) { context.ChangeTracker.AutoDetectChangesEnabled = false; @@ -313,9 +313,7 @@ namespace osu.Game.Beatmaps } context.ChangeTracker.AutoDetectChangesEnabled = true; - context.SaveChanges(); - - transaction.Commit(); + context.SaveChanges(transaction); } } } diff --git a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs index 42db025a40..1aff764ede 100644 --- a/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs +++ b/osu.Game/Beatmaps/Drawables/DifficultyIcon.cs @@ -35,7 +35,8 @@ namespace osu.Game.Beatmaps.Drawables new ConstrainedIconContainer { RelativeSizeAxes = Axes.Both, - Icon = beatmap.Ruleset.CreateInstance().CreateIcon() + // the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment) + Icon = beatmap.Ruleset?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.fa_question_circle_o } } }; } diff --git a/osu.Game/Database/DatabaseBackedStore.cs b/osu.Game/Database/DatabaseBackedStore.cs index be86d35335..68f412eee6 100644 --- a/osu.Game/Database/DatabaseBackedStore.cs +++ b/osu.Game/Database/DatabaseBackedStore.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Threading; using osu.Framework.Logging; using osu.Framework.Platform; @@ -11,12 +12,26 @@ namespace osu.Game.Database { protected readonly Storage Storage; - protected readonly Func GetContext; + /// + /// Create a new instance (separate from the shared context via for performing isolated operations. + /// + protected readonly Func CreateContext; - protected DatabaseBackedStore(Func getContext, Storage storage = null) + private readonly ThreadLocal queryContext; + + /// + /// Retrieve a shared context for performing lookups (or write operations on the update thread, for now). + /// + protected OsuDbContext GetContext() => queryContext.Value; + + protected DatabaseBackedStore(Func createContext, Storage storage = null) { + CreateContext = createContext; + + // todo: while this seems to work quite well, we need to consider that contexts could enter a state where they are never cleaned up. + queryContext = new ThreadLocal(CreateContext); + Storage = storage; - GetContext = getContext; try { diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index 7824cf9712..2187274c18 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -3,6 +3,7 @@ using System; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; using osu.Framework.Logging; @@ -23,6 +24,7 @@ namespace osu.Game.Database public DbSet DatabasedKeyBinding { get; set; } public DbSet FileInfo { get; set; } public DbSet RulesetInfo { get; set; } + private readonly string connectionString; private static readonly Lazy logger = new Lazy(() => new OsuDbLoggerFactory()); @@ -52,8 +54,6 @@ namespace osu.Game.Database { this.connectionString = connectionString; - Database.SetCommandTimeout(new TimeSpan(TimeSpan.TicksPerSecond * 10)); - var connection = Database.GetDbConnection(); connection.Open(); using (var cmd = connection.CreateCommand()) @@ -70,7 +70,7 @@ namespace osu.Game.Database // this is required for the time being due to the way we are querying in places like BeatmapStore. // if we ever move to having consumers file their own .Includes, or get eager loading support, this could be re-enabled. .ConfigureWarnings(warnings => warnings.Ignore(CoreEventId.IncludeIgnoredWarning)) - .UseSqlite(connectionString) + .UseSqlite(connectionString, sqliteOptions => sqliteOptions.CommandTimeout(10)) .UseLoggerFactory(logger.Value); } @@ -95,6 +95,19 @@ namespace osu.Game.Database modelBuilder.Entity().HasOne(b => b.BaseDifficulty); } + public IDbContextTransaction BeginTransaction() + { + // return Database.BeginTransaction(); + return null; + } + + public new int SaveChanges(IDbContextTransaction transaction = null) + { + var ret = base.SaveChanges(); + transaction?.Commit(); + return ret; + } + private class OsuDbLoggerFactory : ILoggerFactory { #region Disposal @@ -153,7 +166,7 @@ namespace osu.Game.Database public bool IsEnabled(LogLevel logLevel) { -#if DEBUG +#if DEBUG_DATABASE return logLevel > LogLevel.Debug; #else return logLevel > LogLevel.Information; diff --git a/osu.Game/IO/FileStore.cs b/osu.Game/IO/FileStore.cs index 6654fa7cb1..b69916e565 100644 --- a/osu.Game/IO/FileStore.cs +++ b/osu.Game/IO/FileStore.cs @@ -22,7 +22,7 @@ namespace osu.Game.IO public Storage Storage => base.Storage; - public FileStore(Func getContext, Storage storage) : base(getContext, storage.GetStorageForDirectory(@"files")) + public FileStore(Func createContext, Storage storage) : base(createContext, storage.GetStorageForDirectory(@"files")) { Store = new StorageBackedResourceStore(Storage); } diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 07c0319f2f..1e1b1d74d4 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -17,8 +17,8 @@ namespace osu.Game.Input { public event Action KeyBindingChanged; - public KeyBindingStore(Func getContext, RulesetStore rulesets, Storage storage = null) - : base(getContext, storage) + public KeyBindingStore(Func createContext, RulesetStore rulesets, Storage storage = null) + : base(createContext, storage) { foreach (var info in rulesets.AvailableRulesets) { @@ -38,13 +38,14 @@ namespace osu.Game.Input private void insertDefaults(IEnumerable defaults, int? rulesetId = null, int? variant = null) { - using (var context = GetContext()) - using (var transaction = context.Database.BeginTransaction()) + var context = GetContext(); + + using (var transaction = context.BeginTransaction()) { // compare counts in database vs defaults foreach (var group in defaults.GroupBy(k => k.Action)) { - int count = query(context, rulesetId, variant).Count(k => (int)k.Action == (int)group.Key); + int count = Query(rulesetId, variant).Count(k => (int)k.Action == (int)group.Key); int aimCount = group.Count(); if (aimCount <= count) @@ -61,8 +62,7 @@ namespace osu.Game.Input }); } - context.SaveChanges(); - transaction.Commit(); + context.SaveChanges(transaction); } } @@ -72,10 +72,8 @@ namespace osu.Game.Input /// The ruleset's internal ID. /// An optional variant. /// - public IEnumerable Query(int? rulesetId = null, int? variant = null) => query(GetContext(), rulesetId, variant); - - private IEnumerable query(OsuDbContext context, int? rulesetId = null, int? variant = null) => - context.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant); + public IEnumerable Query(int? rulesetId = null, int? variant = null) => + GetContext().DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant); public void Update(KeyBinding keyBinding) { diff --git a/osu.Game/Online/API/APIRequest.cs b/osu.Game/Online/API/APIRequest.cs index 37903f924f..9a8180778d 100644 --- a/osu.Game/Online/API/APIRequest.cs +++ b/osu.Game/Online/API/APIRequest.cs @@ -106,7 +106,7 @@ namespace osu.Game.Online.API return; if (!WebRequest.Aborted) //could have been aborted by a Cancel() call - WebRequest.BlockingPerform(); + WebRequest.Perform(); if (checkAndProcessFailure()) return; diff --git a/osu.Game/Online/API/OAuth.cs b/osu.Game/Online/API/OAuth.cs index 5410bcc55d..445688f2ce 100644 --- a/osu.Game/Online/API/OAuth.cs +++ b/osu.Game/Online/API/OAuth.cs @@ -37,7 +37,7 @@ namespace osu.Game.Online.API { try { - req.BlockingPerform(); + req.Perform(); } catch { @@ -61,7 +61,7 @@ namespace osu.Game.Online.API ClientSecret = clientSecret }) { - req.BlockingPerform(); + req.Perform(); Token = req.ResponseObject; return true; diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 233ca7be60..cea070102d 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance restoreButton.Enabled.Value = false; Task.Run(() => { - foreach (var b in beatmaps.QueryBeatmaps(b => b.Hidden)) + foreach (var b in beatmaps.QueryBeatmaps(b => b.Hidden).ToList()) beatmaps.Restore(b); }).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true)); } diff --git a/osu.Game/Tests/Visual/OsuTestCase.cs b/osu.Game/Tests/Visual/OsuTestCase.cs index ca0aaebb5e..b2c8be47bd 100644 --- a/osu.Game/Tests/Visual/OsuTestCase.cs +++ b/osu.Game/Tests/Visual/OsuTestCase.cs @@ -13,11 +13,9 @@ namespace osu.Game.Tests.Visual { using (var host = new HeadlessGameHost($"test-{Guid.NewGuid()}", realtime: false)) { + host.Storage.DeleteDirectory(string.Empty); host.Run(new OsuTestCaseTestRunner(this)); } - - // clean up after each run - //storage.DeleteDirectory(string.Empty); } public class OsuTestCaseTestRunner : OsuGameBase