mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Converted all .cs files to use CRLF line endings.
This commit is contained in:
@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class BaseDifficulty
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
public float DrainRate { get; set; }
|
||||
public float CircleSize { get; set; }
|
||||
public float OverallDifficulty { get; set; }
|
||||
public float ApproachRate { get; set; }
|
||||
public float SliderMultiplier { get; set; }
|
||||
public float SliderTickRate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class BaseDifficulty
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
public float DrainRate { get; set; }
|
||||
public float CircleSize { get; set; }
|
||||
public float OverallDifficulty { get; set; }
|
||||
public float ApproachRate { get; set; }
|
||||
public float SliderMultiplier { get; set; }
|
||||
public float SliderTickRate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
using System;
|
||||
namespace osu.Game.Beatmaps.Events
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
Background = 0,
|
||||
Video = 1,
|
||||
Break = 2,
|
||||
Colour = 3,
|
||||
Sprite = 4,
|
||||
Sample = 5,
|
||||
Animation = 6
|
||||
}
|
||||
using System;
|
||||
namespace osu.Game.Beatmaps.Events
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
Background = 0,
|
||||
Video = 1,
|
||||
Break = 2,
|
||||
Colour = 3,
|
||||
Sprite = 4,
|
||||
Sample = 5,
|
||||
Animation = 6
|
||||
}
|
||||
}
|
@ -1,25 +1,25 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public abstract class BeatmapDecoder
|
||||
{
|
||||
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
|
||||
|
||||
public static BeatmapDecoder GetDecoder(TextReader stream)
|
||||
{
|
||||
var line = stream.ReadLine().Trim();
|
||||
if (!decoders.ContainsKey(line))
|
||||
throw new IOException(@"Unknown file format");
|
||||
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
|
||||
using System.IO;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public abstract class BeatmapDecoder
|
||||
{
|
||||
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
|
||||
|
||||
public static BeatmapDecoder GetDecoder(TextReader stream)
|
||||
{
|
||||
var line = stream.ReadLine().Trim();
|
||||
if (!decoders.ContainsKey(line))
|
||||
throw new IOException(@"Unknown file format");
|
||||
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
|
||||
}
|
||||
|
||||
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
|
||||
{
|
||||
decoders[magic] = typeof(T);
|
||||
}
|
||||
|
||||
public abstract void Decode(TextReader stream, Beatmap beatmap);
|
||||
|
||||
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
|
||||
{
|
||||
decoders[magic] = typeof(T);
|
||||
}
|
||||
|
||||
public abstract void Decode(TextReader stream, Beatmap beatmap);
|
||||
}
|
@ -1,48 +1,48 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public abstract class ArchiveReader : IDisposable
|
||||
{
|
||||
private class Reader
|
||||
{
|
||||
public Func<BasicStorage, string, bool> Test { get; set; }
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
|
||||
private static List<Reader> readers { get; } = new List<Reader>();
|
||||
|
||||
public static ArchiveReader GetReader(BasicStorage storage, string path)
|
||||
{
|
||||
foreach (var reader in readers)
|
||||
{
|
||||
if (reader.Test(storage, path))
|
||||
return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path));
|
||||
}
|
||||
throw new IOException(@"Unknown file format");
|
||||
}
|
||||
|
||||
protected static void AddReader<T>(Func<BasicStorage, string, bool> test) where T : ArchiveReader
|
||||
{
|
||||
readers.Add(new Reader { Test = test, Type = typeof(T) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the beatmap metadata from this archive.
|
||||
/// </summary>
|
||||
public abstract BeatmapMetadata ReadMetadata();
|
||||
/// <summary>
|
||||
/// Gets a list of beatmap file names.
|
||||
/// </summary>
|
||||
public abstract string[] ReadBeatmaps();
|
||||
/// <summary>
|
||||
/// Opens a stream for reading a specific file from this archive.
|
||||
/// </summary>
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public abstract class ArchiveReader : IDisposable
|
||||
{
|
||||
private class Reader
|
||||
{
|
||||
public Func<BasicStorage, string, bool> Test { get; set; }
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
|
||||
private static List<Reader> readers { get; } = new List<Reader>();
|
||||
|
||||
public static ArchiveReader GetReader(BasicStorage storage, string path)
|
||||
{
|
||||
foreach (var reader in readers)
|
||||
{
|
||||
if (reader.Test(storage, path))
|
||||
return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path));
|
||||
}
|
||||
throw new IOException(@"Unknown file format");
|
||||
}
|
||||
|
||||
protected static void AddReader<T>(Func<BasicStorage, string, bool> test) where T : ArchiveReader
|
||||
{
|
||||
readers.Add(new Reader { Test = test, Type = typeof(T) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the beatmap metadata from this archive.
|
||||
/// </summary>
|
||||
public abstract BeatmapMetadata ReadMetadata();
|
||||
/// <summary>
|
||||
/// Gets a list of beatmap file names.
|
||||
/// </summary>
|
||||
public abstract string[] ReadBeatmaps();
|
||||
/// <summary>
|
||||
/// Opens a stream for reading a specific file from this archive.
|
||||
/// </summary>
|
||||
public abstract Stream ReadFile(string name);
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
@ -1,41 +1,41 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using Ionic.Zip;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public sealed class OszArchiveReader : ArchiveReader
|
||||
{
|
||||
public static void Register()
|
||||
{
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public sealed class OszArchiveReader : ArchiveReader
|
||||
{
|
||||
public static void Register()
|
||||
{
|
||||
AddReader<OszArchiveReader>((storage, path) =>
|
||||
{
|
||||
using (var stream = storage.GetStream(path))
|
||||
{
|
||||
using (var stream = storage.GetStream(path))
|
||||
return ZipFile.IsZipFile(stream, false);
|
||||
});
|
||||
OsuLegacyDecoder.Register();
|
||||
}
|
||||
|
||||
private ZipFile archive { get; set; }
|
||||
private string[] beatmaps { get; set; }
|
||||
});
|
||||
OsuLegacyDecoder.Register();
|
||||
}
|
||||
|
||||
private ZipFile archive { get; set; }
|
||||
private string[] beatmaps { get; set; }
|
||||
private Beatmap firstMap { get; set; }
|
||||
|
||||
public OszArchiveReader(Stream archiveStream)
|
||||
{
|
||||
archive = ZipFile.Read(archiveStream);
|
||||
beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(@".osu"))
|
||||
.Select(e => e.FileName).ToArray();
|
||||
if (beatmaps.Length == 0)
|
||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
firstMap = new Beatmap();
|
||||
decoder.Decode(stream, firstMap);
|
||||
}
|
||||
|
||||
public OszArchiveReader(Stream archiveStream)
|
||||
{
|
||||
archive = ZipFile.Read(archiveStream);
|
||||
beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(@".osu"))
|
||||
.Select(e => e.FileName).ToArray();
|
||||
if (beatmaps.Length == 0)
|
||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
firstMap = new Beatmap();
|
||||
decoder.Decode(stream, firstMap);
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] ReadBeatmaps()
|
||||
@ -45,9 +45,9 @@ namespace osu.Game.Beatmaps.IO
|
||||
|
||||
public override Stream ReadFile(string name)
|
||||
{
|
||||
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||
if (entry == null)
|
||||
throw new FileNotFoundException();
|
||||
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||
if (entry == null)
|
||||
throw new FileNotFoundException();
|
||||
return entry.OpenReader();
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
return firstMap.Metadata;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
archive.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
@ -8,82 +8,82 @@ using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapDatabase
|
||||
{
|
||||
private static SQLiteConnection connection { get; set; }
|
||||
private BasicStorage storage;
|
||||
|
||||
public BeatmapDatabase(BasicStorage storage)
|
||||
{
|
||||
this.storage = storage;
|
||||
if (connection == null)
|
||||
{
|
||||
connection = storage.GetDatabase(@"beatmaps");
|
||||
connection.CreateTable<BeatmapMetadata>();
|
||||
connection.CreateTable<BaseDifficulty>();
|
||||
connection.CreateTable<BeatmapSet>();
|
||||
connection.CreateTable<Beatmap>();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBeatmap(string path)
|
||||
{
|
||||
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)
|
||||
return; // TODO: Update this beatmap instead
|
||||
string[] mapNames = reader.ReadBeatmaps();
|
||||
var beatmapSet = new BeatmapSet
|
||||
{
|
||||
BeatmapSetID = metadata.BeatmapSetID,
|
||||
Path = path,
|
||||
Hash = hash,
|
||||
};
|
||||
var maps = new List<Beatmap>();
|
||||
foreach (var name in mapNames)
|
||||
{
|
||||
using (var stream = new StreamReader(reader.ReadFile(name)))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
Beatmap beatmap = new Beatmap();
|
||||
decoder.Decode(stream, beatmap);
|
||||
maps.Add(beatmap);
|
||||
beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty);
|
||||
}
|
||||
}
|
||||
beatmapSet.BeatmapMetadataID = connection.Insert(metadata);
|
||||
connection.Insert(beatmapSet);
|
||||
connection.InsertAll(maps);
|
||||
}
|
||||
|
||||
public ArchiveReader GetReader(BeatmapSet beatmapSet)
|
||||
{
|
||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
|
||||
/// </summary>
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapDatabase
|
||||
{
|
||||
private static SQLiteConnection connection { get; set; }
|
||||
private BasicStorage storage;
|
||||
|
||||
public BeatmapDatabase(BasicStorage storage)
|
||||
{
|
||||
this.storage = storage;
|
||||
if (connection == null)
|
||||
{
|
||||
{
|
||||
connection = storage.GetDatabase(@"beatmaps");
|
||||
connection.CreateTable<BeatmapMetadata>();
|
||||
connection.CreateTable<BaseDifficulty>();
|
||||
connection.CreateTable<BeatmapSet>();
|
||||
connection.CreateTable<Beatmap>();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBeatmap(string path)
|
||||
{
|
||||
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)
|
||||
return; // TODO: Update this beatmap instead
|
||||
string[] mapNames = reader.ReadBeatmaps();
|
||||
var beatmapSet = new BeatmapSet
|
||||
{
|
||||
BeatmapSetID = metadata.BeatmapSetID,
|
||||
Path = path,
|
||||
Hash = hash,
|
||||
};
|
||||
var maps = new List<Beatmap>();
|
||||
foreach (var name in mapNames)
|
||||
{
|
||||
using (var stream = new StreamReader(reader.ReadFile(name)))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
Beatmap beatmap = new Beatmap();
|
||||
decoder.Decode(stream, beatmap);
|
||||
maps.Add(beatmap);
|
||||
beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty);
|
||||
}
|
||||
}
|
||||
beatmapSet.BeatmapMetadataID = connection.Insert(metadata);
|
||||
connection.Insert(beatmapSet);
|
||||
connection.InsertAll(maps);
|
||||
}
|
||||
|
||||
public ArchiveReader GetReader(BeatmapSet beatmapSet)
|
||||
{
|
||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
|
||||
/// </summary>
|
||||
public void PopulateBeatmap(BeatmapSet beatmapSet)
|
||||
{
|
||||
using (var reader = GetReader(beatmapSet))
|
||||
{
|
||||
string[] mapNames = reader.ReadBeatmaps();
|
||||
@ -92,9 +92,9 @@ namespace osu.Game.Database
|
||||
using (var stream = new StreamReader(reader.ReadFile(name)))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
Beatmap beatmap = new Beatmap();
|
||||
decoder.Decode(stream, beatmap);
|
||||
beatmapSet.Beatmaps.Add(beatmap);
|
||||
}
|
||||
}
|
||||
Beatmap beatmap = new Beatmap();
|
||||
decoder.Decode(stream, beatmap);
|
||||
beatmapSet.Beatmaps.Add(beatmap);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user