/// <summary>
        /// Reloads the configuration file (path). If file is not present, it will generate a new one.
        /// </summary>
        /// <returns>A RootConfig object.</returns>
        public Config Reload()
        {
            var config = new Config();

            if (!File.Exists(_path))
            {
                File.Create(_path).Close();

                #region append

                // BuildMyString.com generated code. Please enjoy your string responsibly.

                var sb = new StringBuilder();

                sb.Append("{\r\n");
                sb.Append("    \"Username\": \"\",\r\n");
                sb.Append("    \"Password\": \"\",\r\n");
                sb.Append("    \"ApiKey\": \"\",\r\n");
                sb.Append("    \"SteamMachineAuth\": \"\",\r\n");
                sb.Append("    \"Inventories\":[440,730]\r\n");
                sb.Append("}\r\n");

                #endregion

                File.WriteAllText(_path, sb.ToString());
            }

            config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(_path));

            return config;
        }
Пример #2
0
        private static void Main()
        {
            Console.Title = "Donation Bot by sne4kyFox";
            Console.WriteLine("Welcome to the donation bot!");
            Console.WriteLine(
                "By using this software you agree to the terms in \"license.txt\".");

            _config = ConfigHandler.Reload();

            if (string.IsNullOrEmpty(_config.ApiKey))
            {
                Console.WriteLine("Fatal error: API key is missing. Please fill in the API key field in \"configuration.xml\"");
                Console.ReadLine();
                Environment.Exit(-1);
            }

            _apiKey = _config.ApiKey;

            if (string.IsNullOrEmpty(_config.Username) || string.IsNullOrEmpty(_config.Password))
            {
                Console.WriteLine("Please input your username and password.");

                Console.Write("Username: "******"Password: "******"Attempting web login...");

            _account = Web.RetryDoLogin(TimeSpan.FromSeconds(5), 10, _user, _pass, _config.SteamMachineAuth);

            if (!string.IsNullOrEmpty(Web.SteamMachineAuth))
            {
                _config.SteamMachineAuth = Web.SteamMachineAuth;
                ConfigHandler.WriteChanges(_config);
            }

            Console.WriteLine("Login was successful!");

            PollOffers();
        }
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(Config towrite)
 {
     File.WriteAllText(_path, JsonConvert.SerializeObject(towrite));
 }
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(Config towrite)
 {
     File.WriteAllText(_path, towrite.SerializeToXml());
 }