mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 05:53:10 +08:00
Update in line with framework storage changes
This commit is contained in:
parent
5edabbdee2
commit
7781408643
@ -6,15 +6,14 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
using osu.Desktop.Overlays;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
using osuTK.Input;
|
||||
using Microsoft.Win32;
|
||||
using osu.Desktop.Updater;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform.Windows;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Updater;
|
||||
@ -37,7 +36,11 @@ namespace osu.Desktop
|
||||
try
|
||||
{
|
||||
if (Host is DesktopGameHost desktopHost)
|
||||
return new StableStorage(desktopHost);
|
||||
{
|
||||
string stablePath = getStableInstallPath();
|
||||
if (!string.IsNullOrEmpty(stablePath))
|
||||
return new DesktopStorage(stablePath, desktopHost);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -47,6 +50,35 @@ namespace osu.Desktop
|
||||
return null;
|
||||
}
|
||||
|
||||
private string getStableInstallPath()
|
||||
{
|
||||
static bool checkExists(string p) => Directory.Exists(Path.Combine(p, "Songs"));
|
||||
|
||||
string stableInstallPath;
|
||||
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("osu"))
|
||||
stableInstallPath = key?.OpenSubKey(@"shell\open\command")?.GetValue(string.Empty).ToString().Split('"')[1].Replace("osu!.exe", "");
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override UpdateManager CreateUpdateManager()
|
||||
{
|
||||
switch (RuntimeInfo.OS)
|
||||
@ -111,45 +143,5 @@ namespace osu.Desktop
|
||||
|
||||
Task.Factory.StartNew(() => Import(filePaths), TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A method of accessing an osu-stable install in a controlled fashion.
|
||||
/// </summary>
|
||||
private class StableStorage : WindowsStorage
|
||||
{
|
||||
protected override string LocateBasePath()
|
||||
{
|
||||
static bool checkExists(string p) => Directory.Exists(Path.Combine(p, "Songs"));
|
||||
|
||||
string stableInstallPath;
|
||||
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("osu"))
|
||||
stableInstallPath = key?.OpenSubKey(@"shell\open\command")?.GetValue(string.Empty).ToString().Split('"')[1].Replace("osu!.exe", "");
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StableStorage(DesktopGameHost host)
|
||||
: base(string.Empty, host)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ using Microsoft.Win32;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Platform.Windows;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
@ -52,7 +51,12 @@ namespace osu.Game.Tournament.IPC
|
||||
|
||||
try
|
||||
{
|
||||
Storage = new StableStorage(host as DesktopGameHost);
|
||||
var path = findStablePath();
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return null;
|
||||
|
||||
Storage = new DesktopStorage(path, host as DesktopGameHost);
|
||||
|
||||
const string file_ipc_filename = "ipc.txt";
|
||||
const string file_ipc_state_filename = "ipc-state.txt";
|
||||
@ -145,64 +149,50 @@ namespace osu.Game.Tournament.IPC
|
||||
return Storage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A method of accessing an osu-stable install in a controlled fashion.
|
||||
/// </summary>
|
||||
private class StableStorage : WindowsStorage
|
||||
private string findStablePath()
|
||||
{
|
||||
protected override string LocateBasePath()
|
||||
{
|
||||
static bool checkExists(string p)
|
||||
{
|
||||
return File.Exists(Path.Combine(p, "ipc.txt"));
|
||||
}
|
||||
static bool checkExists(string p) => File.Exists(Path.Combine(p, "ipc.txt"));
|
||||
|
||||
string stableInstallPath = string.Empty;
|
||||
string stableInstallPath = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
stableInstallPath = Environment.GetEnvironmentVariable("OSU_STABLE_PATH");
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
stableInstallPath = Environment.GetEnvironmentVariable("OSU_STABLE_PATH");
|
||||
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("osu"))
|
||||
stableInstallPath = key?.OpenSubKey(@"shell\open\command")?.GetValue(string.Empty).ToString().Split('"')[1].Replace("osu!.exe", "");
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("osu"))
|
||||
stableInstallPath = key?.OpenSubKey(@"shell\open\command")?.GetValue(string.Empty).ToString().Split('"')[1].Replace("osu!.exe", "");
|
||||
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
catch
|
||||
{
|
||||
Logger.Log($"Stable path for tourney usage: {stableInstallPath}");
|
||||
}
|
||||
}
|
||||
|
||||
public StableStorage(DesktopGameHost host)
|
||||
: base(string.Empty, host)
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
||||
if (checkExists(stableInstallPath))
|
||||
return stableInstallPath;
|
||||
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Logger.Log($"Stable path for tourney usage: {stableInstallPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
osu.Game/IO/OsuStorage.cs
Normal file
26
osu.Game/IO/OsuStorage.cs
Normal file
@ -0,0 +1,26 @@
|
||||
// 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 osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Configuration;
|
||||
|
||||
namespace osu.Game.IO
|
||||
{
|
||||
public class OsuStorage : WrappedStorage
|
||||
{
|
||||
public OsuStorage(GameHost host)
|
||||
: base(host.Storage, string.Empty)
|
||||
{
|
||||
var storageConfig = new StorageConfigManager(host.Storage);
|
||||
|
||||
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
|
||||
|
||||
if (!string.IsNullOrEmpty(customStoragePath))
|
||||
{
|
||||
ChangeTargetStorage(host.GetStorage(customStoragePath));
|
||||
Logger.Storage = UnderlyingStorage.GetStorageForDirectory("logs");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
80
osu.Game/IO/WrappedStorage.cs
Normal file
80
osu.Game/IO/WrappedStorage.cs
Normal file
@ -0,0 +1,80 @@
|
||||
// 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 osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// A storage which wraps another storage and delegates implementation, potentially mutating the lookup path.
|
||||
/// </summary>
|
||||
public class WrappedStorage : Storage
|
||||
{
|
||||
protected Storage UnderlyingStorage { get; private set; }
|
||||
|
||||
private readonly string subPath;
|
||||
|
||||
public WrappedStorage(Storage underlyingStorage, string subPath = null)
|
||||
: base(string.Empty)
|
||||
{
|
||||
ChangeTargetStorage(underlyingStorage);
|
||||
|
||||
this.subPath = subPath;
|
||||
}
|
||||
|
||||
protected virtual string MutatePath(string path) => !string.IsNullOrEmpty(subPath) ? Path.Combine(subPath, path) : path;
|
||||
|
||||
protected void ChangeTargetStorage(Storage newStorage)
|
||||
{
|
||||
UnderlyingStorage = newStorage;
|
||||
}
|
||||
|
||||
public override string GetFullPath(string path, bool createIfNotExisting = false) =>
|
||||
UnderlyingStorage.GetFullPath(MutatePath(path), createIfNotExisting);
|
||||
|
||||
public override bool Exists(string path) =>
|
||||
UnderlyingStorage.Exists(MutatePath(path));
|
||||
|
||||
public override bool ExistsDirectory(string path) =>
|
||||
UnderlyingStorage.ExistsDirectory(MutatePath(path));
|
||||
|
||||
public override void DeleteDirectory(string path) =>
|
||||
UnderlyingStorage.DeleteDirectory(MutatePath(path));
|
||||
|
||||
public override void Delete(string path) =>
|
||||
UnderlyingStorage.Delete(MutatePath(path));
|
||||
|
||||
public override IEnumerable<string> GetDirectories(string path) =>
|
||||
UnderlyingStorage.GetDirectories(MutatePath(path));
|
||||
|
||||
public override IEnumerable<string> GetFiles(string path, string pattern = "*") =>
|
||||
UnderlyingStorage.GetFiles(MutatePath(path), pattern);
|
||||
|
||||
public override Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate) =>
|
||||
UnderlyingStorage.GetStream(MutatePath(path), access, mode);
|
||||
|
||||
public override string GetDatabaseConnectionString(string name) =>
|
||||
UnderlyingStorage.GetDatabaseConnectionString(MutatePath(name));
|
||||
|
||||
public override void DeleteDatabase(string name) => UnderlyingStorage.DeleteDatabase(MutatePath(name));
|
||||
|
||||
public override void OpenInNativeExplorer() => UnderlyingStorage.OpenInNativeExplorer();
|
||||
|
||||
public override Storage GetStorageForDirectory(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
throw new ArgumentException("Must be non-null and not empty string", nameof(path));
|
||||
|
||||
if (!path.EndsWith(Path.DirectorySeparatorChar))
|
||||
path += Path.DirectorySeparatorChar;
|
||||
|
||||
// create non-existing path.
|
||||
GetFullPath(path, true);
|
||||
|
||||
return new WrappedStorage(this, path);
|
||||
}
|
||||
}
|
||||
}
|
@ -71,8 +71,6 @@ namespace osu.Game
|
||||
|
||||
protected MenuCursorContainer MenuCursorContainer;
|
||||
|
||||
protected StorageConfigManager StorageConfig;
|
||||
|
||||
private Container content;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
@ -304,17 +302,7 @@ namespace osu.Game
|
||||
{
|
||||
base.SetHost(host);
|
||||
|
||||
StorageConfig = new StorageConfigManager(host.Storage);
|
||||
|
||||
var customStoragePath = StorageConfig.Get<string>(Configuration.StorageConfig.FullPath);
|
||||
|
||||
if (!string.IsNullOrEmpty(customStoragePath))
|
||||
{
|
||||
Storage = new CustomStorage(customStoragePath, host);
|
||||
Logger.Storage = Storage.GetStorageForDirectory("logs");
|
||||
}
|
||||
else
|
||||
Storage = host.Storage;
|
||||
Storage = new OsuStorage(host);
|
||||
|
||||
if (LocalConfig == null)
|
||||
LocalConfig = new OsuConfigManager(Storage);
|
||||
@ -366,17 +354,5 @@ namespace osu.Game
|
||||
public override bool ChangeFocusOnClick => false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A storage pointing to an absolute location specified by the user to store game data files.
|
||||
/// </summary>
|
||||
private class CustomStorage : NativeStorage
|
||||
{
|
||||
public CustomStorage(string fullPath, GameHost host)
|
||||
: base(string.Empty, host)
|
||||
{
|
||||
BasePath = fullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user