Beispiel #1
0
        public AccountSettingsMessage LoadSettings()
        {
            string password = null;

            while (true)
            {
                password = InputPassword();

                if (password != null || password != string.Empty)
                {
                    break;
                }

                _logger.AddLogEntry("User inserted invalid password upon loading settings.");
                Console.WriteLine("We need a valid password.");
            }

            string encryptedSettings;

            using (var sr = new StreamReader(Path.Join(_dirPath, "Settings.txt")))
            {
                encryptedSettings = sr.ReadLine();
            }

            if (encryptedSettings == string.Empty || encryptedSettings == null)
            {
                Console.WriteLine("Failed to retrieve settings.");
                _logger.AddLogEntry("Failed to get settings from settings file. Nothing was returned.");
                return(null);
            }

            var settings      = _decrypt.AesDecrypt(encryptedSettings, password);
            var settingsSplit = settings.Split(':', StringSplitOptions.RemoveEmptyEntries);

            if (settingsSplit.Length != 2)
            {
                _logger.AddLogEntry($"Settings file loaded incorrect number of settings values {settingsSplit.Length}");
                return(null);
            }

            var apiKey    = settingsSplit[0];
            var accountId = settingsSplit[1];

            return(new AccountSettingsMessage(apiKey, accountId));
        }