1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 19:22:56 +08:00

Merge pull request #24998 from peppy/better-nested-path-beatmap-import

Fix legacy beatmap importer not always handling nested paths correctly
This commit is contained in:
Bartłomiej Dach 2023-10-03 09:43:02 +02:00 committed by GitHub
commit 5338ba98f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -44,17 +44,23 @@ namespace osu.Game.Tests.Database
createFile(subdirectory2, Path.Combine("beatmap5", "beatmap.osu"));
createFile(subdirectory2, Path.Combine("beatmap6", "beatmap.osu"));
// songs subdirectory with random file
var subdirectory3 = songsStorage.GetStorageForDirectory("subdirectory3");
createFile(subdirectory3, "silly readme.txt");
createFile(subdirectory3, Path.Combine("beatmap7", "beatmap.osu"));
// empty songs subdirectory
songsStorage.GetStorageForDirectory("subdirectory3");
string[] paths = importer.GetStableImportPaths(songsStorage).ToArray();
Assert.That(paths.Length, Is.EqualTo(6));
Assert.That(paths.Length, Is.EqualTo(7));
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"))));
Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory3", "beatmap7"))));
}
static void createFile(Storage storage, string path)

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
@ -34,9 +33,9 @@ namespace osu.Game.Database
try
{
if (!directoryStorage.GetFiles(string.Empty).ExcludeSystemFileNames().Any())
if (!directoryStorage.GetFiles(string.Empty, "*.osu").Any())
{
// if a directory doesn't contain files, attempt looking for beatmaps inside of that directory.
// if a directory doesn't contain any beatmap files, look for further nested beatmap directories.
// this is a special behaviour in stable for beatmaps only, see https://github.com/ppy/osu/issues/18615.
foreach (string subDirectory in GetStableImportPaths(directoryStorage))
paths.Add(subDirectory);