2016-10-04 23:31:10 +08:00
|
|
|
|
using System;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2016-10-10 21:20:06 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2016-10-08 01:50:34 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
|
using osu.Game.Beatmaps.IO;
|
2016-10-04 23:31:10 +08:00
|
|
|
|
using SQLite;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
|
{
|
|
|
|
|
public class BeatmapDatabase
|
|
|
|
|
{
|
|
|
|
|
private static SQLiteConnection Connection { get; set; }
|
|
|
|
|
|
2016-10-05 01:35:40 +08:00
|
|
|
|
public BeatmapDatabase(BasicStorage storage)
|
2016-10-04 23:31:10 +08:00
|
|
|
|
{
|
|
|
|
|
if (Connection == null)
|
|
|
|
|
{
|
2016-10-05 02:23:34 +08:00
|
|
|
|
Connection = storage.GetDatabase(@"beatmaps");
|
2016-10-04 23:31:10 +08:00
|
|
|
|
Connection.CreateTable<BeatmapMetadata>();
|
2016-10-08 01:57:06 +08:00
|
|
|
|
Connection.CreateTable<BaseDifficulty>();
|
2016-10-04 23:31:10 +08:00
|
|
|
|
Connection.CreateTable<BeatmapSet>();
|
|
|
|
|
Connection.CreateTable<Beatmap>();
|
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
public void AddBeatmap(ArchiveReader input)
|
|
|
|
|
{
|
|
|
|
|
var metadata = input.ReadMetadata();
|
|
|
|
|
if (Connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
|
|
|
|
return;
|
|
|
|
|
string[] mapNames = input.ReadBeatmaps();
|
|
|
|
|
var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID };
|
|
|
|
|
var maps = new List<Beatmap>();
|
|
|
|
|
foreach (var name in mapNames)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new StreamReader(input.ReadFile(name)))
|
|
|
|
|
{
|
|
|
|
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
|
|
|
|
var beatmap = decoder.Decode(stream);
|
2016-10-08 01:57:06 +08:00
|
|
|
|
maps.Add(beatmap);
|
|
|
|
|
beatmap.BaseDifficultyID = Connection.Insert(beatmap.BaseDifficulty);
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-08 01:57:06 +08:00
|
|
|
|
beatmapSet.BeatmapMetadataID = Connection.Insert(metadata);
|
2016-10-05 04:29:08 +08:00
|
|
|
|
Connection.Insert(beatmapSet);
|
|
|
|
|
Connection.InsertAll(maps);
|
2016-10-04 23:31:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|