2022-06-15 03:31:26 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2023-08-16 22:49:48 +00:00
|
|
|
|
using System;
|
2022-06-15 03:31:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2023-08-18 09:00:33 +00:00
|
|
|
|
using System.IO.Compression;
|
2022-06-15 03:31:26 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Framework.Testing;
|
2023-08-16 22:49:48 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2022-06-15 03:31:26 +00:00
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
using osu.Game.IO;
|
2024-03-29 09:32:20 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2023-08-16 22:49:48 +00:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2022-06-15 03:31:26 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Database
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-08-16 22:49:48 +00:00
|
|
|
|
public class LegacyBeatmapImporterTest : RealmTest
|
2022-06-15 03:31:26 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly TestLegacyBeatmapImporter importer = new TestLegacyBeatmapImporter();
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSongsSubdirectories()
|
|
|
|
|
{
|
|
|
|
|
using (var storage = new TemporaryNativeStorage("stable-songs-folder"))
|
|
|
|
|
{
|
|
|
|
|
var songsStorage = storage.GetStorageForDirectory(StableStorage.STABLE_DEFAULT_SONGS_PATH);
|
|
|
|
|
|
|
|
|
|
// normal beatmap folder
|
|
|
|
|
var beatmap1 = songsStorage.GetStorageForDirectory("beatmap1");
|
2022-06-15 05:24:18 +00:00
|
|
|
|
createFile(beatmap1, "beatmap.osu");
|
2022-06-15 03:31:26 +00:00
|
|
|
|
|
|
|
|
|
// songs subdirectory
|
|
|
|
|
var subdirectory = songsStorage.GetStorageForDirectory("subdirectory");
|
2022-06-15 05:24:18 +00:00
|
|
|
|
createFile(subdirectory, Path.Combine("beatmap2", "beatmap.osu"));
|
|
|
|
|
createFile(subdirectory, Path.Combine("beatmap3", "beatmap.osu"));
|
|
|
|
|
createFile(subdirectory, Path.Combine("sub-subdirectory", "beatmap4", "beatmap.osu"));
|
2022-06-15 03:31:26 +00:00
|
|
|
|
|
|
|
|
|
// songs subdirectory with system file
|
|
|
|
|
var subdirectory2 = songsStorage.GetStorageForDirectory("subdirectory2");
|
2022-06-15 05:24:18 +00:00
|
|
|
|
createFile(subdirectory2, ".DS_Store");
|
|
|
|
|
createFile(subdirectory2, Path.Combine("beatmap5", "beatmap.osu"));
|
|
|
|
|
createFile(subdirectory2, Path.Combine("beatmap6", "beatmap.osu"));
|
2022-06-15 03:31:26 +00:00
|
|
|
|
|
2023-10-03 07:01:15 +00:00
|
|
|
|
// songs subdirectory with random file
|
|
|
|
|
var subdirectory3 = songsStorage.GetStorageForDirectory("subdirectory3");
|
|
|
|
|
createFile(subdirectory3, "silly readme.txt");
|
|
|
|
|
createFile(subdirectory3, Path.Combine("beatmap7", "beatmap.osu"));
|
|
|
|
|
|
2022-06-15 03:31:26 +00:00
|
|
|
|
// empty songs subdirectory
|
|
|
|
|
songsStorage.GetStorageForDirectory("subdirectory3");
|
|
|
|
|
|
|
|
|
|
string[] paths = importer.GetStableImportPaths(songsStorage).ToArray();
|
2023-10-03 07:01:15 +00:00
|
|
|
|
Assert.That(paths.Length, Is.EqualTo(7));
|
2022-06-15 03:31:26 +00:00
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath("beatmap1")));
|
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "beatmap2"))));
|
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "beatmap3"))));
|
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "sub-subdirectory", "beatmap4"))));
|
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory2", "beatmap5"))));
|
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory2", "beatmap6"))));
|
2023-10-03 07:01:15 +00:00
|
|
|
|
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory3", "beatmap7"))));
|
2022-06-15 03:31:26 +00:00
|
|
|
|
}
|
2022-06-15 05:24:18 +00:00
|
|
|
|
|
|
|
|
|
static void createFile(Storage storage, string path)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = storage.CreateFileSafely(path))
|
|
|
|
|
stream.WriteByte(0);
|
|
|
|
|
}
|
2022-06-15 03:31:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 22:49:48 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestStableDateAddedApplied()
|
|
|
|
|
{
|
|
|
|
|
RunTestWithRealmAsync(async (realm, storage) =>
|
|
|
|
|
{
|
|
|
|
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
|
|
|
|
using (var tmpStorage = new TemporaryNativeStorage("stable-songs-folder"))
|
2024-03-29 09:32:20 +00:00
|
|
|
|
using (new RealmRulesetStore(realm, storage))
|
2023-08-16 22:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
var stableStorage = new StableStorage(tmpStorage.GetFullPath(""), host);
|
|
|
|
|
var songsStorage = stableStorage.GetStorageForDirectory(StableStorage.STABLE_DEFAULT_SONGS_PATH);
|
|
|
|
|
|
2023-08-18 09:00:33 +00:00
|
|
|
|
ZipFile.ExtractToDirectory(TestResources.GetQuickTestBeatmapForImport(), songsStorage.GetFullPath("renatus"));
|
2023-08-16 22:49:48 +00:00
|
|
|
|
|
|
|
|
|
string[] beatmaps = Directory.GetFiles(songsStorage.GetFullPath("renatus"), "*.osu", SearchOption.TopDirectoryOnly);
|
|
|
|
|
|
|
|
|
|
File.SetLastWriteTimeUtc(beatmaps[beatmaps.Length / 2], new DateTime(2000, 1, 1, 12, 0, 0));
|
|
|
|
|
|
|
|
|
|
await new LegacyBeatmapImporter(new BeatmapImporter(storage, realm)).ImportFromStableAsync(stableStorage);
|
|
|
|
|
|
2023-08-18 09:00:33 +00:00
|
|
|
|
var importedSet = realm.Realm.All<BeatmapSetInfo>().Single();
|
2023-08-16 22:49:48 +00:00
|
|
|
|
|
2023-08-18 09:00:33 +00:00
|
|
|
|
Assert.NotNull(importedSet);
|
|
|
|
|
Assert.AreEqual(new DateTimeOffset(new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)), importedSet.DateAdded);
|
2023-08-16 22:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 03:31:26 +00:00
|
|
|
|
private class TestLegacyBeatmapImporter : LegacyBeatmapImporter
|
|
|
|
|
{
|
|
|
|
|
public TestLegacyBeatmapImporter()
|
2022-11-18 06:46:50 +00:00
|
|
|
|
: base(null!)
|
2022-06-15 03:31:26 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new IEnumerable<string> GetStableImportPaths(Storage storage) => base.GetStableImportPaths(storage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|