Exemplo n.º 1
0
        public Config()
        {
            if (ReadFile(ConfigFilePath))
            {
                try
                {
                    string[] settingsDefaultString = MostUsed.ReadFile(ConfigFilePath).Split('\n');
                    this.QuestionNumber = Convert.ToInt32(settingsDefaultString[0].Split(':')[1]);
                    this.Remembered     = Convert.ToBoolean(settingsDefaultString[1].Split(':')[1]);

                    if (this.Remembered)
                    {
                        this.DefaultUserName = Cipher.CesarDecifrar(settingsDefaultString[2].Split(':')[1].TrimEnd(), 5);
                        this.DefaultPassword = Cipher.CesarDecifrar(settingsDefaultString[3].Split(':')[1].TrimEnd(), 5);
                    }
                    else
                    {
                        this.DefaultUserName = "";
                        this.DefaultPassword = "";
                    }
                }
                catch (Exception)
                {
                    string defaultValues = "QuestionNumber:10\nRemembered:false\nDefaultUserName: \nDefaultPassword: ";
                    MostUsed.WriteFile(this.ConfigFilePath, defaultValues);
                    string[] settingsDefaultString = MostUsed.ReadFile(ConfigFilePath).Split('\n');
                    this.QuestionNumber  = Convert.ToInt32(settingsDefaultString[0].Split(':')[1]);
                    this.Remembered      = Convert.ToBoolean(settingsDefaultString[1].Split(':')[1]);
                    this.DefaultUserName = Cipher.CesarDecifrar(settingsDefaultString[2].Split(':')[1].TrimEnd(), 5);
                    this.DefaultPassword = Cipher.CesarDecifrar(settingsDefaultString[3].Split(':')[1].TrimEnd(), 5);
                }
            }
        }
Exemplo n.º 2
0
        public void SaveCurrentData()
        {
            string valuesToSave = "QuestionNumber:" + this.QuestionNumber +
                                  "\nRemembered:" + this.Remembered.ToString() +
                                  "\nDefaultUserName:"******"\nDefaultPassword:" + Cipher.CesarCifrar(this.DefaultPassword, 5);

            MostUsed.WriteFile(this.ConfigFilePath, valuesToSave);
        }
Exemplo n.º 3
0
 private static bool ReadFile(string Path)
 {
     if (File.Exists(Path))
     {
         return(true);
     }
     else
     {
         try
         {
             File.Create(Path);
             string defaultValues = "QuestionNumber:10\nRemembered:false\nDefaultUserName: \nDefaultPassword: ";
             MostUsed.WriteFile(Path, defaultValues);
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }