osu/osu.Game/Scoring/ScoreStore.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2018-04-13 09:19:50 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.IO;
using osu.Framework.Logging;
2018-04-13 09:19:50 +00:00
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IPC;
using osu.Game.Rulesets.Scoring.Legacy;
2018-11-28 07:12:57 +00:00
namespace osu.Game.Scoring
2018-04-13 09:19:50 +00:00
{
public class ScoreStore : DatabaseBackedStore, ICanAcceptFiles
{
private readonly BeatmapManager beatmaps;
private readonly RulesetStore rulesets;
private const string replay_folder = @"replays";
public event Action<Score> ScoreImported;
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
private ScoreIPCChannel ipc;
2018-09-25 01:08:58 +00:00
public ScoreStore(DatabaseContextFactory factory, IIpcHost importHost = null, BeatmapManager beatmaps = null, RulesetStore rulesets = null) : base(factory)
2018-04-13 09:19:50 +00:00
{
this.beatmaps = beatmaps;
this.rulesets = rulesets;
if (importHost != null)
ipc = new ScoreIPCChannel(importHost, this);
}
public string[] HandledExtensions => new[] { ".osr" };
public void Import(params string[] paths)
{
foreach (var path in paths)
{
var score = ReadReplayFile(path);
if (score != null)
ScoreImported?.Invoke(score);
}
}
public Score ReadReplayFile(string replayFilename)
{
2018-09-25 01:35:13 +00:00
if (File.Exists(replayFilename))
{
2018-09-25 01:35:13 +00:00
using (var stream = File.OpenRead(replayFilename))
return new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(stream);
}
2018-09-25 01:35:13 +00:00
Logger.Log($"Replay file {replayFilename} cannot be found", LoggingTarget.Information, LogLevel.Error);
return null;
2018-04-13 09:19:50 +00:00
}
}
}