mirror of
https://github.com/ppy/osu
synced 2024-12-27 01:12:45 +00:00
Use a lazy for delegating Songs directory locating until it is actually used.
This commit is contained in:
parent
043385f919
commit
2a2b6f347e
@ -17,32 +17,36 @@ namespace osu.Game.IO
|
|||||||
private const string stable_default_songs_path = "Songs";
|
private const string stable_default_songs_path = "Songs";
|
||||||
|
|
||||||
private readonly DesktopGameHost host;
|
private readonly DesktopGameHost host;
|
||||||
private readonly string songsPath;
|
private readonly Lazy<string> songsPath;
|
||||||
|
|
||||||
public StableStorage(string path, DesktopGameHost host)
|
public StableStorage(string path, DesktopGameHost host)
|
||||||
: base(path, host)
|
: base(path, host)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
songsPath = locateSongsDirectory();
|
songsPath = new Lazy<string>(locateSongsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="Storage"/> pointing to the osu-stable Songs directory.
|
/// Returns a <see cref="Storage"/> pointing to the osu-stable Songs directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Storage GetSongStorage() => new DesktopStorage(songsPath, host);
|
public Storage GetSongStorage() => new DesktopStorage(songsPath.Value, host);
|
||||||
|
|
||||||
private string locateSongsDirectory()
|
private string locateSongsDirectory()
|
||||||
{
|
{
|
||||||
var configFile = GetStream(GetFiles(".", "osu!.*.cfg").First());
|
|
||||||
var textReader = new StreamReader(configFile);
|
|
||||||
|
|
||||||
var songsDirectoryPath = Path.Combine(BasePath, stable_default_songs_path);
|
var songsDirectoryPath = Path.Combine(BasePath, stable_default_songs_path);
|
||||||
|
|
||||||
while (!textReader.EndOfStream)
|
var configFile = GetFiles(".", "osu!.*.cfg").FirstOrDefault();
|
||||||
{
|
|
||||||
var line = textReader.ReadLine();
|
|
||||||
|
|
||||||
if (line?.StartsWith("BeatmapDirectory", StringComparison.OrdinalIgnoreCase) == true)
|
if (configFile == null)
|
||||||
|
return songsDirectoryPath;
|
||||||
|
|
||||||
|
using (var textReader = new StreamReader(GetStream(configFile)))
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
|
||||||
|
while ((line = textReader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
if (line.StartsWith("BeatmapDirectory", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var directory = line.Split('=')[1].TrimStart();
|
var directory = line.Split('=')[1].TrimStart();
|
||||||
if (Path.IsPathFullyQualified(directory))
|
if (Path.IsPathFullyQualified(directory))
|
||||||
@ -51,6 +55,7 @@ namespace osu.Game.IO
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return songsDirectoryPath;
|
return songsDirectoryPath;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user