Exemplo n.º 1
0
        public override string GetOptions(string strCurrentOptions)
        {
            advancedOptionsEnabled = null;
            PasswordSequenceConfiguration configuration = new Sequencer().Load(strCurrentOptions);

            if (configuration == null)
            {
                PasswordSequenceConfigurationFactory factory = new PasswordSequenceConfigurationFactory();
                string userFilePath = factory.GetUserFilePath();
                MessageBox.Show("An error occurred reading the Sequencer configuration file at " +
                                userFilePath + ". It may be corrupt. Fix or delete and try again. " +
                                "A default configuration has been loaded.",
                                "Error Reading Configuration",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            MainForm form = new MainForm(configuration ?? new PasswordSequenceConfiguration(true));

            form.ShowDialog();

            // this reset the need for a dialog
            if ((advancedOptionsRequired = GetAdvancedOptionRequired(form.Configuration)) != false)
            {
                advancedOptionsEnabled = null;
            }

            return(form.Configuration.Name);
        }
Exemplo n.º 2
0
        public void Save(PasswordSequenceConfiguration configuration)
        {
            if (Sequencer.GetAdvancedOptionRequired(configuration) && Sequencer.AdvancedOptionsDialog("Configuring password sequence using the advanced mode can result in the password being weaker that what is displaied by the strength bar. " +
                                                                                                      "Click Ok if you want to save the sequence anyway.") == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }


            /* pass "true" to GetConfigurationPath to default to the user config
             * even when it doesn't exist yet; we'll create it here
             */
            PasswordSequenceConfigurationFactory factory = new PasswordSequenceConfigurationFactory();

            string configFile = factory.GetUserFilePath(configuration.Name);

            if (null != configFile)
            {
                XmlSerializer serializer =
                    new XmlSerializer(typeof(PasswordSequenceConfiguration),
                                      "http://quasivirtuel.com/PasswordSequenceConfiguration.xsd");

                /* create the config file's directory if needed */
                Directory.CreateDirectory(Path.GetDirectoryName(configFile));

                /* open the file for writing, creating a new one if needed */
                FileStream configStream = File.Open(configFile, FileMode.Create);

                try
                {
                    serializer.Serialize(configStream, configuration);
                }
                finally
                {
                    configStream.Close();
                }
            }

            /* TODO: should we pop up an error message or something in the
             * "else" case (i.e. when getting config file path fails)?
             */
        }