public static bool DeSerialize(string fileName, ref ConfigPasswordGenerator cfg)
 {
     if (!File.Exists(fileName))
     {
         return(true);
     }
     try
     {
         using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
         {
             XmlSerializer ser = new XmlSerializer(typeof(ConfigPasswordGenerator));
             cfg = (ConfigPasswordGenerator)ser.Deserialize(fileStream);
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.ToString());
     }
     return(true);
 }
Example #2
0
        public Form1()
        {
            InitializeComponent();

            // get values from config file
            ConfigPasswordGenerator.DeSerialize(config.ConfigFileName, ref config);
            WordListFileName.Text     = config.WordFileName;
            specialCharactersCtl.Text = config.SpecialCharacters;

            if (config.WordCount < wordCountCtrl.Minimum || config.WordCount > wordCountCtrl.Maximum)
            {
                config.WordCount = (wordCountCtrl.Maximum - wordCountCtrl.Minimum) / 2;
            }
            wordCountCtrl.Value = config.WordCount;

            if (config.PasswordCount < passwordCntCtrl.Minimum || config.PasswordCount > passwordCntCtrl.Maximum)
            {
                config.PasswordCount = (passwordCntCtrl.Maximum - passwordCntCtrl.Minimum) / 2;
            }

            passwordCntCtrl.Value          = config.PasswordCount;
            capitalizeWordCheckbox.Checked = config.CapitalizeWord;
        }