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

Adjust user storage paths for better cross-platform support #6196

Merged
merged 3 commits into from
Feb 23, 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
7 changes: 3 additions & 4 deletions osu.Framework.Android/AndroidGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Android.Input;
using osu.Framework.Configuration;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Video;
Expand Down Expand Up @@ -67,11 +68,9 @@ protected override IEnumerable<InputHandler> CreateAvailableInputHandlers() =>

public override Storage GetStorage(string path) => new AndroidStorage(path, this);

public override IEnumerable<string> UserStoragePaths => new[]
{
public override IEnumerable<string> UserStoragePaths
// not null as internal "external storage" is always available.
Application.Context.GetExternalFilesDir(string.Empty).AsNonNull().ToString(),
};
=> Application.Context.GetExternalFilesDir(string.Empty).AsNonNull().ToString().Yield();

public override bool OpenFileExternally(string filename) => false;

Expand Down
4 changes: 3 additions & 1 deletion osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ public abstract class GameHost : IIpcHost, IDisposable
/// <summary>
/// All valid user storage paths in order of usage priority.
/// </summary>
public virtual IEnumerable<string> UserStoragePaths => Environment.GetFolderPath(Environment.SpecialFolder.Personal).Yield();
public virtual IEnumerable<string> UserStoragePaths
// This is common to _most_ operating systems, with some specific ones overriding this value where a better option exists.
=> Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create).Yield();

/// <summary>
/// The main storage as proposed by the host game.
Expand Down
18 changes: 0 additions & 18 deletions osu.Framework/Platform/Linux/LinuxGameHost.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using SDL2;
using osu.Framework.Input;
Expand Down Expand Up @@ -35,22 +33,6 @@ protected override void SetupForRun()
base.SetupForRun();
}

public override IEnumerable<string> UserStoragePaths
{
get
{
string? xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");

if (!string.IsNullOrEmpty(xdg))
yield return xdg;

yield return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");

foreach (string path in base.UserStoragePaths)
yield return path;
}
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new SDL2DesktopWindow(preferredSurface);

protected override ReadableKeyCombinationProvider CreateReadableKeyCombinationProvider() => new LinuxReadableKeyCombinationProvider();
Expand Down
12 changes: 3 additions & 9 deletions osu.Framework/Platform/MacOS/MacOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ public override IEnumerable<string> UserStoragePaths
{
get
{
yield return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support");

string xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");

if (!string.IsNullOrEmpty(xdg))
yield return xdg;

yield return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mean that any users which had data at this local will end up with a new install, right? I know that my data was here for some period (it may have been an older default we used in lazer itself).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that true. Can add this back just for macOS.


foreach (string path in base.UserStoragePaths)
yield return path;

// Some older builds of osu! incorrectly used ~/.local/share on macOS.
yield return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
}
}

Expand Down
6 changes: 3 additions & 3 deletions osu.Framework/Platform/Windows/WindowsGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class WindowsGameHost : DesktopGameHost

protected override ReadableKeyCombinationProvider CreateReadableKeyCombinationProvider() => new WindowsReadableKeyCombinationProvider();

public override IEnumerable<string> UserStoragePaths =>
// on windows this is guaranteed to exist (and be usable) so don't fallback to the base/default.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Yield();
public override IEnumerable<string> UserStoragePaths
// The base implementation returns %LOCALAPPDATA%, but %APPDATA% is a better default on Windows.
=> Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create).Yield();

public override bool CapsLockEnabled => Console.CapsLock;

Expand Down
Loading