Beispiel #1
0
        /// <summary>
        /// Reads the config file or walks the user through creating or upgrading one.
        /// </summary>
        /// <param name="exeParent">The directory the executable is in.</param>
        /// <param name="configFilePath">The path to the config file we should use or create.</param>
        /// <returns>Returns the config file to use or null if the application should exit.</returns>
        private ReaderConfig RunConfigFileFlow(String exeParent, String configFilePath)
        {
            // First make sure the file exists
            if (!File.Exists(configFilePath))
            {
                RunCreateConfigFileFlow(configFilePath);
            }

            ReaderConfig config = ConfigFileManager.ReadConfigFile(configFilePath);

            if (config == null)
            {
                Console.WriteLine("There was a problem reading the config file.");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
                return(null);
            }

            // Check the version of the config file
            if (config.Version < ReaderConfig.ReaderConfigVersion)
            {
                Console.WriteLine("The specified config file is an older version.  See Config.json.example for the current format.");
                Console.WriteLine("Would you like Sc2MmrReader to attempt to upgrade to the new format?  New parameters will get default values.");

                String response = GetInputFromUser(new String[] { "yes", "no" });

                // Just quit if they said no.  They can set the config settings themselves.
                if (response == "no")
                {
                    return(null);
                }

                // Otherwise update the config file
                config.Version = ReaderConfig.ReaderConfigVersion;
                if (ConfigFileManager.SaveConfigFile(config, configFilePath))
                {
                    Console.WriteLine("The config file has been updated.  Please check that the settings are correct and then restart Sc2MmrReader.  The path is:");
                    Console.WriteLine("\t" + configFilePath);
                    Console.WriteLine("Press any key to exit.");
                    Console.ReadKey();
                    return(null);
                }
                else
                {
                    Console.WriteLine("There was a problem saving the config file.  Please update it manually.");
                    Console.WriteLine("Press any key to exit.");
                    Console.ReadKey();
                    return(null);
                }
            }
            else if (config.Version > ReaderConfig.ReaderConfigVersion)
            {
                // If it's too new, tell them to update
                Console.WriteLine("The specified config file version is for a new version of Sc2MmrReader.  Please update to the latest version or downgrade your config file to version " + ReaderConfig.ReaderConfigVersion);
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
                return(null);
            }

            // Make the paths absolute with respect to the root of the EXE file if they are relative
            if (!Path.IsPathRooted(config.MmrFilePath))
            {
                config.MmrFilePath = Path.Combine(new string[] { exeParent, config.MmrFilePath });
            }

            if (!Path.IsPathRooted(config.DataDirectory))
            {
                config.DataDirectory = Path.Combine(new string[] { exeParent, config.DataDirectory });
            }

            Console.WriteLine("Using the following config file: " + configFilePath);
            Console.WriteLine("Outputting MMR to: " + config.MmrFilePath);
            Console.WriteLine();

            return(config);
        }
Beispiel #2
0
        /// <summary>
        /// Walks the user through creating a new config file.  If the user follows the flow, the file will be created by the end.
        /// If they say no or cancel partway through there will not be a file afterwards.
        /// </summary>
        /// <param name="configFilePath">The path they specified to create it at.</param>
        private void RunCreateConfigFileFlow(String configFilePath)
        {
            Console.WriteLine("You do not appear to have a config file at: ");
            Console.WriteLine("\t" + configFilePath);
            Console.WriteLine();
            Console.WriteLine("Would you like to create one? ");
            String response = GetInputFromUser(new String[] { "yes", "no" });

            Console.WriteLine();
            if (response == "yes")
            {
                // Load in the default values from the default file:
                ReaderConfig config = ReaderConfig.CreateDefault();
                Console.WriteLine();
                Console.WriteLine("First we'll need the information for the ladder you want to get the MMR for.");
                Console.WriteLine("Please enter the URL to the ladder you would like to monitor.");
                Console.WriteLine("You can find this by doing the following:");
                Console.WriteLine("  1) Navigate to Starcraft2.com");
                Console.WriteLine("  2) Log in to your Blizzard account");
                Console.WriteLine("  3) Navigate to View Profile-->Ladders-->(Pick a Ladder).  Note: The ladders are listed under \"CURRENT SEASON LEAGUES\"");
                Console.WriteLine("  4) Copy the URL of the page and paste it below.");
                Console.WriteLine("        Example: https://starcraft2.com/en-us/profile/1/1/1986271/ladders?ladderId=274006");
                Console.WriteLine();
                Console.Write("  (enter a URL): ");
                response = Console.ReadLine();
                while (response.ToLower() != "q" && !ParseAccountUrlIntoConfig(response, config))
                {
                    Console.WriteLine("That URL is not valid.  Make sure you get the URL of a specific ladder and not your profile, or enter q to quit.");
                    Console.Write("  (enter a URL): ");
                    response = Console.ReadLine();
                }
                Console.WriteLine();

                // If they asked to quit, just stop.
                if (response.ToLower() == "q")
                {
                    Console.WriteLine("Exiting.");
                    return;
                }

                // Otherwise, the URL parsed sucessfully.
                Console.WriteLine("Great!  That URL seems valid.");
                Console.WriteLine();
                response = "";
                while (String.IsNullOrEmpty(response))
                {
                    Console.WriteLine("Please enter your Client ID (See README.md if you dont know what that is).");
                    Console.Write("  (ClientId): ");
                    response = Console.ReadLine();
                }
                Console.WriteLine();

                // Set their response on the config.
                config.ClientId = response;

                Console.WriteLine();
                response = "";
                while (String.IsNullOrEmpty(response))
                {
                    Console.WriteLine("Please enter your Client Secret (See README.md if you dont know what that is).");
                    Console.Write("  (ClientSecret): ");
                    response = Console.ReadLine();
                }
                Console.WriteLine();

                // Set their secret on the config
                config.ClientSecret = response;

                if (!ConfigFileManager.SaveConfigFile(config, configFilePath))
                {
                    Console.WriteLine("Uh oh, we were not able to save the config to: ");
                    Console.WriteLine("\t" + configFilePath);
                    Console.WriteLine("Please check that is a valid path and Sc2MmrReader has access to write there and try again!");
                    return;
                }

                // Print a success message and continue on to the rest of the app with the info that was written.
                Console.WriteLine("All set!  You can check the following path to verify your settings are correct at any time:");
                Console.WriteLine("\t" + configFilePath);
                Console.WriteLine();
            }
            else
            {
                // Just return
            }
        }