Allow auto-detect to work after choosing manually

This commit is contained in:
Bartłomiej Dach
2020-06-13 15:27:46 +02:00
parent 586d5791e0
commit 992aa0041e
2 changed files with 38 additions and 29 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.Win32; using Microsoft.Win32;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Logging; using osu.Framework.Logging;
@ -21,6 +22,8 @@ namespace osu.Game.Tournament.IPC
{ {
public class FileBasedIPC : MatchIPCInfo public class FileBasedIPC : MatchIPCInfo
{ {
public Storage IPCStorage { get; private set; }
[Resolved] [Resolved]
protected IAPIProvider API { get; private set; } protected IAPIProvider API { get; private set; }
@ -36,22 +39,22 @@ namespace osu.Game.Tournament.IPC
[Resolved] [Resolved]
private StableInfo stableInfo { get; set; } private StableInfo stableInfo { get; set; }
[Resolved]
private Storage tournamentStorage { get; set; }
private int lastBeatmapId; private int lastBeatmapId;
private ScheduledDelegate scheduled; private ScheduledDelegate scheduled;
private GetBeatmapRequest beatmapLookupRequest; private GetBeatmapRequest beatmapLookupRequest;
public Storage IPCStorage { get; private set; }
[Resolved]
private Storage tournamentStorage { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
LocateStableStorage(); var stablePath = stableInfo.StablePath ?? findStablePath();
initialiseIPCStorage(stablePath);
} }
public Storage LocateStableStorage() [CanBeNull]
private Storage initialiseIPCStorage(string path)
{ {
scheduled?.Cancel(); scheduled?.Cancel();
@ -59,8 +62,6 @@ namespace osu.Game.Tournament.IPC
try try
{ {
var path = findStablePath();
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
return null; return null;
@ -159,13 +160,37 @@ namespace osu.Game.Tournament.IPC
return IPCStorage; return IPCStorage;
} }
public bool SetIPCLocation(string path)
{
if (!ipcFileExistsInDirectory(path))
return false;
var newStorage = initialiseIPCStorage(stableInfo.StablePath = path);
if (newStorage == null)
return false;
stableInfo.SaveChanges();
return true;
}
public bool AutoDetectIPCLocation()
{
var autoDetectedPath = findStablePath();
if (string.IsNullOrEmpty(autoDetectedPath))
return false;
var newStorage = initialiseIPCStorage(stableInfo.StablePath = autoDetectedPath);
if (newStorage == null)
return false;
stableInfo.SaveChanges();
return true;
}
private static bool ipcFileExistsInDirectory(string p) => File.Exists(Path.Combine(p, "ipc.txt")); private static bool ipcFileExistsInDirectory(string p) => File.Exists(Path.Combine(p, "ipc.txt"));
private string findStablePath() private string findStablePath()
{ {
if (!string.IsNullOrEmpty(stableInfo.StablePath))
return stableInfo.StablePath;
string stableInstallPath = string.Empty; string stableInstallPath = string.Empty;
try try
@ -183,10 +208,7 @@ namespace osu.Game.Tournament.IPC
stableInstallPath = r.Invoke(); stableInstallPath = r.Invoke();
if (stableInstallPath != null) if (stableInstallPath != null)
{
SetIPCLocation(stableInstallPath);
return stableInstallPath; return stableInstallPath;
}
} }
return null; return null;
@ -197,18 +219,6 @@ namespace osu.Game.Tournament.IPC
} }
} }
public bool SetIPCLocation(string path)
{
if (!ipcFileExistsInDirectory(path))
return false;
stableInfo.StablePath = path;
LocateStableStorage();
stableInfo.SaveChanges();
return true;
}
private string findFromEnvVar() private string findFromEnvVar()
{ {
try try

View File

@ -156,9 +156,8 @@ namespace osu.Game.Tournament.Screens
protected virtual void AutoDetect() protected virtual void AutoDetect()
{ {
var fileBasedIpc = ipc as FileBasedIPC; var fileBasedIpc = ipc as FileBasedIPC;
fileBasedIpc?.LocateStableStorage();
if (fileBasedIpc?.IPCStorage == null) if (!fileBasedIpc?.AutoDetectIPCLocation() ?? true)
{ {
overlay = new DialogOverlay(); overlay = new DialogOverlay();
overlay.Push(new IPCErrorDialog("Failed to auto detect", "An osu! stable cutting-edge installation could not be auto detected.\nPlease try and manually point to the directory.")); overlay.Push(new IPCErrorDialog("Failed to auto detect", "An osu! stable cutting-edge installation could not be auto detected.\nPlease try and manually point to the directory."));