Skip to content

Commit

Permalink
Merge pull request #6196 from smoogipoo/fix-data-path
Browse files Browse the repository at this point in the history
Adjust user storage paths for better cross-platform support
  • Loading branch information
peppy committed Feb 23, 2024
2 parents 781db0a + 871f738 commit 82cc944
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 35 deletions.
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 void SetupConfig(IDictionary<FrameworkSetting, object> defaul

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");

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

0 comments on commit 82cc944

Please sign in to comment.