2021-01-25 02:18:16 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.IO
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A storage pointing to an osu-stable installation.
|
|
|
|
|
/// Provides methods for handling installations with a custom Song folder location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StableStorage : DesktopStorage
|
|
|
|
|
{
|
2021-01-27 01:26:01 +08:00
|
|
|
|
private const string stable_default_songs_path = "Songs";
|
2021-01-25 02:18:16 +08:00
|
|
|
|
|
|
|
|
|
private readonly DesktopGameHost host;
|
2021-01-27 02:07:05 +08:00
|
|
|
|
private readonly Lazy<string> songsPath;
|
2021-01-25 02:18:16 +08:00
|
|
|
|
|
|
|
|
|
public StableStorage(string path, DesktopGameHost host)
|
|
|
|
|
: base(path, host)
|
|
|
|
|
{
|
|
|
|
|
this.host = host;
|
2021-01-27 02:07:05 +08:00
|
|
|
|
songsPath = new Lazy<string>(locateSongsDirectory);
|
2021-01-25 02:18:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a <see cref="Storage"/> pointing to the osu-stable Songs directory.
|
|
|
|
|
/// </summary>
|
2021-01-27 02:07:05 +08:00
|
|
|
|
public Storage GetSongStorage() => new DesktopStorage(songsPath.Value, host);
|
2021-01-25 02:18:16 +08:00
|
|
|
|
|
|
|
|
|
private string locateSongsDirectory()
|
|
|
|
|
{
|
2021-01-27 01:26:01 +08:00
|
|
|
|
var songsDirectoryPath = Path.Combine(BasePath, stable_default_songs_path);
|
2021-01-25 02:18:16 +08:00
|
|
|
|
|
2021-01-27 02:07:05 +08:00
|
|
|
|
var configFile = GetFiles(".", "osu!.*.cfg").FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (configFile == null)
|
|
|
|
|
return songsDirectoryPath;
|
|
|
|
|
|
|
|
|
|
using (var textReader = new StreamReader(GetStream(configFile)))
|
2021-01-25 02:18:16 +08:00
|
|
|
|
{
|
2021-01-27 02:07:05 +08:00
|
|
|
|
string line;
|
2021-01-25 02:18:16 +08:00
|
|
|
|
|
2021-01-27 02:07:05 +08:00
|
|
|
|
while ((line = textReader.ReadLine()) != null)
|
2021-01-25 02:18:16 +08:00
|
|
|
|
{
|
2021-01-27 02:07:05 +08:00
|
|
|
|
if (line.StartsWith("BeatmapDirectory", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var directory = line.Split('=')[1].TrimStart();
|
|
|
|
|
if (Path.IsPathFullyQualified(directory))
|
|
|
|
|
songsDirectoryPath = directory;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-25 02:18:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-26 02:05:16 +08:00
|
|
|
|
return songsDirectoryPath;
|
2021-01-25 02:18:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|