mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 06:12:56 +08:00
Update StableStorage implementation in line with framework changes
This commit is contained in:
parent
b6f232e394
commit
d6840d880a
@ -6,15 +6,14 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Win32;
|
||||||
using osu.Desktop.Overlays;
|
using osu.Desktop.Overlays;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game;
|
using osu.Game;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using Microsoft.Win32;
|
|
||||||
using osu.Desktop.Updater;
|
using osu.Desktop.Updater;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform.Windows;
|
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osu.Game.Updater;
|
using osu.Game.Updater;
|
||||||
@ -37,7 +36,11 @@ namespace osu.Desktop
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Host is DesktopGameHost desktopHost)
|
if (Host is DesktopGameHost desktopHost)
|
||||||
return new StableStorage(desktopHost);
|
{
|
||||||
|
string stablePath = getStableInstallPath();
|
||||||
|
if (!string.IsNullOrEmpty(stablePath))
|
||||||
|
return new DesktopStorage(stablePath, desktopHost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@ -47,6 +50,35 @@ namespace osu.Desktop
|
|||||||
return null;
|
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()
|
protected override UpdateManager CreateUpdateManager()
|
||||||
{
|
{
|
||||||
switch (RuntimeInfo.OS)
|
switch (RuntimeInfo.OS)
|
||||||
@ -111,45 +143,5 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
Task.Factory.StartNew(() => Import(filePaths), TaskCreationOptions.LongRunning);
|
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.Allocation;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Platform.Windows;
|
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Legacy;
|
using osu.Game.Beatmaps.Legacy;
|
||||||
@ -52,7 +51,12 @@ namespace osu.Game.Tournament.IPC
|
|||||||
|
|
||||||
try
|
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_filename = "ipc.txt";
|
||||||
const string file_ipc_state_filename = "ipc-state.txt";
|
const string file_ipc_state_filename = "ipc-state.txt";
|
||||||
@ -145,64 +149,50 @@ namespace osu.Game.Tournament.IPC
|
|||||||
return Storage;
|
return Storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private string findStablePath()
|
||||||
/// 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) => File.Exists(Path.Combine(p, "ipc.txt"));
|
||||||
{
|
|
||||||
static bool checkExists(string p)
|
|
||||||
{
|
|
||||||
return 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
|
||||||
{
|
{
|
||||||
try
|
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("osu"))
|
||||||
{
|
stableInstallPath = key?.OpenSubKey(@"shell\open\command")?.GetValue(string.Empty).ToString().Split('"')[1].Replace("osu!.exe", "");
|
||||||
stableInstallPath = Environment.GetEnvironmentVariable("OSU_STABLE_PATH");
|
|
||||||
|
|
||||||
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))
|
if (checkExists(stableInstallPath))
|
||||||
return 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)
|
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
||||||
: base(string.Empty, host)
|
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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user