mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add lifecycle management to BeatmapDatabase
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -65,6 +66,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
Beatmap beatmap = decoder.Decode(stream);
|
Beatmap beatmap = decoder.Decode(stream);
|
||||||
|
beatmap.BeatmapInfo.Path = name;
|
||||||
// TODO: Diff beatmap metadata with set metadata and insert if necessary
|
// TODO: Diff beatmap metadata with set metadata and insert if necessary
|
||||||
beatmap.BeatmapInfo.Metadata = null;
|
beatmap.BeatmapInfo.Metadata = null;
|
||||||
maps.Add(beatmap.BeatmapInfo);
|
maps.Add(beatmap.BeatmapInfo);
|
||||||
@ -82,5 +84,43 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Beatmap GetBeatmap(BeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
var beatmapSet = Query<BeatmapSetInfo>()
|
||||||
|
.Where(s => s.BeatmapSetID == beatmapInfo.BeatmapSetID).FirstOrDefault();
|
||||||
|
if (beatmapSet == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
|
||||||
|
using (var reader = GetReader(beatmapSet))
|
||||||
|
using (var stream = new StreamReader(reader.ReadFile(beatmapInfo.Path)))
|
||||||
|
{
|
||||||
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
|
return decoder.Decode(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableQuery<T> Query<T>() where T : class
|
||||||
|
{
|
||||||
|
return connection.Table<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly Type[] validTypes = new[]
|
||||||
|
{
|
||||||
|
typeof(BeatmapSetInfo),
|
||||||
|
typeof(BeatmapInfo),
|
||||||
|
typeof(BeatmapMetadata),
|
||||||
|
typeof(BaseDifficulty),
|
||||||
|
};
|
||||||
|
|
||||||
|
public void Update<T>(T record, bool cascade = true) where T : class
|
||||||
|
{
|
||||||
|
if (!validTypes.Any(t => t == typeof(T)))
|
||||||
|
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
||||||
|
if (cascade)
|
||||||
|
connection.UpdateWithChildren(record);
|
||||||
|
else
|
||||||
|
connection.Update(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
using osu.Game.GameModes.Play;
|
using osu.Game.GameModes.Play;
|
||||||
using SQLite.Net.Attributes;
|
using SQLite.Net.Attributes;
|
||||||
using SQLiteNetExtensions.Attributes;
|
using SQLiteNetExtensions.Attributes;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
@ -27,6 +27,8 @@ namespace osu.Game.Database
|
|||||||
[OneToOne]
|
[OneToOne]
|
||||||
public BaseDifficulty BaseDifficulty { get; set; }
|
public BaseDifficulty BaseDifficulty { get; set; }
|
||||||
|
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
// General
|
// General
|
||||||
public int AudioLeadIn { get; set; }
|
public int AudioLeadIn { get; set; }
|
||||||
public bool Countdown { get; set; }
|
public bool Countdown { get; set; }
|
||||||
|
Reference in New Issue
Block a user