mirror of
https://github.com/osukey/osukey.git
synced 2025-05-20 04:57:38 +09:00
Copy imported beatmaps into beatmap storage
This commit is contained in:
parent
b7976dce46
commit
fd10e6e582
@ -22,5 +22,7 @@ namespace osu.Game.Beatmaps
|
|||||||
public BeatmapMetadata Metadata { get; set; }
|
public BeatmapMetadata Metadata { get; set; }
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public User Creator { get; set; }
|
public User Creator { get; set; }
|
||||||
|
public string Hash { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using Ionic.Zip;
|
using Ionic.Zip;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
@ -12,9 +13,11 @@ namespace osu.Game.Database
|
|||||||
public class BeatmapDatabase
|
public class BeatmapDatabase
|
||||||
{
|
{
|
||||||
private static SQLiteConnection connection { get; set; }
|
private static SQLiteConnection connection { get; set; }
|
||||||
|
private BasicStorage storage;
|
||||||
|
|
||||||
public BeatmapDatabase(BasicStorage storage)
|
public BeatmapDatabase(BasicStorage storage)
|
||||||
{
|
{
|
||||||
|
this.storage = storage;
|
||||||
if (connection == null)
|
if (connection == null)
|
||||||
{
|
{
|
||||||
connection = storage.GetDatabase(@"beatmaps");
|
connection = storage.GetDatabase(@"beatmaps");
|
||||||
@ -24,17 +27,39 @@ namespace osu.Game.Database
|
|||||||
connection.CreateTable<Beatmap>();
|
connection.CreateTable<Beatmap>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void AddBeatmap(ArchiveReader input)
|
public void AddBeatmap(string path)
|
||||||
{
|
{
|
||||||
var metadata = input.ReadMetadata();
|
string hash = null;
|
||||||
|
ArchiveReader reader;
|
||||||
|
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||||
|
{
|
||||||
|
using (var md5 = MD5.Create())
|
||||||
|
using (var input = storage.GetStream(path))
|
||||||
|
{
|
||||||
|
hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant();
|
||||||
|
input.Seek(0, SeekOrigin.Begin);
|
||||||
|
var outputPath = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
|
||||||
|
using (var output = storage.GetStream(outputPath, FileAccess.Write))
|
||||||
|
input.CopyTo(output);
|
||||||
|
reader = ArchiveReader.GetReader(storage, path = outputPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
reader = ArchiveReader.GetReader(storage, path);
|
||||||
|
var metadata = reader.ReadMetadata();
|
||||||
if (connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
if (connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||||
return;
|
return;
|
||||||
string[] mapNames = input.ReadBeatmaps();
|
string[] mapNames = reader.ReadBeatmaps();
|
||||||
var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID };
|
var beatmapSet = new BeatmapSet
|
||||||
|
{
|
||||||
|
BeatmapSetID = metadata.BeatmapSetID,
|
||||||
|
Path = path,
|
||||||
|
Hash = hash,
|
||||||
|
};
|
||||||
var maps = new List<Beatmap>();
|
var maps = new List<Beatmap>();
|
||||||
foreach (var name in mapNames)
|
foreach (var name in mapNames)
|
||||||
{
|
{
|
||||||
using (var stream = new StreamReader(input.ReadFile(name)))
|
using (var stream = new StreamReader(reader.ReadFile(name)))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
var beatmap = decoder.Decode(stream);
|
var beatmap = decoder.Decode(stream);
|
||||||
@ -46,5 +71,12 @@ namespace osu.Game.Database
|
|||||||
connection.Insert(beatmapSet);
|
connection.Insert(beatmapSet);
|
||||||
connection.InsertAll(maps);
|
connection.InsertAll(maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
|
||||||
|
/// </summary>
public void PopulateBeatmap(BeatmapSet beatmap)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,8 +73,7 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var reader = ArchiveReader.GetReader(Host.Storage, message.Path);
|
Beatmaps.AddBeatmap(message.Path);
|
||||||
Beatmaps.AddBeatmap(reader);
|
|
||||||
// TODO: Switch to beatmap list and select the new song
|
// TODO: Switch to beatmap list and select the new song
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user