public WindowViewModel(INotificationHandler notificationHandler) { if (BSMTSettingsManager.Instance == null) { BSMTSettingsManager.UseDefaultManager(); } _notificationHandler = notificationHandler; try { SettingsViewModel = new SettingsViewModel(); //AddLocation(new BeatSaberInstall(@"C:\SteamInstall", InstallType.Steam)); //AddLocation(new BeatSaberInstall(@"C:\OculusInstall\DDDDDDDDDD\AAAAAAAAAA\VVVVVVVVVVVV\CCCCCCCCCCCCCC\SSSSSSSSSSSSSS\F", InstallType.Oculus)); //AddLocation(new BeatSaberInstall(@"C:\ManualInstall", InstallType.Manual)); var detectedLocations = BeatSaberTools.GetBeatSaberPathsFromRegistry(); BeatSaberLocations = new ObservableCollection <BeatSaberInstall>(detectedLocations); SetInstallByPath(SettingsViewModel.CurrentSettings.ChosenInstallPath); } catch (Exception ex) { ShowError(ex); if (BeatSaberLocations == null) { BeatSaberLocations = new ObservableCollection <BeatSaberInstall>(); SetInstallByPath(SettingsViewModel.CurrentSettings.ChosenInstallPath); } } }
public void ReadVdf() { string path = Path.Combine("Data", "config.vdf"); int expectedResults = 2; string[] libraryPaths = BeatSaberTools.LibrariesFromVdf(path); Assert.AreEqual(expectedResults, libraryPaths.Length); foreach (var libPath in libraryPaths) { Console.WriteLine(libPath); } }
public WindowViewModel() { if (BSMTSettingsManager.Instance == null) { BSMTSettingsManager.UseDefaultManager(); } var detectedLocations = BeatSaberTools.GetBeatSaberPathsFromRegistry(); BeatSaberLocations = new ObservableCollection <BeatSaberInstall>(detectedLocations); SettingsViewModel = new SettingsViewModel(); //AddLocation(new BeatSaberInstall(@"C:\SteamInstall", InstallType.Steam)); //AddLocation(new BeatSaberInstall(@"C:\OculusInstall\DDDDDDDDDD\AAAAAAAAAA\VVVVVVVVVVVV\CCCCCCCCCCCCCC\SSSSSSSSSSSSSS\F", InstallType.Oculus)); //AddLocation(new BeatSaberInstall(@"C:\ManualInstall", InstallType.Manual)); SetInstallByPath(SettingsViewModel.CurrentSettings.ChosenInstallPath); }
public void GetAllReferences() { var existingPath = @"Data\BSMLPractice.csproj"; var list = XmlFunctions.GetReferences(existingPath, true); foreach (var item in list) { string filePath = item.HintPath.Replace("$(BeatSaberDir)", @"H:\SteamApps\SteamApps\common\Beat Saber"); if (File.Exists(filePath)) { var assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(filePath); } Console.WriteLine(item.ToString(30)); } var otherList = BeatSaberTools.GetAvailableReferences(@"H:\SteamApps\SteamApps\common\Beat Saber"); foreach (var item in otherList) { Console.WriteLine(item.ToString(30)); } foreach (var item in list) { try { var check = otherList.Where(r => r.Name == item.Name).Single(); if (item.HintPath.Contains("$(BeatSaberDir)")) { Assert.AreEqual(check.RelativeDirectory, item.RelativeDirectory); } }catch (InvalidOperationException ex) { Console.WriteLine($"Exception: {item.Name}"); //throw ex; } } }
public async Task <bool> InitializeConfigAsync() { Directory.CreateDirectory(Paths.GetFullPath(ConfigDirectory, PathRoot.AssemblyDirectory)); ConsoleConfigPath = Path.Combine(ConfigDirectory, BeatSyncConsoleConfigName); string fullConsolePath = Paths.GetFullPath(ConsoleConfigPath, PathRoot.AssemblyDirectory); bool validConfig = true; try { if (File.Exists(fullConsolePath)) { Config = JsonConvert.DeserializeObject <Config>(await File.ReadAllTextAsync(fullConsolePath).ConfigureAwait(false)); } else { Logger.log.Info($"{ConsoleConfigPath} not found, creating a new one."); Config = Config.GetDefaultConfig(); } } catch (JsonReaderException ex) { WriteJsonException(ConsoleConfigPath, ex); Config = null; } catch (Exception ex) { Logger.log.Error($"Invalid BeatSyncConsole.json file, using defaults: {ex.Message}"); Logger.log.Debug(ex); Config = null; } if (Config == null) { string?response = LogManager.GetUserInput($"Would you like to replace the existing '{ConsoleConfigPath}' with a new one? (Y/N): "); if (response?.Equals("y", StringComparison.OrdinalIgnoreCase) ?? false) { Config = Config.GetDefaultConfig(); } else { return(false); } } Paths.UseLocalTemp = !Config.UseSystemTemp; string fullBeatSyncConfigPath = Paths.GetFullPath(BeatSyncConfigPath, PathRoot.AssemblyDirectory); try { if (File.Exists(fullBeatSyncConfigPath)) { Logger.log.Info($"Using BeatSync config '{BeatSyncConfigPath}'."); Config.BeatSyncConfig = JsonConvert.DeserializeObject <BeatSyncConfig>(await File.ReadAllTextAsync(fullBeatSyncConfigPath).ConfigureAwait(false)); } else { Logger.log.Info($"{BeatSyncConfigPath} not found, creating a new one."); Config.BeatSyncConfig = new BeatSyncConfig(true); } } catch (JsonReaderException ex) { WriteJsonException(BeatSyncConfigPath, ex); } catch (Exception ex) { Logger.log.Error($"Invalid BeatSync.json file, using defaults: {ex.Message}"); Logger.log.Debug(ex); } if (Config.BeatSyncConfig == null) { string?response = LogManager.GetUserInput($"Would you like to replace the existing '{BeatSyncConfigPath}' with a new one? (Y/N): "); if (response?.Equals("y", StringComparison.OrdinalIgnoreCase) ?? false) { Config.BeatSyncConfig = new BeatSyncConfig(true); } else { return(false); } } Config.FillDefaults(); ISongLocation[] enabledPaths = GetValidEnabledLocations().ToArray(); ISongLocation[] validPaths = GetValidLocations().ToArray(); if (enabledPaths.Length == 0) { if (validPaths.Length == 0) { string?response = LogManager.GetUserInput($"No song paths found in '{ConsoleConfigPath}', should I search for game installs? (Y/N): "); if (response == "Y" || response == "y") { BeatSaberInstall[] gameInstalls = BeatSaberTools.GetBeatSaberInstalls(); if (gameInstalls.Length > 0) { Config.BeatSaberInstallLocations.Clear(); for (int i = 0; i < gameInstalls.Length; i++) { Logger.log.Info($" {gameInstalls[i]}"); BeatSaberInstallLocation newLocation = gameInstalls[i].ToSongLocation(); newLocation.Enabled = false; Config.BeatSaberInstallLocations.Add(newLocation); } if (gameInstalls.Length == 1) { Logger.log.Info($"Found 1 game install, enabling for BeatSyncConsole: {gameInstalls[0]}"); Config.BeatSaberInstallLocations[0].Enabled = true;; } else { Logger.log.Info($"Found {gameInstalls.Length} game installs:"); } Config.SetConfigChanged(true, nameof(Config.BeatSaberInstallLocations)); } } } enabledPaths = GetValidEnabledLocations().ToArray(); validPaths = GetValidLocations().ToArray(); if (enabledPaths.Length == 0 && validPaths.Length > 0) { Logger.log.Warn("No locations currently enabled."); for (int i = 0; i < validPaths.Length; i++) { Logger.log.Info($" {i}: {validPaths[i]}"); } string?response = LogManager.GetUserInput($"Enter the numbers of the locations you wish to enable, separated by commas.") ?? string.Empty; string[] selectionResponse = response.Split(','); int[] selectionInts = selectionResponse.Select(r => { if (int.TryParse(r.Trim(), out int parsed)) { return(parsed); } return(-1); }).ToArray(); for (int i = 0; i < selectionInts.Length; i++) { int current = selectionInts[i]; if (current > -1 && current < validPaths.Length) { validPaths[current].Enabled = true; Logger.log.Info($"Enabling {validPaths[current]}."); Config.SetConfigChanged(true, nameof(Config.AlternateSongsPaths)); } else { Logger.log.Warn($"'{selectionResponse[i]}' is invalid."); } } } } enabledPaths = GetValidEnabledLocations().ToArray(); if (enabledPaths.Length > 0) { Logger.log.Info("Using the following targets:"); foreach (ISongLocation enabledLocation in enabledPaths) { Logger.log.Info($" {enabledLocation}"); } } else { Logger.log.Warn($"No enabled custom songs paths found. If you want songs downloaded to your Beat Saber game, please manually enter a 'GameDirectory' path for your songs in '{ConsoleConfigPath}' under 'BeatSaberInstallLocations'. Otherwise, add a 'BasePath' to the entry under 'AlternateSongsPaths'."); validConfig = false; } string?favoriteMappersPath = GetFavoriteMappersLocation(enabledPaths); if (validConfig && favoriteMappersPath != null) { FavoriteMappers favoriteMappers = new FavoriteMappers(favoriteMappersPath); Logger.log.Info($"Getting FavoriteMappers from '{favoriteMappersPath.Replace(Directory.GetCurrentDirectory(), ".")}'."); List <string> mappers = favoriteMappers.ReadFromFile(); if (mappers.Count > 0) { Config.BeatSyncConfig.BeatSaver.FavoriteMappers.Mappers = mappers.ToArray(); } } var beastSaberConfig = Config.BeatSyncConfig.BeastSaber; if (validConfig && beastSaberConfig.Enabled && string.IsNullOrEmpty(beastSaberConfig.Username)) { if (beastSaberConfig.Bookmarks.Enabled || beastSaberConfig.Follows.Enabled) { string?username = LogManager.GetUserInput("You have BeastSaber feeds enabled that require your bsaber.com username, enter your username:"******"No BeastSaber username entered, BeastSaber feeds 'Bookmarks' and 'Follows' will be unavailable."); } } } if (Config.ConfigChanged || Config.legacyValueChanged) { await StoreConsoleConfig().ConfigureAwait(false); } if (Config.BeatSyncConfig.ConfigChanged) { await StoreBeatSyncConfig().ConfigureAwait(false); } return(validConfig); }
public void FindBeatSaberDir() { var installs = BeatSaberTools.GetBeatSaberPathsFromRegistry(); }