/// <summary>
        ///
        /// </summary>
        public SelectPartition()
        {
            InitializeComponent();
            _config = Singleton <ConfigManager> .Instance.Init(_config);

            _language     = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, "");
            _wmidriveinfo = new WmiDriveInfo();
            _drives       = _wmidriveinfo.GetDrives();
            int i = 0;

            foreach (var item in _drives.Keys)
            {
                comboBoxDisks.Items.Add(item.ToString());
                i++;
            }
            if (_drives.Keys.Count > 0)
            {
                comboBoxDisks.SelectedIndex = _drives.Keys.Count - 1;
            }
            LanguageFill();
        }
Пример #2
0
        private void openFileDialogKontainerFileOK(object sender, CancelEventArgs e)
        {
            WmiDriveInfo wmiinfo             = new WmiDriveInfo();
            string       path                = null;
            string       driveletterFromPath = null;

            path = textBoxKontainer.Text = openFileDialogKontainer.FileName;

            try
            {
                driveletterFromPath = Path.GetPathRoot(@path);
                driveletterFromPath = driveletterFromPath.Replace(@"\", "");
                string[] pnpandin = wmiinfo.GetPNPidfromDriveletter(driveletterFromPath);
                textBoxSelectedDrive.Text = pnpandin[0] + " Partition: " + pnpandin[1];
            }
            catch (Exception)
            {
                textBoxSelectedDrive.Text    = LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDriveNotConnected", _language);
                checkBoxAutomountUsb.Checked = false;
                checkBoxAutomountUsb.Enabled = false;
            }
        }
Пример #3
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();
        }
Пример #4
0
        /// <summary>
        /// Fill all controls for editing a container.
        /// </summary>
        /// <param name="description"></param>
        private void NewKontainerEdit(string description)
        {
            _oldName = description;
            string path = _config.GetValue(description, ConfigTrm.Container.Kontainerpath, "");

            textBoxDescription.Text = description;
            comboBoxHash.Items.AddRange(new object[] { "", "sha512", "sha256", "wirlpool", "ripemd160", "streebog" });
            comboBoxHash.SelectedItem = _config.GetValue(description, ConfigTrm.Container.Hash, "");
            checkBoxNoKeyfile.Checked = _config.GetValue(description, ConfigTrm.Container.Nokeyfile, false);

            textBoxKontainer.Text          = path;
            textBoxKeyfile.Text            = _config.GetValue(description, ConfigTrm.Container.Keyfile, "");
            checkBoxReadonly.Checked       = _config.GetValue(description, ConfigTrm.Container.Readonly, false);
            checkBoxRemovable.Checked      = _config.GetValue(description, ConfigTrm.Container.Removable, false);
            checkBoxAutomountStart.Checked = _config.GetValue(description, ConfigTrm.Container.Automountstart, false);
            checkBoxAutomountUsb.Checked   = _config.GetValue(description, ConfigTrm.Container.Automountusb, false);
            checkBoxTrueCrypt.Checked      = _config.GetValue(description, ConfigTrm.Container.Truecrypt, false);
            checkBoxPim.Checked            = _config.GetValue(description, ConfigTrm.Container.Pimuse, false);
            _password = _config.GetValue(description, ConfigTrm.Drive.Password, "");
            _pim      = _config.GetValue(description, ConfigTrm.Drive.Pim, "");

            foreach (string element in DrivelettersHelper.GetDriveletters())
            {
                _driveletters.Add(element);
            }
            foreach (string elemnt in DrivelettersHelper.GetUsedDriveletter())
            {
                _useddriveletters.Add(elemnt);
            }

            comboBoxDriveletter.DataSource = _driveletters;

            comboBoxDriveletter.SelectedItem = _config.GetValue(description, ConfigTrm.Container.Driveletter, "");

            WmiDriveInfo wmiinfo = new WmiDriveInfo();

            // TODO Automatisch ermitteln der PNPID für den pfad FEHLERBEHANDLUNG
            _pnpid       = _config.GetValue(description, ConfigTrm.Container.Pnpid, "");
            _partnummber = _config.GetValue(description, ConfigTrm.Container.Partnummber, "");

            if (!string.IsNullOrEmpty(_pnpid) || !string.IsNullOrEmpty(_partnummber))
            {
                string driveletterFromPath = "";
                try
                {
                    driveletterFromPath = Path.GetPathRoot(@path);
                    driveletterFromPath = driveletterFromPath.Replace(@"\", "");
                    string[] pnpandin = wmiinfo.GetPNPidfromDriveletter(driveletterFromPath);
                    textBoxSelectedDrive.Text = pnpandin[0] + " Partition: " + pnpandin[1];
                }
                catch (Exception)
                {
                    textBoxSelectedDrive.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDriveNotConnected", _language);
                }
            }

            if (string.IsNullOrEmpty(_password))
            {
                buttonShowPassword.Enabled = false;
            }
        }
Пример #5
0
        private MountVareables ValidateDrive(string drivename, string _language)
        {
            List <string>    parlist = new List <string>();
            WmiDriveInfo     info    = new WmiDriveInfo();
            List <DriveInfo> list;
            string           keyfilepath = null;
            const bool       beep        = false;
            const bool       force       = false;
            string           key         = null;

            // get vareables from config
            bool   silent  = _config.GetValue(ConfigTrm.Mainconfig.Section, "Silentmode", true);
            string dletter = _config.GetValue(drivename, ConfigTrm.Drive.Driveletter, "");

            _password = _config.GetValue(drivename, ConfigTrm.Drive.Password, null);
            _pim      = _config.GetValue(drivename, ConfigTrm.Drive.Pim, null);
            bool   removable            = _config.GetValue(drivename, ConfigTrm.Drive.Removable, false);
            bool   readOnly             = _config.GetValue(drivename, ConfigTrm.Drive.Readonly, false);
            string hash                 = _config.GetValue(drivename, ConfigTrm.Drive.Hash, "");
            bool   tc                   = _config.GetValue(drivename, ConfigTrm.Drive.Truecrypt, false);
            string diskmodel            = _config.GetValue(drivename, ConfigTrm.Drive.Diskmodel, null);
            string diskserial           = _config.GetValue(drivename, ConfigTrm.Drive.Diskserial, null);
            string disknumber           = _config.GetValue(drivename, ConfigTrm.Drive.Disknumber, null);
            string partnumber           = _config.GetValue(drivename, ConfigTrm.Drive.Partnumber, null);
            string pnpdeviceid          = _config.GetValue(drivename, ConfigTrm.Drive.Pnpdeviceid, null);
            bool   nokeyfile            = _config.GetValue(drivename, ConfigTrm.Drive.Nokeyfile, true);
            bool   autostartWithWindows = _config.GetValue(drivename, ConfigTrm.Drive.PartitionNotCorrect, false);

            // Test if disk is connected on machine
            if (!info.CheckDiskPresent(pnpdeviceid))
            {
                throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "DiskNotPresentMessage", _language) + "\"" + diskmodel + "\"");
            }

            if (!_config.GetValue(drivename, ConfigTrm.Drive.Nokeyfile, true))
            {
                //test if keyfilekontainer is used and mounted
                if (_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Nokeyfile, true))
                {
                    keyfilepath = _config.GetValue(drivename, ConfigTrm.Drive.Keyfile, "");
                    // test if keyfile is valid path
                    try
                    {
                        if (Path.IsPathRooted(keyfilepath))
                        {
                            if (!File.Exists(keyfilepath))
                            {
                                throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "NoKeyfileMessage", _language));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "NoKeyfileMessage", _language));
                    }
                }
                else
                {
                    keyfilepath = _config.GetValue(drivename, ConfigTrm.Drive.Keyfile, "");

                    if (Path.IsPathRooted(keyfilepath))
                    {
                        if (!File.Exists(keyfilepath))
                        {
                            throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "NoKeyfileMessage", _language));
                        }
                    }
                    else
                    {
                        keyfilepath = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Driveletter, "") + _config.GetValue(drivename, ConfigTrm.Drive.Keyfile, "");
                        //TODO Prüfe ob kexfilekontainer eingebunden ist???
                        if (!File.Exists(keyfilepath))
                        {
                            throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "NoKeyfileMessage", _language));
                        }
                    }
                }
                key = keyfilepath;
            }

# if DEBUG