Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic setup switching for the tournament client #9256

Merged
merged 65 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
17cd956
Introduce new storage class and manager
MiraiSubject Jun 7, 2020
9a20ffa
Rename to TournamentStorage
MiraiSubject Jun 7, 2020
ba5a747
Implement migration for TournamentStorage
MiraiSubject Jun 8, 2020
f01a86f
Fix styling issues and move StorageManager to Configuration Folder
MiraiSubject Jun 8, 2020
ce66b72
Refactor paths
MiraiSubject Jun 8, 2020
d2ae146
Remove unnecessary parameters and implement delete
MiraiSubject Jun 8, 2020
2f15d7f
Code styling fixes
MiraiSubject Jun 8, 2020
4179193
change namespace to osu.Game.Tournament.IO
MiraiSubject Jun 9, 2020
c2e01e1
Rename tournamentStorage to storage
MiraiSubject Jun 11, 2020
b69ff30
Fixed migration logic
MiraiSubject Jun 11, 2020
18a9e5a
Add NonVisual tests for custom tournaments
MiraiSubject Jun 11, 2020
a317b85
Remove misleading log
MiraiSubject Jun 11, 2020
5d49b70
Change access modifier public -> internal
MiraiSubject Jun 11, 2020
2964b45
Rename VideoStorage to VideoStore
MiraiSubject Jun 11, 2020
af1bbe7
move TournamentVideoResourceStore to separate file
MiraiSubject Jun 11, 2020
883185d
Add a comment to describe what's going on before the headless game st…
MiraiSubject Jun 11, 2020
603054f
Remove unused property and reuse tournamentBasePath
MiraiSubject Jun 11, 2020
222ac86
Add newlines at the end of the file
MiraiSubject Jun 11, 2020
1d4d749
Undo blank line removal
MiraiSubject Jun 11, 2020
c9dc17f
Introduce migrations for drawings
MiraiSubject Jun 11, 2020
327795b
Switch drawing storage to tournamentstorage
MiraiSubject Jun 11, 2020
32d86d6
Create storage for config files of a tournament
MiraiSubject Jun 11, 2020
592e3bf
Implement migrations for the drawings config file
MiraiSubject Jun 11, 2020
56a40e6
Add drawings to the migration test
MiraiSubject Jun 11, 2020
5ef3a3f
Merge branch 'master' into tourney-asset-refactor
peppy Jun 12, 2020
5041c74
Fix merge issue
peppy Jun 12, 2020
29ae1c4
TournamentStorage now takes in a parent storage
MiraiSubject Jun 16, 2020
b75fd7b
Refactor moving logic (1/2)
MiraiSubject Jun 16, 2020
02d66c4
Refactor moving (2/2)
MiraiSubject Jun 16, 2020
dd96970
Introduce new class MigratableStorage
MiraiSubject Jun 16, 2020
21774b8
Move static properties to parent class and inherit OsuStorage from it
MiraiSubject Jun 22, 2020
f878388
Fix TestMigrationToSeeminglyNestedTarget failing
MiraiSubject Jun 22, 2020
291dadf
Merge branch 'master' of https://github.com/ppy/osu into tourney-asse…
MiraiSubject Jun 22, 2020
eec1e9e
Remove unnecessary comments and added file check for tournament.ini o…
MiraiSubject Jun 22, 2020
08759da
Move drawings.ini out of config subfolder
MiraiSubject Jun 22, 2020
6b14079
InspectCode changes
MiraiSubject Jun 22, 2020
a94dcc4
Add xmldoc to MigratableStorage
MiraiSubject Jun 22, 2020
e0d5a91
make tournament migration private
MiraiSubject Jun 22, 2020
a899c75
Remove whitespace at the end of xmldoc line
MiraiSubject Jun 22, 2020
a47d34f
make ignore properties protected virtual get-only in base
MiraiSubject Jun 23, 2020
8b9cf6f
Remove default value in Storagemgr
MiraiSubject Jun 23, 2020
8e8458a
make migrate public abstract in base and override
MiraiSubject Jun 23, 2020
7a3315d
invert and early return
MiraiSubject Jun 23, 2020
0ca8c96
Remove string interpolation & unnecessary test setup
MiraiSubject Jun 23, 2020
e5851be
change accessor from internal readonly to public get-only
MiraiSubject Jun 23, 2020
9d2392b
Cache TournamentStorage as Storage and only cast when necessary
MiraiSubject Jun 23, 2020
c32ef5e
Address formatting issues
MiraiSubject Jun 23, 2020
af11340
Fix nullref exceptions and redundant explicit type
MiraiSubject Jun 24, 2020
839f197
Change type from TournamentStorage to Storage in tests
MiraiSubject Jun 24, 2020
c94f95c
Check if the file exists before reading
MiraiSubject Jun 24, 2020
063503f
Move null check outside of the loop
MiraiSubject Jun 24, 2020
47a732e
Address review comments
MiraiSubject Jun 24, 2020
d82d901
Reuse custom_tournament where it was still used as a literal
MiraiSubject Jun 25, 2020
9639ebd
Merge branch 'master' into tourney-asset-refactor
MiraiSubject Jun 28, 2020
0cddb85
Move storageconfig set and saving to migrate method
MiraiSubject Jun 28, 2020
c3cd2a7
Move general purpose migration to MigratableStorage
MiraiSubject Jul 1, 2020
66e61aa
Logger now shows the actual path of the destination
MiraiSubject Jul 1, 2020
c167727
Merge branch 'master' into tourney-asset-refactor
MiraiSubject Aug 8, 2020
1989141
Merge branch 'master' into tourney-asset-refactor
peppy Oct 7, 2020
f218a32
Merge branch 'master' into tourney-asset-refactor
peppy Oct 19, 2020
7ed862e
Add comment about migration code
peppy Oct 19, 2020
9c566e7
Update tests to use correct parameters of CleanRunGameHost
peppy Oct 19, 2020
31f6051
Add missing xmldoc
peppy Oct 19, 2020
3f41003
Move video store out of TournamentStorage
peppy Oct 19, 2020
daceb0c
Fix texture store not being initialised correctly
peppy Oct 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move general purpose migration to MigratableStorage
  • Loading branch information
MiraiSubject committed Jul 1, 2020
commit c3cd2a74f5f0ee89e531d564db3d7a5cb9e3ed04
10 changes: 4 additions & 6 deletions osu.Game.Tournament/IO/TournamentStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ public TournamentStorage(Storage storage)
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(storageConfig.Get<string>(StorageConfig.CurrentTournament)));
}
else
{
Migrate(GetFullPath(default_tournament));
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(default_tournament));
}
Migrate(UnderlyingStorage.GetStorageForDirectory(default_tournament));

VideoStore = new TournamentVideoResourceStore(this);
Logger.Log("Using tournament storage: " + GetFullPath(string.Empty));
}

public override void Migrate(string newLocation)
public override void Migrate(Storage newStorage)
{
var source = new DirectoryInfo(storage.GetFullPath("tournament"));
var destination = new DirectoryInfo(newLocation);
var destination = new DirectoryInfo(newStorage.GetFullPath("."));

if (source.Exists)
{
Expand All @@ -53,6 +50,7 @@ public override void Migrate(string newLocation)
moveFileIfExists("drawings.txt", destination);
moveFileIfExists("drawings_results.txt", destination);
moveFileIfExists("drawings.ini", destination);
ChangeTargetStorage(newStorage);
storageConfig.Set(StorageConfig.CurrentTournament, default_tournament);
storageConfig.Save();
}
Expand Down
31 changes: 30 additions & 1 deletion osu.Game/IO/MigratableStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,36 @@ protected MigratableStorage(Storage storage, string subPath = null)
{
}

public abstract void Migrate(string newLocation);
/// <summary>
/// A general purpose migration method to move the storage to a different location.
/// <param name="newStorage">The target storage of the migration.</param>
/// </summary>
public virtual void Migrate(Storage newStorage)
{
var source = new DirectoryInfo(GetFullPath("."));
var destination = new DirectoryInfo(newStorage.GetFullPath("."));

// using Uri is the easiest way to check equality and contains (https://stackoverflow.com/a/7710620)
var sourceUri = new Uri(source.FullName + Path.DirectorySeparatorChar);
var destinationUri = new Uri(destination.FullName + Path.DirectorySeparatorChar);

if (sourceUri == destinationUri)
throw new ArgumentException("Destination provided is already the current location", nameof(newStorage));

if (sourceUri.IsBaseOf(destinationUri))
throw new ArgumentException("Destination provided is inside the source", nameof(newStorage));

// ensure the new location has no files present, else hard abort
if (destination.Exists)
{
if (destination.GetFiles().Length > 0 || destination.GetDirectories().Length > 0)
throw new ArgumentException("Destination provided already has files or directories present", nameof(newStorage));
}

CopyRecursive(source, destination);
ChangeTargetStorage(newStorage);
DeleteRecursive(source);
}

protected void DeleteRecursive(DirectoryInfo target, bool topLevelExcludes = true)
{
Expand Down
36 changes: 3 additions & 33 deletions osu.Game/IO/OsuStorage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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 osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Configuration;
Expand All @@ -11,7 +9,6 @@ namespace osu.Game.IO
{
public class OsuStorage : MigratableStorage
{
private readonly GameHost host;
private readonly StorageConfigManager storageConfig;

public override string[] IgnoreDirectories => new[] { "cache" };
Expand All @@ -25,8 +22,6 @@ public class OsuStorage : MigratableStorage
public OsuStorage(GameHost host)
: base(host.Storage, string.Empty)
{
this.host = host;

storageConfig = new StorageConfigManager(host.Storage);

var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
Expand All @@ -41,36 +36,11 @@ protected override void ChangeTargetStorage(Storage newStorage)
Logger.Storage = UnderlyingStorage.GetStorageForDirectory("logs");
}

public override void Migrate(string newLocation)
public override void Migrate(Storage newStorage)
{
var source = new DirectoryInfo(GetFullPath("."));
var destination = new DirectoryInfo(newLocation);

// using Uri is the easiest way to check equality and contains (https://stackoverflow.com/a/7710620)
var sourceUri = new Uri(source.FullName + Path.DirectorySeparatorChar);
var destinationUri = new Uri(destination.FullName + Path.DirectorySeparatorChar);

if (sourceUri == destinationUri)
throw new ArgumentException("Destination provided is already the current location", nameof(newLocation));

if (sourceUri.IsBaseOf(destinationUri))
throw new ArgumentException("Destination provided is inside the source", nameof(newLocation));

// ensure the new location has no files present, else hard abort
if (destination.Exists)
{
if (destination.GetFiles().Length > 0 || destination.GetDirectories().Length > 0)
throw new ArgumentException("Destination provided already has files or directories present", nameof(newLocation));
}

CopyRecursive(source, destination);

ChangeTargetStorage(host.GetStorage(newLocation));

storageConfig.Set(StorageConfig.FullPath, newLocation);
base.Migrate(newStorage);
storageConfig.Set(StorageConfig.FullPath, newStorage.GetFullPath("."));
storageConfig.Save();

DeleteRecursive(source);
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public RightMouseManager(MouseButton button)
public void Migrate(string path)
{
contextFactory.FlushConnections();
(Storage as OsuStorage)?.Migrate(path);
(Storage as OsuStorage)?.Migrate(Host.GetStorage(path));
}
}
}