Crentalise all import logic

This commit is contained in:
Dean Herbert
2018-02-15 14:19:16 +09:00
parent d3dd31dadb
commit a0a65abcac
8 changed files with 45 additions and 23 deletions

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using System.IO;
using osu.Framework.Platform;
@ -14,7 +15,7 @@ using SharpCompress.Compressors.LZMA;
namespace osu.Game.Rulesets.Scoring
{
public class ScoreStore : DatabaseBackedStore
public class ScoreStore : DatabaseBackedStore, ICanAcceptFiles
{
private readonly Storage storage;
@ -23,6 +24,8 @@ namespace osu.Game.Rulesets.Scoring
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;
@ -36,6 +39,18 @@ namespace osu.Game.Rulesets.Scoring
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)
{
Score score;
@ -159,5 +174,6 @@ namespace osu.Game.Rulesets.Scoring
return new Replay { Frames = frames };
}
}
}