2021-11-25 15:56:19 +08: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.
|
|
|
|
|
2022-11-17 12:34:40 +08:00
|
|
|
using System;
|
2022-06-15 11:53:49 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.IO.Stores;
|
2022-11-17 12:34:40 +08:00
|
|
|
using osu.Framework.Logging;
|
2021-11-25 14:36:12 +08:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.IO;
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
{
|
2021-11-25 15:33:04 +08:00
|
|
|
public class LegacyBeatmapImporter : LegacyModelImporter<BeatmapSetInfo>
|
2021-11-25 14:36:12 +08:00
|
|
|
{
|
|
|
|
protected override string ImportFromStablePath => ".";
|
|
|
|
|
|
|
|
protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage();
|
|
|
|
|
2022-06-15 11:53:49 +08:00
|
|
|
protected override IEnumerable<string> GetStableImportPaths(Storage storage)
|
|
|
|
{
|
2022-08-28 12:13:38 +08:00
|
|
|
// make sure the directory exists
|
|
|
|
if (!storage.ExistsDirectory(string.Empty))
|
2022-11-17 12:34:40 +08:00
|
|
|
return Array.Empty<string>();
|
2022-08-28 12:13:38 +08:00
|
|
|
|
2022-11-17 12:34:40 +08:00
|
|
|
List<string> paths = new List<string>();
|
2022-06-15 11:53:49 +08:00
|
|
|
|
2022-11-17 12:34:40 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (string directory in storage.GetDirectories(string.Empty))
|
2022-06-15 11:53:49 +08:00
|
|
|
{
|
2022-11-17 12:34:40 +08:00
|
|
|
var directoryStorage = storage.GetStorageForDirectory(directory);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!directoryStorage.GetFiles(string.Empty).ExcludeSystemFileNames().Any())
|
|
|
|
{
|
|
|
|
// if a directory doesn't contain files, attempt looking for beatmaps inside of that directory.
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
paths.Add(storage.GetFullPath(directory));
|
|
|
|
}
|
2022-11-17 12:36:16 +08:00
|
|
|
catch (Exception e)
|
2022-11-17 12:34:40 +08:00
|
|
|
{
|
|
|
|
// Catch any errors when enumerating files
|
|
|
|
Logger.Log($"Error when enumerating files in {directoryStorage.GetFullPath(string.Empty)}: {e}");
|
|
|
|
}
|
2022-06-15 11:53:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-17 12:36:16 +08:00
|
|
|
catch (Exception e)
|
2022-11-17 12:34:40 +08:00
|
|
|
{
|
|
|
|
// Catch any errors when enumerating directories
|
|
|
|
Logger.Log($"Error when enumerating directories in {storage.GetFullPath(string.Empty)}: {e}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths;
|
2022-06-15 11:53:49 +08:00
|
|
|
}
|
|
|
|
|
2021-11-25 14:39:05 +08:00
|
|
|
public LegacyBeatmapImporter(IModelImporter<BeatmapSetInfo> importer)
|
2021-11-25 14:36:12 +08:00
|
|
|
: base(importer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 14:39:05 +08:00
|
|
|
}
|