mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Crentalise all import logic
This commit is contained in:
@ -115,21 +115,7 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
if (filePaths.Any(f => Path.GetExtension(f) != firstExtension)) return;
|
if (filePaths.Any(f => Path.GetExtension(f) != firstExtension)) return;
|
||||||
|
|
||||||
switch (firstExtension)
|
Task.Factory.StartNew(() => Import(filePaths), TaskCreationOptions.LongRunning);
|
||||||
{
|
|
||||||
case ".osz":
|
|
||||||
Task.Factory.StartNew(() => BeatmapManager.Import(filePaths), TaskCreationOptions.LongRunning);
|
|
||||||
return;
|
|
||||||
case ".osr":
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
var score = ScoreStore.ReadReplayFile(filePaths.First());
|
|
||||||
Schedule(() => LoadScore(score));
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string[] allowed_extensions = { @".osz", @".osr" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanImportArchives
|
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles
|
||||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||||
where TFileModel : INamedFileInfo, new()
|
where TFileModel : INamedFileInfo, new()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
public interface ICanImportArchives
|
public interface ICanAcceptFiles
|
||||||
{
|
{
|
||||||
void Import(params string[] paths);
|
void Import(params string[] paths);
|
||||||
|
|
@ -12,9 +12,9 @@ namespace osu.Game.IPC
|
|||||||
{
|
{
|
||||||
public class ArchiveImportIPCChannel : IpcChannel<ArchiveImportMessage>
|
public class ArchiveImportIPCChannel : IpcChannel<ArchiveImportMessage>
|
||||||
{
|
{
|
||||||
private readonly ICanImportArchives importer;
|
private readonly ICanAcceptFiles importer;
|
||||||
|
|
||||||
public ArchiveImportIPCChannel(IIpcHost host, ICanImportArchives importer = null)
|
public ArchiveImportIPCChannel(IIpcHost host, ICanAcceptFiles importer = null)
|
||||||
: base(host)
|
: base(host)
|
||||||
{
|
{
|
||||||
this.importer = importer;
|
this.importer = importer;
|
||||||
|
@ -105,6 +105,8 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
this.frameworkConfig = frameworkConfig;
|
this.frameworkConfig = frameworkConfig;
|
||||||
|
|
||||||
|
ScoreStore.ScoreImported += score => Schedule(() => LoadScore(score));
|
||||||
|
|
||||||
if (!Host.IsPrimaryInstance)
|
if (!Host.IsPrimaryInstance)
|
||||||
{
|
{
|
||||||
Logger.Log(@"osu! does not support multiple running instances.", LoggingTarget.Runtime, LogLevel.Error);
|
Logger.Log(@"osu! does not support multiple running instances.", LoggingTarget.Runtime, LogLevel.Error);
|
||||||
@ -114,7 +116,8 @@ namespace osu.Game
|
|||||||
if (args?.Length > 0)
|
if (args?.Length > 0)
|
||||||
{
|
{
|
||||||
var paths = args.Where(a => !a.StartsWith(@"-"));
|
var paths = args.Where(a => !a.StartsWith(@"-"));
|
||||||
Task.Run(() => BeatmapManager.Import(paths.ToArray()));
|
|
||||||
|
Task.Run(() => Import(paths.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies.CacheAs(this);
|
dependencies.CacheAs(this);
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
@ -30,7 +33,7 @@ using osu.Game.Rulesets.Scoring;
|
|||||||
|
|
||||||
namespace osu.Game
|
namespace osu.Game
|
||||||
{
|
{
|
||||||
public class OsuGameBase : Framework.Game, IOnlineComponent
|
public class OsuGameBase : Framework.Game, IOnlineComponent, ICanAcceptFiles
|
||||||
{
|
{
|
||||||
protected OsuConfigManager LocalConfig;
|
protected OsuConfigManager LocalConfig;
|
||||||
|
|
||||||
@ -114,6 +117,8 @@ namespace osu.Game
|
|||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(new OsuColour());
|
dependencies.Cache(new OsuColour());
|
||||||
|
|
||||||
|
fileImporters.Add(BeatmapManager);
|
||||||
|
|
||||||
//this completely overrides the framework default. will need to change once we make a proper FontStore.
|
//this completely overrides the framework default. will need to change once we make a proper FontStore.
|
||||||
dependencies.Cache(Fonts = new FontStore { ScaleAdjust = 100 });
|
dependencies.Cache(Fonts = new FontStore { ScaleAdjust = 100 });
|
||||||
|
|
||||||
@ -257,5 +262,17 @@ namespace osu.Game
|
|||||||
|
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>();
|
||||||
|
|
||||||
|
public void Import(params string[] paths)
|
||||||
|
{
|
||||||
|
var extension = Path.GetExtension(paths.First());
|
||||||
|
|
||||||
|
foreach (var importer in fileImporters)
|
||||||
|
if (importer.HandledExtensions.Contains(extension)) importer.Import(paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
@ -14,7 +15,7 @@ using SharpCompress.Compressors.LZMA;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Scoring
|
namespace osu.Game.Rulesets.Scoring
|
||||||
{
|
{
|
||||||
public class ScoreStore : DatabaseBackedStore
|
public class ScoreStore : DatabaseBackedStore, ICanAcceptFiles
|
||||||
{
|
{
|
||||||
private readonly Storage storage;
|
private readonly Storage storage;
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
|
|
||||||
private const string replay_folder = @"replays";
|
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)
|
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
|
||||||
private ScoreIPCChannel ipc;
|
private ScoreIPCChannel ipc;
|
||||||
|
|
||||||
@ -36,6 +39,18 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
ipc = new ScoreIPCChannel(importHost, this);
|
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)
|
public Score ReadReplayFile(string replayFilename)
|
||||||
{
|
{
|
||||||
Score score;
|
Score score;
|
||||||
@ -159,5 +174,6 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
|
|
||||||
return new Replay { Frames = frames };
|
return new Replay { Frames = frames };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@
|
|||||||
<Compile Include="Database\ArchiveModelManager.cs" />
|
<Compile Include="Database\ArchiveModelManager.cs" />
|
||||||
<Compile Include="Database\DatabaseContextFactory.cs" />
|
<Compile Include="Database\DatabaseContextFactory.cs" />
|
||||||
<Compile Include="Database\DatabaseWriteUsage.cs" />
|
<Compile Include="Database\DatabaseWriteUsage.cs" />
|
||||||
<Compile Include="Database\ICanImportArchives.cs" />
|
<Compile Include="Database\ICanAcceptFiles.cs" />
|
||||||
<Compile Include="Database\IDatabaseContextFactory.cs" />
|
<Compile Include="Database\IDatabaseContextFactory.cs" />
|
||||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||||
<Compile Include="Database\INamedFileInfo.cs" />
|
<Compile Include="Database\INamedFileInfo.cs" />
|
||||||
|
Reference in New Issue
Block a user