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-05 01:35:40 +08:00
|
|
|
|
using osu.Framework.OS;
|
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>();
|
|
|
|
|
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 beatmapMetadata = new BeatmapMetadata
|
|
|
|
|
{
|
|
|
|
|
Title = metadata.Title,
|
|
|
|
|
TitleUnicode = metadata.TitleUnicode,
|
|
|
|
|
Artist = metadata.Artist,
|
|
|
|
|
ArtistUnicode = metadata.ArtistUnicode,
|
|
|
|
|
Author = metadata.Author,
|
|
|
|
|
Source = metadata.Source,
|
|
|
|
|
Tags = metadata.Tags,
|
|
|
|
|
Mode = metadata.Mode,
|
|
|
|
|
PreviewTime = metadata.PreviewTime,
|
|
|
|
|
AudioFile = metadata.AudioFile,
|
|
|
|
|
BackgroundFile = metadata.BackgroundFile,
|
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
maps.Add(new Beatmap
|
|
|
|
|
{
|
|
|
|
|
ID = beatmap.BeatmapID,
|
|
|
|
|
BeatmapSetID = metadata.BeatmapSetID,
|
|
|
|
|
// TODO: Import more things
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
beatmapSet.BeatmapMetadataID = Connection.Insert(beatmapMetadata);
|
|
|
|
|
Connection.Insert(beatmapSet);
|
|
|
|
|
Connection.InsertAll(maps);
|
2016-10-04 23:31:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|