Ejemplo n.º 1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string       description         = textBoxDescription.Text;
            string       driveletterFromPath = "";
            string       keyfile             = textBoxKeyfile.Text;
            string       usedriveletter      = DrivelettersHelper.IsDrivletterUsedByConfig(comboBoxDriveletter.SelectedItem.ToString());
            WmiDriveInfo wmiinfo             = new WmiDriveInfo();

            try
            {
                if (checkBoxPim.Checked)
                {
                    if (string.IsNullOrEmpty(_pim) && !string.IsNullOrEmpty(_password))
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePimNotSet", _language));
                    }
                }
            }
            catch (Exception ex)
            {
                DialogResult res = MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                buttonSavePassword_Click(this, e);
            }

            try
            {
                if (usedriveletter != null && usedriveletter != description)
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDrivletterIsUsed", _language) + usedriveletter);
                }
            }
            catch (Exception ex)
            {
                DialogResult res = MessageBox.Show(ex.Message, "", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                if (res == DialogResult.Abort)
                {
                    return;
                }
                if (res == DialogResult.Retry)
                {
                    buttonOk_Click(sender, e);
                    return;
                }
            }

            try
            {
                if (string.IsNullOrEmpty(description))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDescriptionNullorEmpty", _language));
                }

                if (_oldName != null)
                {
                    if (description != _oldName)
                    {
                        _config.RemoveSection(_oldName);
                    }
                }



                if (!checkBoxNoKeyfile.Checked)
                {
                    _config.SetValue(description, ConfigTrm.Container.Keyfile, keyfile);
                }

                driveletterFromPath = Path.GetPathRoot(@textBoxKontainer.Text);
                driveletterFromPath = driveletterFromPath.Replace(@"\", "");
                string[] pnpandin = wmiinfo.GetPNPidfromDriveletter(driveletterFromPath);

                //if no pnpdeviceid is found set to nothing
                if (pnpandin == null)
                {
                    pnpandin    = new string[2];
                    pnpandin[0] = "";
                    pnpandin[1] = "";
                }

                textBoxSelectedDrive.Text = pnpandin[0] + " Partition: " + pnpandin[1];

                if (checkBoxAutomountUsb.Checked)
                {
                }

                string hash = (comboBoxHash.SelectedItem == null) ? "" : comboBoxHash.SelectedItem.ToString();

                _config.SetValue(description, ConfigTrm.Container.Type, ConfigTrm.Container.Typename);
                _config.SetValue(description, ConfigTrm.Container.Kontainerpath, textBoxKontainer.Text);
                _config.SetValue(description, ConfigTrm.Container.Driveletter, comboBoxDriveletter.SelectedItem.ToString());
                _config.SetValue(description, ConfigTrm.Container.Readonly, checkBoxReadonly.Checked);
                _config.SetValue(description, ConfigTrm.Container.Removable, checkBoxRemovable.Checked);
                _config.SetValue(description, ConfigTrm.Container.Nokeyfile, checkBoxNoKeyfile.Checked);
                _config.SetValue(description, ConfigTrm.Container.Automountstart, checkBoxAutomountStart.Checked);
                _config.SetValue(description, ConfigTrm.Container.Automountusb, checkBoxAutomountUsb.Checked);
                _config.SetValue(description, ConfigTrm.Container.Pimuse, checkBoxPim.Checked);
                _config.SetValue(description, ConfigTrm.Container.Truecrypt, checkBoxTrueCrypt.Checked);
                _config.SetValue(description, ConfigTrm.Container.Hash, hash);
                _config.SetValue(description, ConfigTrm.Container.Pnpid, pnpandin[0]);
                _config.SetValue(description, ConfigTrm.Container.Partnummber, pnpandin[1]);

                if (!string.IsNullOrEmpty(_password))
                {
                    _config.SetValue(description, ConfigTrm.Container.Password, _password);
                    _config.SetValue(description, ConfigTrm.Container.Pim, _pim);
                }

                if (checkBoxPassword.Checked)
                {
                    _config.SetValue(description, ConfigTrm.Container.Password, "");
                    _config.SetValue(description, ConfigTrm.Container.Pim, "");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            _password = null;
            _pim      = null;
            Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event for button ok. Save the chosen config to config xml file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxNoKeyfilecontainer.Checked)
                {
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Nokeyfile, true);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Kontainerpath);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Removable);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Readonly);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Driveletter);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Hash);
                    _config.RemoveEntry(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Pim);
                }
                else
                {
                    if (!File.Exists(textBoxContainerPath.Text))
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MesageSetPathContainer", _language));
                    }

                    if (comboBoxDriveletter.SelectedItem == null)
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageSelectDriveletter", _language));
                    }

                    string usedriveletter = DrivelettersHelper.IsDrivletterUsedByConfig(comboBoxDriveletter.SelectedItem.ToString());

                    if (usedriveletter != null && usedriveletter != ConfigTrm.Mainconfig.Section)
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDrivletterIsUsed", _language) + usedriveletter);
                    }

                    string hash = (comboBoxHash.SelectedItem == null) ? "" : comboBoxHash.SelectedItem.ToString();

                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Pim, checkBoxPim.Checked);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Kontainerpath, textBoxContainerPath.Text);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Removable, checkBoxRemovable.Checked);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Readonly, checkBoxReadonly.Checked);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Driveletter, comboBoxDriveletter.SelectedItem.ToString());
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Hash, hash);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Pim, checkBoxPim.Checked);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Nokeyfile, false);
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Automount, checkBoxAutomount.Checked);
                }
                bool autoright = false;
                autoright = WriteAutostartAtWindows(checkBox_startwithwin.Checked);
                if (autoright)
                {
                    _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.AutostartWithWindows, checkBox_startwithwin.Checked);
                }

                _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Silentmode, !checkBoxSilentMode.Checked);

                if (string.IsNullOrEmpty(textBoxTruecryptPath.Text))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageSelectVeracryptPath", _language));
                }

                _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Truecryptpath, textBoxTruecryptPath.Text);
                // Get letter for selected language and write it to config.
                foreach (var language in _languages)
                {
                    if (comboBoxLanguage.SelectedItem.ToString() == language[0])
                    {
                        _config.SetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, language[1]);
                    }
                }

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Event from buttonOK. Write the information for the drive in the config.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void erstellen_Click(object sender, EventArgs e)
        {
            string part;
            string key;
            string dletter;
            string beschr;
            string hash;
            string usedriveletter = DrivelettersHelper.IsDrivletterUsedByConfig(comboBoxDriveletter.SelectedItem.ToString());

            // Load information from controls into variables
            beschr  = textBoxDescription.Text;
            part    = textBoxPartition.Text;
            key     = textBoxKeyfile.Text;
            dletter = comboBoxDriveletter.SelectedItem.ToString();

            try
            {
                if (checkBoxPim.Checked)
                {
                    if (string.IsNullOrEmpty(_pim) && !string.IsNullOrEmpty(_password))
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePimNotSet", _language));
                    }
                }
            }
            catch (Exception ex)
            {
                DialogResult res = MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                buttonSavePassword_Click(this, e);
            }

            //if driveletter is used ask if it shoud ignor or select a new one
            try
            {
                if (usedriveletter != null && usedriveletter != textBoxDescription.Text)
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDrivletterIsUsed", _language) + usedriveletter);
                }
            }
            catch (Exception ex)
            {
                DialogResult res = MessageBox.Show(ex.Message, "", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                if (res == DialogResult.Abort)
                {
                    return;
                }
                if (res == DialogResult.Retry)
                {
                    erstellen_Click(sender, e);
                    return;
                }
            }
            // Validate userinput
            try
            {
                if (_oldName != null)
                {
                    if (beschr != _oldName)
                    {
                        _config.RemoveSection(_oldName);
                    }
                }



                //check if hash is selected
                hash = (comboBoxHash.SelectedItem == null) ? "" : comboBoxHash.SelectedItem.ToString();



                // Check if driveconfig exist
                if (!_edit)
                {
                    string[] names = _config.GetSectionNames();
                    foreach (string name in names)
                    {
                        if (name == beschr)
                        {
                            throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDriveExist", _language));
                        }
                    }
                }
                // Check if drivename is set.
                if (string.IsNullOrEmpty(beschr))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDesciptionEmpty", _language));
                }

                // Check if description begins with a letter.
                char[] firstLetter = textBoxDescription.Text.ToCharArray();
                if (!char.IsLetter(firstLetter[0]))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDescriptionLetter", _language));
                }

                // Check if description has not a valid name.
                if (textBoxDescription.Text == ConfigTrm.Mainconfig.Section || textBoxDescription.Text == "configSections")
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDescriptNoValidName", _language));
                }

                // Check if partitionname is set.
                if (string.IsNullOrEmpty(part))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePartitionIsEmpty", _language));
                }

                // Check if keyfile is empty when nokeyfile is not checked.
                if (!checkBoxNoKeyfile.Checked)
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageKeyfileEmpty", _language));
                    }
                }

                string pat = @"\\Device\\Harddisk\d+\\Partition\d+$";
                Regex  r   = new Regex(pat);

                // Check if partiton has the right format.
                if (!r.IsMatch(part))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePartitionWrongFormat", _language));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language),
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            // Write data into config file.
            try
            {
                //use entry in textbox of partition if it is not the same
                string dd = part.Substring(part.LastIndexOf("n") + 1);
                if (!_partnummber.Equals(dd))
                {
                    _partnummber = dd;
                }
                _config.SetValue(beschr, ConfigTrm.Drive.Partition, part);
                _config.SetValue(beschr, ConfigTrm.Drive.Keyfile, key);
                _config.SetValue(beschr, ConfigTrm.Drive.Driveletter, dletter);
                _config.SetValue(beschr, ConfigTrm.Drive.Type, ConfigTrm.Drive.Typename);
                _config.SetValue(beschr, ConfigTrm.Drive.Nokeyfile, checkBoxNoKeyfile.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Removable, checkBoxRemovable.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Readonly, checkBoxReadonly.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Automountusb, checkBoxAutomountUsb.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Automountstart, checkBoxAutomountStart.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Diskmodel, _diskmodel);
                _config.SetValue(beschr, ConfigTrm.Drive.Diskserial, _diskserial);
                _config.SetValue(beschr, ConfigTrm.Drive.Pimuse, checkBoxPim.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Truecrypt, checkBoxTruecrypt.Checked);
                _config.SetValue(beschr, ConfigTrm.Drive.Hash, hash);
                _config.SetValue(beschr, ConfigTrm.Drive.Disknumber, _disknummber);
                _config.SetValue(beschr, ConfigTrm.Drive.Partnumber, _partnummber);
                _config.SetValue(beschr, ConfigTrm.Drive.Pnpdeviceid, _pnpdeviceid);
                _config.SetValue(beschr, ConfigTrm.Drive.Pimuse, checkBoxPim.Checked);

                if (!string.IsNullOrEmpty(_password))
                {
                    _config.SetValue(beschr, ConfigTrm.Drive.Password, _password);
                    _config.SetValue(beschr, ConfigTrm.Drive.Pim, _pim);
                }

                if (checkBoxPassword.Checked)
                {
                    _config.SetValue(beschr, ConfigTrm.Drive.Password, "");
                    _config.SetValue(beschr, ConfigTrm.Drive.Pim, "");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error writing config");
                _config.RemoveSection(beschr);
            }
            // Close the form.
            Close();
        }