2020-06-11 11:57:29 +00: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.IO;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Tests;
|
2021-07-29 16:53:08 +00:00
|
|
|
using osu.Game.Tournament.Configuration;
|
2020-06-11 11:57:29 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests.NonVisual
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2021-07-29 16:53:08 +00:00
|
|
|
public class CustomTourneyDirectoryTest : TournamentHostTest
|
2020-06-11 11:57:29 +00:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestDefaultDirectory()
|
|
|
|
{
|
2021-12-24 11:17:20 +00:00
|
|
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
2020-06-11 11:57:29 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-07-29 16:53:08 +00:00
|
|
|
var osu = LoadTournament(host);
|
2020-06-24 00:37:59 +00:00
|
|
|
var storage = osu.Dependencies.Get<Storage>();
|
2020-10-19 06:34:46 +00:00
|
|
|
|
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(host.Storage.GetFullPath("."), "tournaments", "default")));
|
2020-06-11 11:57:29 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCustomDirectory()
|
|
|
|
{
|
2020-10-19 06:34:46 +00:00
|
|
|
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file.
|
2020-06-11 11:57:29 +00:00
|
|
|
{
|
2021-11-23 05:38:37 +00:00
|
|
|
string osuDesktopStorage = PrepareBasePath(nameof(TestCustomDirectory));
|
2020-06-11 11:57:29 +00:00
|
|
|
const string custom_tournament = "custom";
|
|
|
|
|
|
|
|
// need access before the game has constructed its own storage yet.
|
|
|
|
Storage storage = new DesktopStorage(osuDesktopStorage, host);
|
|
|
|
// manual cleaning so we can prepare a config file.
|
|
|
|
storage.DeleteDirectory(string.Empty);
|
|
|
|
|
|
|
|
using (var storageConfig = new TournamentStorageManager(storage))
|
2021-03-17 07:10:16 +00:00
|
|
|
storageConfig.SetValue(StorageConfig.CurrentTournament, custom_tournament);
|
2020-06-11 11:57:29 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-07-29 16:53:08 +00:00
|
|
|
var osu = LoadTournament(host);
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2020-06-24 00:37:59 +00:00
|
|
|
storage = osu.Dependencies.Get<Storage>();
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2020-10-19 06:34:46 +00:00
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(host.Storage.GetFullPath("."), "tournaments", custom_tournament)));
|
2020-06-11 11:57:29 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
2021-11-23 05:38:37 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Directory.Exists(osuDesktopStorage))
|
|
|
|
Directory.Delete(osuDesktopStorage, true);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
2020-06-11 11:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMigration()
|
|
|
|
{
|
2020-10-19 06:34:46 +00:00
|
|
|
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration.
|
2020-06-11 11:57:29 +00:00
|
|
|
{
|
2021-11-23 05:38:37 +00:00
|
|
|
string osuRoot = PrepareBasePath(nameof(TestMigration));
|
2020-06-22 10:22:59 +00:00
|
|
|
string configFile = Path.Combine(osuRoot, "tournament.ini");
|
|
|
|
|
|
|
|
if (File.Exists(configFile))
|
|
|
|
File.Delete(configFile);
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2020-06-22 10:22:59 +00:00
|
|
|
// Recreate the old setup that uses "tournament" as the base path.
|
2020-06-11 18:11:44 +00:00
|
|
|
string oldPath = Path.Combine(osuRoot, "tournament");
|
2020-06-28 13:27:50 +00:00
|
|
|
|
2021-11-28 15:14:12 +00:00
|
|
|
string videosPath = Path.Combine(oldPath, "Videos");
|
|
|
|
string modsPath = Path.Combine(oldPath, "Mods");
|
|
|
|
string flagsPath = Path.Combine(oldPath, "Flags");
|
2020-06-11 11:57:29 +00:00
|
|
|
|
|
|
|
Directory.CreateDirectory(videosPath);
|
|
|
|
Directory.CreateDirectory(modsPath);
|
|
|
|
Directory.CreateDirectory(flagsPath);
|
|
|
|
|
2020-06-11 18:11:44 +00:00
|
|
|
// Define testing files corresponding to the specific file migrations that are needed
|
2021-12-03 07:04:11 +00:00
|
|
|
string bracketFile = Path.Combine(osuRoot, TournamentGameBase.BRACKET_FILENAME);
|
2020-06-11 18:11:44 +00:00
|
|
|
|
|
|
|
string drawingsConfig = Path.Combine(osuRoot, "drawings.ini");
|
|
|
|
string drawingsFile = Path.Combine(osuRoot, "drawings.txt");
|
|
|
|
string drawingsResult = Path.Combine(osuRoot, "drawings_results.txt");
|
|
|
|
|
|
|
|
// Define sample files to test recursive copying
|
2020-06-11 11:57:29 +00:00
|
|
|
string videoFile = Path.Combine(videosPath, "video.mp4");
|
|
|
|
string modFile = Path.Combine(modsPath, "mod.png");
|
|
|
|
string flagFile = Path.Combine(flagsPath, "flag.png");
|
|
|
|
|
|
|
|
File.WriteAllText(bracketFile, "{}");
|
2020-06-11 18:11:44 +00:00
|
|
|
File.WriteAllText(drawingsConfig, "test");
|
|
|
|
File.WriteAllText(drawingsFile, "test");
|
|
|
|
File.WriteAllText(drawingsResult, "test");
|
2020-06-11 11:57:29 +00:00
|
|
|
File.WriteAllText(videoFile, "test");
|
|
|
|
File.WriteAllText(modFile, "test");
|
|
|
|
File.WriteAllText(flagFile, "test");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-07-29 16:53:08 +00:00
|
|
|
var osu = LoadTournament(host);
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2020-06-24 00:37:59 +00:00
|
|
|
var storage = osu.Dependencies.Get<Storage>();
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2020-10-19 06:34:46 +00:00
|
|
|
string migratedPath = Path.Combine(host.Storage.GetFullPath("."), "tournaments", "default");
|
2020-06-11 11:57:29 +00:00
|
|
|
|
2021-11-28 15:14:12 +00:00
|
|
|
videosPath = Path.Combine(migratedPath, "Videos");
|
|
|
|
modsPath = Path.Combine(migratedPath, "Mods");
|
|
|
|
flagsPath = Path.Combine(migratedPath, "Flags");
|
2020-06-11 11:57:29 +00:00
|
|
|
|
|
|
|
videoFile = Path.Combine(videosPath, "video.mp4");
|
|
|
|
modFile = Path.Combine(modsPath, "mod.png");
|
|
|
|
flagFile = Path.Combine(flagsPath, "flag.png");
|
|
|
|
|
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(migratedPath));
|
2020-06-11 18:11:44 +00:00
|
|
|
|
2021-12-03 07:04:11 +00:00
|
|
|
Assert.True(storage.Exists(TournamentGameBase.BRACKET_FILENAME));
|
2020-06-11 18:11:44 +00:00
|
|
|
Assert.True(storage.Exists("drawings.txt"));
|
|
|
|
Assert.True(storage.Exists("drawings_results.txt"));
|
|
|
|
|
2020-06-22 10:41:43 +00:00
|
|
|
Assert.True(storage.Exists("drawings.ini"));
|
2020-06-11 18:11:44 +00:00
|
|
|
|
2020-06-11 11:57:29 +00:00
|
|
|
Assert.True(storage.Exists(videoFile));
|
|
|
|
Assert.True(storage.Exists(modFile));
|
|
|
|
Assert.True(storage.Exists(flagFile));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
2021-11-23 05:38:37 +00:00
|
|
|
host.Exit();
|
|
|
|
|
2021-07-06 06:08:00 +00:00
|
|
|
try
|
|
|
|
{
|
2021-11-23 05:38:37 +00:00
|
|
|
if (Directory.Exists(osuRoot))
|
|
|
|
Directory.Delete(osuRoot, true);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2021-07-06 06:08:00 +00:00
|
|
|
}
|
2020-06-11 11:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 05:38:37 +00:00
|
|
|
public static string PrepareBasePath(string testInstance)
|
|
|
|
{
|
|
|
|
string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance);
|
|
|
|
|
|
|
|
// manually clean before starting in case there are left-over files at the test site.
|
|
|
|
if (Directory.Exists(basePath))
|
|
|
|
Directory.Delete(basePath, true);
|
|
|
|
|
|
|
|
return basePath;
|
|
|
|
}
|
2020-06-11 11:57:29 +00:00
|
|
|
}
|
2020-06-11 13:52:14 +00:00
|
|
|
}
|