示例#1
0
        public void NonexistantFile()
        {
            var fileName = "FavoriteMappers_DoesntExist.ini";
            var filePath = Path.Combine(DataPath, fileName);

            Assert.IsFalse(File.Exists(filePath));
            var favoriteMappers = new FavoriteMappers(filePath);

            favoriteMappers.Initialize();
            Assert.AreEqual(0, favoriteMappers.Mappers.Count);
        }
示例#2
0
        public void EmptyFile()
        {
            var fileName = "FavoriteMappers_Empty.ini";
            var filePath = Path.Combine(DataPath, fileName);

            Assert.IsTrue(File.Exists(filePath));
            var favoriteMappers = new FavoriteMappers(filePath);

            favoriteMappers.Initialize();
            Assert.AreEqual(0, favoriteMappers.Mappers.Count);
        }
示例#3
0
        //private TransformBlock<PlaylistSong, JobResult> DownloadBatch;

        public SongDownloader(PluginConfig config, HistoryManager historyManager, SongHasher hashSource, string customLevelsPath)
        {
            CustomLevelsPath = customLevelsPath;
            Directory.CreateDirectory(CustomLevelsPath);
            HashSource      = hashSource;
            DownloadQueue   = new ConcurrentQueue <PlaylistSong>();
            HistoryManager  = historyManager;
            FavoriteMappers = new FavoriteMappers();
            FavoriteMappers.Initialize();
            Config = config.Clone();
        }
示例#4
0
        public void NewLineAtMiddle()
        {
            var fileName = "FavoriteMappers_NewLineAtMiddle.ini";
            var filePath = Path.Combine(DataPath, fileName);

            Assert.IsTrue(File.Exists(filePath));
            var favoriteMappers = new FavoriteMappers(filePath);

            favoriteMappers.Initialize();
            Assert.AreEqual(6, favoriteMappers.Mappers.Count);
            foreach (var mapper in DefaultMappers)
            {
                Assert.IsTrue(favoriteMappers.Mappers.Contains(mapper));
            }
        }
示例#5
0
        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);
        }
示例#6
0
        public bool InitializeConfig()
        {
            Directory.CreateDirectory(ConfigDirectory);
            string modConfigPath = BeatSyncModConfigPath;
            bool   validConfig   = true;

            try
            {
                if (File.Exists(modConfigPath))
                {
                    Config = JsonConvert.DeserializeObject <BeatSyncModConfig>(File.ReadAllText(modConfigPath));
                }
                else
                {
                    Plugin.log.Info($"{modConfigPath} not found, creating a new one.");
                    Config = BeatSyncModConfig.GetDefaultConfig();
                }
            }
            catch (JsonReaderException ex)
            {
                WriteJsonException(modConfigPath, ex);
                Config = null;
            }
            catch (Exception ex)
            {
                Plugin.log.Error($"Invalid {BeatSyncModConfigName} file, using defaults: {ex.Message}");
                Plugin.log.Debug(ex);
                Config = null;
            }
            if (Config == null)
            {
                Config = BeatSyncModConfig.GetDefaultConfig();
            }
            string beatSyncConfigPath = BeatSyncConfigPath;

            try
            {
                if (File.Exists(beatSyncConfigPath))
                {
                    Plugin.log.Debug($"Using BeatSync config '{beatSyncConfigPath}'.");
                    Config.BeatSyncConfig = JsonConvert.DeserializeObject <BeatSyncConfig>(File.ReadAllText(beatSyncConfigPath));
                }
                else
                {
                    Plugin.log.Info($"{beatSyncConfigPath} not found, creating a new one.");
                }
            }
            catch (JsonReaderException ex)
            {
                WriteJsonException(beatSyncConfigPath, ex);
            }
            catch (Exception ex)
            {
                Plugin.log.Error($"Invalid BeatSync.json file, using defaults: {ex.Message}");
                Plugin.log.Debug(ex);
            }
            if (Config.BeatSyncConfig == null)
            {
                Config.BeatSyncConfig = new BeatSyncConfig(true);
            }
            Config.FillDefaults();

            string?favoriteMappersPath = FavoriteMappersPath;

            if (validConfig && favoriteMappersPath != null)
            {
                FavoriteMappers favoriteMappers = new FavoriteMappers(favoriteMappersPath);
                Plugin.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;

            SaveConfig();
            return(validConfig);
        }