1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00
osu-lazer/osu.Game.Tests/Resources/TestResources.cs
Salman Ahmed 82fe99cf4a
Replace any potential usage of Environment.CurrentDirectory with a new RuntimeInfo.StartupDirectory
Using `Environment.CurrentDirectory` for storing / reading files is dangerous as the current directory is mutable and can be changed when performing a certain operation (like opening solutions in roslyn type reference builder for example).
2020-05-31 02:24:49 +03:00

32 lines
1.1 KiB
C#

// 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.IO;
using NUnit.Framework;
using osu.Framework;
using osu.Framework.IO.Stores;
namespace osu.Game.Tests.Resources
{
public static class TestResources
{
public static DllResourceStore GetStore() => new DllResourceStore(typeof(TestResources).Assembly);
public static Stream OpenResource(string name) => GetStore().GetStream($"Resources/{name}");
public static Stream GetTestBeatmapStream(bool virtualTrack = false) => OpenResource($"Archives/241526 Soleily - Renatus{(virtualTrack ? "_virtual" : "")}.osz");
public static string GetTestBeatmapForImport(bool virtualTrack = false)
{
var temp = Path.GetTempFileName() + ".osz";
using (var stream = GetTestBeatmapStream(virtualTrack))
using (var newFile = RuntimeInfo.StartupStorage.GetStream(temp, FileAccess.Write))
stream.CopyTo(newFile);
Assert.IsTrue(RuntimeInfo.StartupStorage.Exists(temp));
return temp;
}
}
}