mirror of
https://github.com/ppy/osu.git
synced 2026-06-03 22:14:57 +08:00
Merge pull request #34893 from bdach/ignore-osu-files-in-subdirs
Ignore `.osu` files not placed at top level of beatmap archive on import
This commit is contained in:
@@ -1018,6 +1018,49 @@ namespace osu.Game.Tests.Database
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBeatmapFilesInNestedDirectoriesAreIgnored()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
var importer = new BeatmapImporter(storage, realm);
|
||||
using var store = new RealmRulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
string extractedFolder = $"{temp}_extracted";
|
||||
Directory.CreateDirectory(extractedFolder);
|
||||
|
||||
try
|
||||
{
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(extractedFolder);
|
||||
|
||||
var subdirectory = Directory.CreateDirectory(Path.Combine(extractedFolder, "subdir"));
|
||||
string modifiedCopyPath = Path.Combine(subdirectory.FullName, "duplicate.osu");
|
||||
File.Copy(Directory.GetFiles(extractedFolder, "*.osu").First(), modifiedCopyPath);
|
||||
|
||||
using (var stream = File.OpenWrite(modifiedCopyPath))
|
||||
using (var textWriter = new StreamWriter(stream))
|
||||
await textWriter.WriteLineAsync("# adding a comment so that the hashes are different");
|
||||
|
||||
using (var zip = ZipArchive.Create())
|
||||
{
|
||||
zip.AddAllFromDirectory(extractedFolder);
|
||||
zip.SaveTo(temp, new ZipWriterOptions(CompressionType.Deflate));
|
||||
}
|
||||
|
||||
await importer.Import(temp);
|
||||
|
||||
EnsureLoaded(realm.Realm);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(extractedFolder, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportNestedStructure()
|
||||
{
|
||||
|
||||
@@ -367,7 +367,11 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
var beatmaps = new List<BeatmapInfo>();
|
||||
|
||||
foreach (var file in beatmapSet.Files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
|
||||
// stable appears to ignore `.osu` files which are not placed at the top level of the beatmap archive.
|
||||
// the logic that achieves this is very difficult to make sense of, but appears to be located somewhere around
|
||||
// https://github.com/peppy/osu-stable-reference/blob/67795dba3c308e7d0493b296149dcb073ca47ecb/osu!/GameplayElements/Beatmaps/BeatmapManager.cs#L207-L208
|
||||
// only testing the `/` path separator character is sufficient as `RealmNamedFileUsage`s are normalised to use the front slash unix path separator convention
|
||||
foreach (var file in beatmapSet.Files.Where(f => !f.Filename.Contains('/') && f.Filename.EndsWith(@".osu", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
using (var memoryStream = new MemoryStream(Files.Store.Get(file.File.GetStoragePath()))) // we need a memory stream so we can seek
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user