2021-09-30 14:45:09 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-07-25 10:31:46 +00:00
|
|
|
using System.Diagnostics;
|
2021-09-30 14:45:09 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
2022-07-25 10:31:46 +00:00
|
|
|
using System.Threading.Tasks;
|
2021-09-30 14:45:09 +00:00
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2022-07-28 06:03:23 +00:00
|
|
|
using osu.Game.Collections;
|
2021-09-30 14:45:09 +00:00
|
|
|
using osu.Game.Database;
|
2021-11-19 07:07:55 +00:00
|
|
|
using osu.Game.Extensions;
|
2021-09-30 14:45:09 +00:00
|
|
|
using osu.Game.IO;
|
|
|
|
using osu.Game.IO.Archives;
|
2022-07-25 10:31:46 +00:00
|
|
|
using osu.Game.Overlays.Notifications;
|
2021-09-30 14:45:09 +00:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using Realms;
|
|
|
|
|
2022-06-15 08:12:01 +00:00
|
|
|
namespace osu.Game.Beatmaps
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
|
|
|
/// </summary>
|
2022-06-20 09:39:53 +00:00
|
|
|
public class BeatmapImporter : RealmArchiveModelImporter<BeatmapSetInfo>
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2023-07-12 13:04:06 +00:00
|
|
|
public override IEnumerable<string> HandledExtensions => new[] { ".osz", ".olz" };
|
2021-09-30 14:45:09 +00:00
|
|
|
|
|
|
|
protected override string[] HashableFileTypes => new[] { ".osu" };
|
|
|
|
|
2023-04-11 19:42:55 +00:00
|
|
|
public ProcessBeatmapDelegate? ProcessBeatmap { private get; set; }
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-07-04 09:13:53 +00:00
|
|
|
public BeatmapImporter(Storage storage, RealmAccess realm)
|
2022-01-24 10:59:58 +00:00
|
|
|
: base(storage, realm)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-26 06:46:29 +00:00
|
|
|
public override async Task<Live<BeatmapSetInfo>?> ImportAsUpdate(ProgressNotification notification, ImportTask importTask, BeatmapSetInfo original)
|
2022-07-25 10:31:46 +00:00
|
|
|
{
|
2022-12-16 09:54:56 +00:00
|
|
|
var imported = await Import(notification, new[] { importTask }).ConfigureAwait(true);
|
2022-07-25 10:31:46 +00:00
|
|
|
|
2022-07-25 14:59:25 +00:00
|
|
|
if (!imported.Any())
|
2022-07-26 06:46:29 +00:00
|
|
|
return null;
|
2022-07-25 14:59:25 +00:00
|
|
|
|
2022-07-25 10:31:46 +00:00
|
|
|
Debug.Assert(imported.Count() == 1);
|
|
|
|
|
2022-07-26 06:46:29 +00:00
|
|
|
var first = imported.First();
|
|
|
|
|
2022-07-26 08:00:28 +00:00
|
|
|
// If there were no changes, ensure we don't accidentally nuke ourselves.
|
|
|
|
if (first.ID == original.ID)
|
2022-08-29 09:17:41 +00:00
|
|
|
{
|
|
|
|
first.PerformRead(s =>
|
|
|
|
{
|
|
|
|
// Re-run processing even in this case. We might have outdated metadata.
|
2023-04-11 19:42:55 +00:00
|
|
|
ProcessBeatmap?.Invoke(s, MetadataLookupScope.OnlineFirst);
|
2022-08-29 09:17:41 +00:00
|
|
|
});
|
2022-07-26 08:00:28 +00:00
|
|
|
return first;
|
2022-08-29 09:17:41 +00:00
|
|
|
}
|
2022-07-26 08:00:28 +00:00
|
|
|
|
2022-07-26 06:46:29 +00:00
|
|
|
first.PerformWrite(updated =>
|
2022-07-25 10:31:46 +00:00
|
|
|
{
|
2022-07-25 10:51:10 +00:00
|
|
|
var realm = updated.Realm;
|
2022-07-25 10:31:46 +00:00
|
|
|
|
2022-07-25 10:51:10 +00:00
|
|
|
Logger.Log($"Beatmap \"{updated}\" update completed successfully", LoggingTarget.Database);
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
original = realm!.Find<BeatmapSetInfo>(original.ID)!;
|
2022-07-25 10:31:46 +00:00
|
|
|
|
|
|
|
// Generally the import process will do this for us if the OnlineIDs match,
|
|
|
|
// but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated).
|
|
|
|
original.DeletePending = true;
|
|
|
|
|
|
|
|
// Transfer local values which should be persisted across a beatmap update.
|
|
|
|
updated.DateAdded = original.DateAdded;
|
|
|
|
|
2022-07-28 06:03:23 +00:00
|
|
|
transferCollectionReferences(realm, original, updated);
|
|
|
|
|
2022-07-25 10:31:46 +00:00
|
|
|
foreach (var beatmap in original.Beatmaps.ToArray())
|
|
|
|
{
|
|
|
|
var updatedBeatmap = updated.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.Hash);
|
|
|
|
|
|
|
|
if (updatedBeatmap != null)
|
|
|
|
{
|
|
|
|
// If the updated beatmap matches an existing one, transfer any user data across..
|
|
|
|
if (beatmap.Scores.Any())
|
|
|
|
{
|
|
|
|
Logger.Log($"Transferring {beatmap.Scores.Count()} scores for unchanged difficulty \"{beatmap}\"", LoggingTarget.Database);
|
|
|
|
|
|
|
|
foreach (var score in beatmap.Scores)
|
|
|
|
score.BeatmapInfo = updatedBeatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ..then nuke the old beatmap completely.
|
|
|
|
// this is done instead of a soft deletion to avoid a user potentially creating weird
|
|
|
|
// interactions, like restoring the outdated beatmap then updating a second time
|
|
|
|
// (causing user data to be wiped).
|
|
|
|
original.Beatmaps.Remove(beatmap);
|
2022-07-25 10:51:10 +00:00
|
|
|
|
|
|
|
realm.Remove(beatmap.Metadata);
|
|
|
|
realm.Remove(beatmap);
|
2022-07-25 10:31:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the beatmap differs in the original, leave it in a soft-deleted state but reset online info.
|
|
|
|
// This caters to the case where a user has made modifications they potentially want to restore,
|
|
|
|
// but after restoring we want to ensure it can't be used to trigger an update of the beatmap.
|
|
|
|
beatmap.ResetOnlineInfo();
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 10:51:10 +00:00
|
|
|
|
|
|
|
// If the original has no beatmaps left, delete the set as well.
|
|
|
|
if (!original.Beatmaps.Any())
|
|
|
|
realm.Remove(original);
|
2022-07-25 10:31:46 +00:00
|
|
|
});
|
|
|
|
|
2022-07-26 06:46:29 +00:00
|
|
|
return first;
|
2022-07-25 10:31:46 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 06:03:23 +00:00
|
|
|
private static void transferCollectionReferences(Realm realm, BeatmapSetInfo original, BeatmapSetInfo updated)
|
|
|
|
{
|
|
|
|
// First check if every beatmap in the original set is in any collections.
|
|
|
|
// In this case, we will assume they also want any newly added difficulties added to the collection.
|
|
|
|
foreach (var c in realm.All<BeatmapCollection>())
|
|
|
|
{
|
|
|
|
if (original.Beatmaps.Select(b => b.MD5Hash).All(c.BeatmapMD5Hashes.Contains))
|
|
|
|
{
|
|
|
|
foreach (var b in original.Beatmaps)
|
|
|
|
c.BeatmapMD5Hashes.Remove(b.MD5Hash);
|
|
|
|
|
|
|
|
foreach (var b in updated.Beatmaps)
|
|
|
|
c.BeatmapMD5Hashes.Add(b.MD5Hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle collections using permissive difficulty name to track difficulties.
|
|
|
|
foreach (var originalBeatmap in original.Beatmaps)
|
|
|
|
{
|
2022-10-11 06:50:02 +00:00
|
|
|
updated.Beatmaps
|
|
|
|
.FirstOrDefault(b => b.DifficultyName == originalBeatmap.DifficultyName)?
|
|
|
|
.TransferCollectionReferences(realm, originalBeatmap.MD5Hash);
|
2022-07-28 06:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 19:04:09 +00:00
|
|
|
protected override bool ShouldDeleteArchive(string path) => HandledExtensions.Contains(Path.GetExtension(path).ToLowerInvariant());
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-01-13 07:27:07 +00:00
|
|
|
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
if (archive != null)
|
2022-06-27 06:29:01 +00:00
|
|
|
beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet, realm));
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
2022-01-07 15:40:14 +00:00
|
|
|
{
|
2021-09-30 14:45:09 +00:00
|
|
|
b.BeatmapSet = beatmapSet;
|
|
|
|
|
2022-01-07 15:40:14 +00:00
|
|
|
// ensure we aren't trying to add a new ruleset to the database
|
|
|
|
// this can happen in tests, mostly
|
|
|
|
if (!b.Ruleset.IsManaged)
|
2022-01-17 05:02:15 +00:00
|
|
|
b.Ruleset = realm.Find<RulesetInfo>(b.Ruleset.ShortName) ?? throw new ArgumentNullException(nameof(b.Ruleset));
|
2022-01-07 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 14:45:09 +00:00
|
|
|
validateOnlineIds(beatmapSet, realm);
|
|
|
|
|
2021-11-12 08:45:05 +00:00
|
|
|
bool hadOnlineIDs = beatmapSet.Beatmaps.Any(b => b.OnlineID > 0);
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-06-20 09:39:53 +00:00
|
|
|
// TODO: this may no longer be valid as we aren't doing an online population at this point.
|
2021-09-30 14:45:09 +00:00
|
|
|
// ensure at least one beatmap was able to retrieve or keep an online ID, else drop the set ID.
|
2021-11-12 08:45:05 +00:00
|
|
|
if (hadOnlineIDs && !beatmapSet.Beatmaps.Any(b => b.OnlineID > 0))
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-20 06:20:30 +00:00
|
|
|
if (beatmapSet.OnlineID > 0)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-18 07:10:37 +00:00
|
|
|
beatmapSet.OnlineID = -1;
|
2021-09-30 14:45:09 +00:00
|
|
|
LogForModel(beatmapSet, "Disassociating beatmap set ID due to loss of all beatmap IDs");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
protected override void PreImport(BeatmapSetInfo beatmapSet, Realm realm)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-18 06:06:09 +00:00
|
|
|
// We are about to import a new beatmap. Before doing so, ensure that no other set shares the online IDs used by the new one.
|
|
|
|
// Note that this means if the previous beatmap is restored by the user, it will no longer be linked to its online IDs.
|
|
|
|
// If this is ever an issue, we can consider marking as pending delete but not resetting the IDs (but care will be required for
|
|
|
|
// beatmaps, which don't have their own `DeletePending` state).
|
|
|
|
|
2021-10-20 06:20:30 +00:00
|
|
|
if (beatmapSet.OnlineID > 0)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2022-07-14 08:04:00 +00:00
|
|
|
// OnlineID should really be unique, but to avoid catastrophic failure let's iterate just to be sure.
|
|
|
|
foreach (var existingSetWithSameOnlineID in realm.All<BeatmapSetInfo>().Where(b => b.OnlineID == beatmapSet.OnlineID))
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-19 02:37:46 +00:00
|
|
|
existingSetWithSameOnlineID.DeletePending = true;
|
|
|
|
existingSetWithSameOnlineID.OnlineID = -1;
|
2021-10-18 06:06:09 +00:00
|
|
|
|
2021-10-19 02:37:46 +00:00
|
|
|
foreach (var b in existingSetWithSameOnlineID.Beatmaps)
|
2022-07-25 09:51:19 +00:00
|
|
|
b.ResetOnlineInfo();
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-07-14 08:04:00 +00:00
|
|
|
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineID ({beatmapSet.OnlineID}). It will be disassociated and marked for deletion.");
|
2021-09-30 14:45:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 14:56:11 +00:00
|
|
|
protected override void PostImport(BeatmapSetInfo model, Realm realm, ImportParameters parameters)
|
2022-06-24 10:04:20 +00:00
|
|
|
{
|
2022-12-12 14:56:11 +00:00
|
|
|
base.PostImport(model, realm, parameters);
|
2023-06-29 05:07:43 +00:00
|
|
|
|
2023-07-01 18:37:33 +00:00
|
|
|
// Scores are stored separately from beatmaps, and persist even when a beatmap is modified or deleted.
|
2023-07-01 14:37:22 +00:00
|
|
|
// Let's reattach any matching scores that exist in the database, based on hash.
|
2023-07-01 14:12:04 +00:00
|
|
|
foreach (BeatmapInfo beatmap in model.Beatmaps)
|
2023-06-29 05:07:43 +00:00
|
|
|
{
|
2023-07-04 05:51:09 +00:00
|
|
|
beatmap.UpdateLocalScores(realm);
|
2023-06-29 05:07:43 +00:00
|
|
|
}
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2023-04-11 19:42:55 +00:00
|
|
|
ProcessBeatmap?.Invoke(model, parameters.Batch ? MetadataLookupScope.LocalCacheFirst : MetadataLookupScope.OnlineFirst);
|
2022-06-24 10:04:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
private void validateOnlineIds(BeatmapSetInfo beatmapSet, Realm realm)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-20 06:20:30 +00:00
|
|
|
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineID > 0).Select(b => b.OnlineID).ToList();
|
2021-09-30 14:45:09 +00:00
|
|
|
|
|
|
|
// ensure all IDs are unique
|
|
|
|
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
|
|
|
|
{
|
|
|
|
LogForModel(beatmapSet, "Found non-unique IDs, resetting...");
|
|
|
|
resetIds();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find any existing beatmaps in the database that have matching online ids
|
2021-11-19 10:07:21 +00:00
|
|
|
List<BeatmapInfo> existingBeatmaps = new List<BeatmapInfo>();
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
foreach (int id in beatmapIds)
|
2021-11-19 10:07:21 +00:00
|
|
|
existingBeatmaps.AddRange(realm.All<BeatmapInfo>().Where(b => b.OnlineID == id));
|
2021-09-30 14:45:09 +00:00
|
|
|
|
|
|
|
if (existingBeatmaps.Any())
|
|
|
|
{
|
|
|
|
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
|
|
|
|
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
|
|
|
|
|
|
|
|
var existing = CheckForExisting(beatmapSet, realm);
|
|
|
|
|
|
|
|
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
|
|
|
|
{
|
|
|
|
LogForModel(beatmapSet, "Found existing import with online IDs already, resetting...");
|
|
|
|
resetIds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 09:51:19 +00:00
|
|
|
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.ResetOnlineInfo());
|
2021-09-30 14:45:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
if (!base.CanSkipImport(existing, import))
|
|
|
|
return false;
|
|
|
|
|
2021-10-20 06:20:30 +00:00
|
|
|
return existing.Beatmaps.Any(b => b.OnlineID > 0);
|
2021-09-30 14:45:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
protected override bool CanReuseExisting(BeatmapSetInfo existing, BeatmapSetInfo import)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
if (!base.CanReuseExisting(existing, import))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var existingIds = existing.Beatmaps.Select(b => b.OnlineID).OrderBy(i => i);
|
|
|
|
var importIds = import.Beatmaps.Select(b => b.OnlineID).OrderBy(i => i);
|
|
|
|
|
|
|
|
// force re-import if we are not in a sane state.
|
|
|
|
return existing.OnlineID == import.OnlineID && existingIds.SequenceEqual(importIds);
|
|
|
|
}
|
|
|
|
|
2022-03-22 05:10:21 +00:00
|
|
|
protected override void UndeleteForReuse(BeatmapSetInfo existing)
|
|
|
|
{
|
|
|
|
base.UndeleteForReuse(existing);
|
|
|
|
existing.DateAdded = DateTimeOffset.UtcNow;
|
|
|
|
}
|
|
|
|
|
2021-09-30 14:45:09 +00:00
|
|
|
public override string HumanisedModelName => "beatmap";
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
protected override BeatmapSetInfo? CreateModel(ArchiveReader reader)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
|
|
|
// let's make sure there are actually .osu files to import.
|
|
|
|
string? mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(mapName))
|
|
|
|
{
|
|
|
|
Logger.Log($"No beatmap files found in the beatmap archive ({reader.Name}).", LoggingTarget.Database);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Beatmap beatmap;
|
2022-06-20 07:07:10 +00:00
|
|
|
|
2021-09-30 14:45:09 +00:00
|
|
|
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
|
2022-06-20 07:07:10 +00:00
|
|
|
{
|
|
|
|
if (stream.PeekLine() == null)
|
|
|
|
{
|
|
|
|
Logger.Log($"No content found in first .osu file of beatmap archive ({reader.Name} / {mapName})", LoggingTarget.Database);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-30 14:45:09 +00:00
|
|
|
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
2022-06-20 07:07:10 +00:00
|
|
|
}
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
return new BeatmapSetInfo
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-11-12 08:50:31 +00:00
|
|
|
OnlineID = beatmap.BeatmapInfo.BeatmapSet?.OnlineID ?? -1,
|
2021-09-30 14:45:09 +00:00
|
|
|
// Metadata = beatmap.Metadata,
|
|
|
|
DateAdded = DateTimeOffset.UtcNow
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2021-11-19 10:07:21 +00:00
|
|
|
/// Create all required <see cref="BeatmapInfo"/>s for the provided archive.
|
2021-09-30 14:45:09 +00:00
|
|
|
/// </summary>
|
2022-06-27 06:29:01 +00:00
|
|
|
private List<BeatmapInfo> createBeatmapDifficulties(BeatmapSetInfo beatmapSet, Realm realm)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-11-19 10:07:21 +00:00
|
|
|
var beatmaps = new List<BeatmapInfo>();
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-06-27 06:29:01 +00:00
|
|
|
foreach (var file in beatmapSet.Files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-11-19 07:07:55 +00:00
|
|
|
using (var memoryStream = new MemoryStream(Files.Store.Get(file.File.GetStoragePath()))) // we need a memory stream so we can seek
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-11 05:33:47 +00:00
|
|
|
IBeatmap decoded;
|
2022-06-27 06:29:01 +00:00
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
using (var lineReader = new LineBufferedReader(memoryStream, true))
|
2022-06-27 06:29:01 +00:00
|
|
|
{
|
|
|
|
if (lineReader.PeekLine() == null)
|
|
|
|
{
|
|
|
|
LogForModel(beatmapSet, $"No content found in beatmap file {file.Filename}.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
decoded = Decoder.GetDecoder<Beatmap>(lineReader).Decode(lineReader);
|
2022-06-27 06:29:01 +00:00
|
|
|
}
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
string hash = memoryStream.ComputeSHA2Hash();
|
2021-09-30 14:45:09 +00:00
|
|
|
|
|
|
|
if (beatmaps.Any(b => b.Hash == hash))
|
2021-10-11 05:33:47 +00:00
|
|
|
{
|
2022-06-27 06:29:01 +00:00
|
|
|
LogForModel(beatmapSet, $"Skipping import of {file.Filename} due to duplicate file content.");
|
2021-09-30 14:45:09 +00:00
|
|
|
continue;
|
2021-10-11 05:33:47 +00:00
|
|
|
}
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
var decodedInfo = decoded.BeatmapInfo;
|
2022-01-18 13:57:39 +00:00
|
|
|
var decodedDifficulty = decodedInfo.Difficulty;
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2022-01-27 06:19:48 +00:00
|
|
|
var ruleset = realm.All<RulesetInfo>().FirstOrDefault(r => r.OnlineID == decodedInfo.Ruleset.OnlineID);
|
2021-09-30 14:45:09 +00:00
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
if (ruleset?.Available != true)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2022-06-27 06:29:01 +00:00
|
|
|
LogForModel(beatmapSet, $"Skipping import of {file.Filename} due to missing local ruleset {decodedInfo.Ruleset.OnlineID}.");
|
2021-09-30 14:45:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
var difficulty = new BeatmapDifficulty
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-11 05:33:47 +00:00
|
|
|
DrainRate = decodedDifficulty.DrainRate,
|
|
|
|
CircleSize = decodedDifficulty.CircleSize,
|
|
|
|
OverallDifficulty = decodedDifficulty.OverallDifficulty,
|
|
|
|
ApproachRate = decodedDifficulty.ApproachRate,
|
|
|
|
SliderMultiplier = decodedDifficulty.SliderMultiplier,
|
|
|
|
SliderTickRate = decodedDifficulty.SliderTickRate,
|
2021-09-30 14:45:09 +00:00
|
|
|
};
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
var metadata = new BeatmapMetadata
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-11 05:33:47 +00:00
|
|
|
Title = decoded.Metadata.Title,
|
|
|
|
TitleUnicode = decoded.Metadata.TitleUnicode,
|
|
|
|
Artist = decoded.Metadata.Artist,
|
|
|
|
ArtistUnicode = decoded.Metadata.ArtistUnicode,
|
2021-11-04 09:22:21 +00:00
|
|
|
Author =
|
|
|
|
{
|
2021-11-22 05:55:41 +00:00
|
|
|
OnlineID = decoded.Metadata.Author.OnlineID,
|
2021-11-04 09:46:26 +00:00
|
|
|
Username = decoded.Metadata.Author.Username
|
2021-11-04 09:22:21 +00:00
|
|
|
},
|
2021-10-11 05:33:47 +00:00
|
|
|
Source = decoded.Metadata.Source,
|
|
|
|
Tags = decoded.Metadata.Tags,
|
|
|
|
PreviewTime = decoded.Metadata.PreviewTime,
|
|
|
|
AudioFile = decoded.Metadata.AudioFile,
|
|
|
|
BackgroundFile = decoded.Metadata.BackgroundFile,
|
2021-09-30 14:45:09 +00:00
|
|
|
};
|
|
|
|
|
2021-11-19 10:07:21 +00:00
|
|
|
var beatmap = new BeatmapInfo(ruleset, difficulty, metadata)
|
2021-09-30 14:45:09 +00:00
|
|
|
{
|
2021-10-11 05:33:47 +00:00
|
|
|
Hash = hash,
|
2021-11-11 08:19:53 +00:00
|
|
|
DifficultyName = decodedInfo.DifficultyName,
|
2021-11-22 05:55:41 +00:00
|
|
|
OnlineID = decodedInfo.OnlineID,
|
2021-10-11 05:33:47 +00:00
|
|
|
AudioLeadIn = decodedInfo.AudioLeadIn,
|
|
|
|
StackLeniency = decodedInfo.StackLeniency,
|
|
|
|
SpecialStyle = decodedInfo.SpecialStyle,
|
|
|
|
LetterboxInBreaks = decodedInfo.LetterboxInBreaks,
|
|
|
|
WidescreenStoryboard = decodedInfo.WidescreenStoryboard,
|
|
|
|
EpilepsyWarning = decodedInfo.EpilepsyWarning,
|
|
|
|
SamplesMatchPlaybackRate = decodedInfo.SamplesMatchPlaybackRate,
|
|
|
|
DistanceSpacing = decodedInfo.DistanceSpacing,
|
|
|
|
BeatDivisor = decodedInfo.BeatDivisor,
|
|
|
|
GridSize = decodedInfo.GridSize,
|
|
|
|
TimelineZoom = decodedInfo.TimelineZoom,
|
|
|
|
MD5Hash = memoryStream.ComputeMD5Hash(),
|
2021-09-30 14:45:09 +00:00
|
|
|
};
|
|
|
|
|
2021-10-11 05:33:47 +00:00
|
|
|
beatmaps.Add(beatmap);
|
2021-09-30 14:45:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return beatmaps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|