From 975883da5c4ce921ee48319ee000c4f901f6a3c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Mar 2022 13:34:48 +0900 Subject: [PATCH] Move all usages of `client.realm` filename to a single `const` --- osu.Game.Benchmarks/BenchmarkRealmReads.cs | 2 +- osu.Game.Tests/Database/RealmTest.cs | 4 ++-- .../NonVisual/CustomDataDirectoryTest.cs | 20 ++++++++----------- osu.Game/Database/RealmAccess.cs | 2 +- osu.Game/IO/OsuStorage.cs | 6 +++--- osu.Game/OsuGameBase.cs | 7 ++++++- .../Maintenance/MigrationSelectScreen.cs | 2 +- osu.Game/Tests/Visual/OsuTestScene.cs | 2 +- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/osu.Game.Benchmarks/BenchmarkRealmReads.cs b/osu.Game.Benchmarks/BenchmarkRealmReads.cs index bf9467700c..615e2e964d 100644 --- a/osu.Game.Benchmarks/BenchmarkRealmReads.cs +++ b/osu.Game.Benchmarks/BenchmarkRealmReads.cs @@ -27,7 +27,7 @@ namespace osu.Game.Benchmarks storage = new TemporaryNativeStorage("realm-benchmark"); storage.DeleteDirectory(string.Empty); - realm = new RealmAccess(storage, "client"); + realm = new RealmAccess(storage, OsuGameBase.CLIENT_DATABASE_FILENAME); realm.Run(r => { diff --git a/osu.Game.Tests/Database/RealmTest.cs b/osu.Game.Tests/Database/RealmTest.cs index 838759c991..16072888b9 100644 --- a/osu.Game.Tests/Database/RealmTest.cs +++ b/osu.Game.Tests/Database/RealmTest.cs @@ -39,7 +39,7 @@ namespace osu.Game.Tests.Database // ReSharper disable once AccessToDisposedClosure var testStorage = new OsuStorage(host, storage.GetStorageForDirectory(caller)); - using (var realm = new RealmAccess(testStorage, "client")) + using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME)) { Logger.Log($"Running test using realm file {testStorage.GetFullPath(realm.Filename)}"); testAction(realm, testStorage); @@ -62,7 +62,7 @@ namespace osu.Game.Tests.Database { var testStorage = storage.GetStorageForDirectory(caller); - using (var realm = new RealmAccess(testStorage, "client")) + using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME)) { Logger.Log($"Running test using realm file {testStorage.GetFullPath(realm.Filename)}"); await testAction(realm, testStorage); diff --git a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs index b5ab33b9fc..fd5691a9f4 100644 --- a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs +++ b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs @@ -143,14 +143,14 @@ namespace osu.Game.Tests.NonVisual Assert.That(osuStorage, Is.Not.Null); // In the following tests, realm files are ignored as - // - in the case of checking the source, interacting with the pipe files (client.realm.note) may + // - in the case of checking the source, interacting with the pipe files (.realm.note) may // lead to unexpected behaviour. // - in the case of checking the destination, the files may have already been recreated by the game // as part of the standard migration flow. foreach (string file in osuStorage.IgnoreFiles) { - if (!file.Contains("realm", StringComparison.Ordinal)) + if (!file.Contains(".realm", StringComparison.Ordinal)) { Assert.That(File.Exists(Path.Combine(originalDirectory, file))); Assert.That(storage.Exists(file), Is.False, () => $"{file} exists in destination when it was expected to be ignored"); @@ -159,7 +159,7 @@ namespace osu.Game.Tests.NonVisual foreach (string dir in osuStorage.IgnoreDirectories) { - if (!dir.Contains("realm", StringComparison.Ordinal)) + if (!dir.Contains(".realm", StringComparison.Ordinal)) { Assert.That(Directory.Exists(Path.Combine(originalDirectory, dir))); Assert.That(storage.Exists(dir), Is.False, () => $"{dir} exists in destination when it was expected to be ignored"); @@ -188,19 +188,17 @@ namespace osu.Game.Tests.NonVisual { var osu = LoadOsuIntoHost(host); - const string database_filename = "client.realm"; - Assert.DoesNotThrow(() => osu.Migrate(customPath)); - Assert.That(File.Exists(Path.Combine(customPath, database_filename))); + Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME))); Assert.DoesNotThrow(() => osu.Migrate(customPath2)); - Assert.That(File.Exists(Path.Combine(customPath2, database_filename))); + Assert.That(File.Exists(Path.Combine(customPath2, OsuGameBase.CLIENT_DATABASE_FILENAME))); // some files may have been left behind for whatever reason, but that's not what we're testing here. cleanupPath(customPath); Assert.DoesNotThrow(() => osu.Migrate(customPath)); - Assert.That(File.Exists(Path.Combine(customPath, database_filename))); + Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME))); } finally { @@ -250,13 +248,11 @@ namespace osu.Game.Tests.NonVisual string originalDirectory = storage.GetFullPath("."); - const string database_filename = "client.realm"; - Assert.DoesNotThrow(() => osu.Migrate(customPath)); - Assert.That(File.Exists(Path.Combine(customPath, database_filename))); + Assert.That(File.Exists(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME))); Directory.CreateDirectory(customPath2); - File.Copy(Path.Combine(customPath, database_filename), Path.Combine(customPath2, database_filename)); + File.Copy(Path.Combine(customPath, OsuGameBase.CLIENT_DATABASE_FILENAME), Path.Combine(customPath2, OsuGameBase.CLIENT_DATABASE_FILENAME)); // Fails because file already exists. Assert.Throws(() => osu.Migrate(customPath2)); diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 8dbb338980..b0a70b51d0 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -212,7 +212,7 @@ namespace osu.Game.Database if (realm.All().Any()) { Logger.Log(@"Recovery aborted as the existing database has scores set already.", LoggingTarget.Database); - Logger.Log(@"To perform recovery, delete client.realm while osu! is not running.", LoggingTarget.Database); + Logger.Log($@"To perform recovery, delete {OsuGameBase.CLIENT_DATABASE_FILENAME} while osu! is not running.", LoggingTarget.Database); return; } } diff --git a/osu.Game/IO/OsuStorage.cs b/osu.Game/IO/OsuStorage.cs index a3f7b4bfec..c49365a9de 100644 --- a/osu.Game/IO/OsuStorage.cs +++ b/osu.Game/IO/OsuStorage.cs @@ -36,15 +36,15 @@ namespace osu.Game.IO public override string[] IgnoreDirectories => new[] { "cache", - "client.realm.management" + $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.management", }; public override string[] IgnoreFiles => new[] { "framework.ini", "storage.ini", - "client.realm.note", - "client.realm.lock", + $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.note", + $"{OsuGameBase.CLIENT_DATABASE_FILENAME}.lock", }; public OsuStorage(GameHost host, Storage defaultStorage) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 7b9aca4086..324fcada89 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -57,6 +57,11 @@ namespace osu.Game public const string CLIENT_STREAM_NAME = @"lazer"; + /// + /// The filename of the main client database. + /// + public const string CLIENT_DATABASE_FILENAME = @"client.realm"; + public const int SAMPLE_CONCURRENCY = 6; /// @@ -200,7 +205,7 @@ namespace osu.Game if (Storage.Exists(DatabaseContextFactory.DATABASE_NAME)) dependencies.Cache(EFContextFactory = new DatabaseContextFactory(Storage)); - dependencies.Cache(realm = new RealmAccess(Storage, "client", Host.UpdateThread, EFContextFactory)); + dependencies.Cache(realm = new RealmAccess(Storage, CLIENT_DATABASE_FILENAME, Host.UpdateThread, EFContextFactory)); dependencies.CacheAs(RulesetStore = new RealmRulesetStore(realm, Storage)); dependencies.CacheAs(RulesetStore); diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs index 047587e084..0304a4291a 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs @@ -47,7 +47,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance if (directoryInfos.Length > 0 || fileInfos.Length > 0) { // Quick test for whether there's already an osu! install at the target path. - if (fileInfos.Any(f => f.Name == @"client.realm")) + if (fileInfos.Any(f => f.Name == OsuGameBase.CLIENT_DATABASE_FILENAME)) { dialogOverlay.Push(new ConfirmDialog("The target directory already seems to have an osu! install. Use that data instead?", () => { diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 6c332c2408..f2d280417e 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -121,7 +121,7 @@ namespace osu.Game.Tests.Visual Resources = parent.Get().Resources; - realm = new Lazy(() => new RealmAccess(LocalStorage, "client", host.UpdateThread)); + realm = new Lazy(() => new RealmAccess(LocalStorage, OsuGameBase.CLIENT_DATABASE_FILENAME, host.UpdateThread)); RecycleLocalStorage(false);