public void SetInstallByPath(string path) { try { path = Path.GetFullPath(path); } catch { } if (!string.IsNullOrEmpty(path)) { var matchingInstall = BeatSaberLocations.Where(i => string.Equals(Path.GetFullPath(i.InstallPath), path, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (matchingInstall != null) { ChosenInstall = matchingInstall; } else { var newInstall = new BeatSaberInstall(path, InstallType.Manual); BeatSaberLocations.Add(newInstall); ChosenInstall = newInstall; } } else { ChosenInstall = BeatSaberLocations.FirstOrDefault(); } }
public bool CanAddLocation(string pathStr) { if (string.IsNullOrEmpty(pathStr)) { return(false); } try { pathStr = pathStr.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); var fullInstallPath = Path.GetFullPath(pathStr).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (Directory.Exists(fullInstallPath) && Path.IsPathRooted(pathStr) && !pathStr.EndsWith(":")) { bool locationExists = BeatSaberLocations.Any(i => { var comp = Path.GetFullPath(i.InstallPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); return(string.Equals(fullInstallPath, comp, StringComparison.CurrentCultureIgnoreCase)); }); if (!locationExists) { return(true); } } } catch { return(false); } return(false); }
private bool RemoveLocation(BeatSaberInstall install) { bool result = BeatSaberLocations.Remove(install); if (ChosenInstall == install) { ChosenInstall = null; } NewLocationIsValid = CanAddLocation(NewLocationInput); return(result); }
private bool AddLocation(BeatSaberInstall beatSaberInstall) { bool hadEmptyList = BeatSaberLocations.Count == 0; BeatSaberLocations.Add(beatSaberInstall); if (BeatSaberLocations.Any(i => i.InstallPath == NewLocationInput.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))) { NewLocationIsValid = false; } if (hadEmptyList) { ChosenInstall = beatSaberInstall; } return(true); }