コード例 #1
0
        private void TransferConfig()
        {
            if (File.Exists("config.txt"))
            {
                string username = "", password = "";
                foreach (var currentLine in File.ReadAllLines("config.txt"))
                {
                    var line = currentLine.Trim();
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    if (line.StartsWith("username"))
                    {
                        username = line.Split('"')[1].Split('"')[0];
                    }
                    else if (line.StartsWith("password"))
                    {
                        password = line.Split('"')[1].Split('"')[0];
                    }
                }
                if (configuration.GetConfiguration("username") == "USERNAME")
                {
                    configuration.SetConfigurationEntry("username", username);
                }
                if (configuration.GetConfiguration("password") == "PASSWORD")
                {
                    configuration.SetConfigurationEntry("password", password);
                }
                configuration.SaveConfigurationFile();
                File.Delete("config.txt");
            }
        }