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

Remove "leftover files" notification when migration partly fails #29562

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions osu.Game/Localisation/MaintenanceSettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public static class MaintenanceSettingsStrings
/// </summary>
public static LocalisableString ProhibitedInteractDuringMigration => new TranslatableString(getKey(@"prohibited_interact_during_migration"), @"Please avoid interacting with the game!");

/// <summary>
/// "Some files couldn't be cleaned up during migration. Clicking this notification will open the folder so you can manually clean things up."
/// </summary>
public static LocalisableString FailedCleanupNotification => new TranslatableString(getKey(@"failed_cleanup_notification"), @"Some files couldn't be cleaned up during migration. Clicking this notification will open the folder so you can manually clean things up.");

/// <summary>
/// "Please select a new location"
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ public virtual void AttemptExit()
/// <returns>Whether a restart operation was queued.</returns>
public virtual bool RestartAppWhenExited() => false;

/// <summary>
/// Perform migration of user data to a specified path.
/// </summary>
/// <param name="path">The path to migrate to.</param>
/// <returns>Whether migration succeeded to completion. If <c>false</c>, some files were left behind.</returns>
/// <exception cref="TimeoutException"></exception>
public bool Migrate(string path)
{
Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""...");
Expand Down Expand Up @@ -542,10 +548,10 @@ public bool Migrate(string path)
if (!readyToRun.Wait(30000) || !success)
throw new TimeoutException("Attempting to block for migration took too long.");

bool? cleanupSucceded = (Storage as OsuStorage)?.Migrate(Host.GetStorage(path));
bool? cleanupSucceeded = (Storage as OsuStorage)?.Migrate(Host.GetStorage(path));

Logger.Log(@"Migration complete!");
return cleanupSucceded != false;
return cleanupSucceeded != false;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
using System.IO;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays.Notifications;
using osu.Game.Screens;
using osuTK;

Expand All @@ -29,15 +26,6 @@ public partial class MigrationRunScreen : OsuScreen
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }

[Resolved]
private INotificationOverlay notifications { get; set; }

[Resolved]
private Storage storage { get; set; }

[Resolved]
private GameHost host { get; set; }

public override bool AllowBackButton => false;

public override bool AllowExternalScreenChange => false;
Expand Down Expand Up @@ -99,27 +87,13 @@ protected override void LoadComplete()

Beatmap.Value = Beatmap.Default;

var originalStorage = new NativeStorage(storage.GetFullPath(string.Empty), host);

migrationTask = Task.Run(PerformMigration)
.ContinueWith(task =>
{
if (task.IsFaulted)
{
Logger.Error(task.Exception, $"Error during migration: {task.Exception?.Message}");
}
else if (!task.GetResultSafely())
{
notifications.Post(new SimpleNotification
{
Text = MaintenanceSettingsStrings.FailedCleanupNotification,
Activated = () =>
{
originalStorage.PresentExternally();
return true;
}
});
}

Schedule(this.Exit);
});
Expand Down
Loading