/// <summary> /// Fills the controls with the needed information for creating a drive. /// </summary> private void NewDriveCreate() { Text = LanguagePool.GetInstance().GetString(LanguageRegion, "NewDrive", _language); // Set _edit to false. _edit = false; // Get the driveletters and the used driveletters and stor them in the lists. foreach (string element in DrivelettersHelper.GetDriveletters()) { _driveletters.Add(element); } foreach (string elemnt in DrivelettersHelper.GetUsedDriveletter()) { _useddriveletters.Add(elemnt); } // Set the datasource for the drivelettercobobox and select the first. comboBoxDriveletter.DataSource = _driveletters; //comboBoxDriveletter.SelectedItem = _driveletters[0]; foreach (string element in DrivelettersHelper.GetDriveletters()) { if (!_useddriveletters.Contains(element)) { comboBoxDriveletter.SelectedItem = element; } } comboBoxHash.Items.AddRange(_hashes); buttonShowPassword.Enabled = false; }
/// <summary> /// Fill all controls with information for creating a new container. /// </summary> private void NewKontainer() { foreach (string element in DrivelettersHelper.GetDriveletters()) { _driveletters.Add(element); } foreach (string elemnt in DrivelettersHelper.GetUsedDriveletter()) { _useddriveletters.Add(elemnt); } comboBoxHash.Items.AddRange(_hashes); comboBoxDriveletter.DataSource = _driveletters; buttonShowPassword.Enabled = false; }
/// <summary> /// Fill the controls with the information that needed to edit the drive. /// </summary> /// <param name="driveName"></param> private void NewDriveEdit(string driveName) { Text = LanguagePool.GetInstance().GetString(LanguageRegion, "DriveEdit", _language); _edit = true; _oldName = driveName; foreach (string element in DrivelettersHelper.GetDriveletters()) { _driveletters.Add(element); } foreach (string elemnt in DrivelettersHelper.GetUsedDriveletter()) { _useddriveletters.Add(elemnt); } comboBoxDriveletter.DataSource = _driveletters; comboBoxHash.Items.AddRange(_hashes); textBoxDescription.Text = driveName; textBoxPartition.Text = _config.GetValue(driveName, ConfigTrm.Drive.Partition, "\\Device\\Harddisk\\Partition"); textBoxKeyfile.Text = _config.GetValue(driveName, ConfigTrm.Drive.Keyfile, ""); checkBoxNoKeyfile.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Nokeyfile, false); checkBoxReadonly.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Readonly, false); checkBoxRemovable.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Removable, false); checkBoxAutomountStart.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Automountstart, false); checkBoxAutomountUsb.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Automountusb, false); checkBoxPim.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Pimuse, false); checkBoxTruecrypt.Checked = _config.GetValue(driveName, ConfigTrm.Drive.Truecrypt, false); comboBoxHash.SelectedItem = _config.GetValue(driveName, ConfigTrm.Drive.Hash, ""); _disknummber = _config.GetValue(driveName, ConfigTrm.Drive.Disknumber, ""); _partnummber = _config.GetValue(driveName, ConfigTrm.Drive.Partnumber, ""); _pnpdeviceid = _config.GetValue(driveName, ConfigTrm.Drive.Pnpdeviceid, ""); _password = _config.GetValue(driveName, ConfigTrm.Drive.Password, ""); _pim = _config.GetValue(driveName, ConfigTrm.Drive.Pim, ""); textBox_PNPDeviceID.Text = _pnpdeviceid; comboBoxDriveletter.SelectedItem = _config.GetValue(driveName, ConfigTrm.Drive.Driveletter, ""); if (string.IsNullOrEmpty(_password)) { buttonShowPassword.Enabled = false; } }
/// <summary> /// Mount a Drive. Call veracrypt process and try to mount. /// </summary> /// <param name="partition"></param> /// <param name="driveletter"></param> /// <param name="keyfile"></param> /// <param name="password"></param> /// <param name="silent"></param> /// <param name="beep"></param> /// <param name="force"></param> /// <param name="readOnly"></param> /// <param name="removable"></param> /// <param name="pim"></param> /// <param name="hash"></param> /// <param name="tc"></param> /// <returns></returns> /// <exception cref="Exception"></exception> internal static int MountDrive(string[] partition, string driveletter, string keyfile, string password, bool silent, bool beep, bool force, bool readOnly, bool removable, string pim, string hash, bool tc) { int output; Tc.FileName = _config.GetValue("Grundeinstellungen", "Truecryptpath", ""); Tc.RedirectStandardOutput = true; Tc.UseShellExecute = false; const string status = "Die Vareable ist null oder leer:"; try { if (partition.Length <= 0) { throw new Exception(status + "(partition)"); } if (string.IsNullOrEmpty(driveletter)) { throw new Exception(status + "(driveletter)"); } if (!DrivelettersHelper.IsDriveletterFree(driveletter)) { throw new Exception("Laufwerksbuchstabe ist belegt"); } if (!string.IsNullOrEmpty(keyfile)) { if (!File.Exists(keyfile)) { throw new Exception("Keyfile nicht vorhanden"); } } if (!File.Exists(Tc.FileName)) { throw new Exception("TrueCrypt.exe nicht vorhanden"); } } catch (Exception e) { string text = ""; #if DEBUG text = "Mount Class"; #endif #if RELEASE text = "Fehler"; #endif MessageBox.Show(e.Message, text); return(2); } string argumentstring = Letter + driveletter + Password + password + Quit; if (!string.IsNullOrEmpty(keyfile)) { argumentstring += Keyfile + Quote + keyfile + Quote; } if (!string.IsNullOrEmpty(pim)) { argumentstring += Pim + Quote + pim + Quote; } if (!string.IsNullOrEmpty(hash)) { argumentstring += Hash + Quote + hash + Quote; } if (silent) { argumentstring += Silent; } if (beep) { argumentstring += Beep; } if (force) { argumentstring += Force; } if (removable) { argumentstring += Mountoption + MountoptionRemovable; } if (readOnly) { argumentstring += Mountoption + MountoptionReadonly; } if (tc) { argumentstring += Truecrypt; } # if DEBUG
/// <summary> /// Fill all controllelements with selections from configfile. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainsettingsLoad(object sender, EventArgs e) { string defaultlanguage = ""; string selectedlanguage = ""; textBoxConfigPath.Text = _config.XmlPathName; // Get languages from language.xml file. try { _languages = LanguagePool.GetInstance().GetLanguages(); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); } // Fill combobox with available languages and get default language if (_languages != null) { foreach (var language in _languages) { comboBoxLanguage.Items.Add(language[0]); if (_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Defaultlanguage, "") == language[1]) { defaultlanguage = language[0]; } if (_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, defaultlanguage) == language[1]) { selectedlanguage = language[0]; } } } // Select chosen Language in combobox. If nothing chosen use default language if (selectedlanguage == "") { selectedlanguage = defaultlanguage; } comboBoxLanguage.SelectedItem = selectedlanguage; if (!string.IsNullOrEmpty(_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Truecryptpath, ""))) { select_truecrypt.InitialDirectory = Path.GetDirectoryName(_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Truecryptpath, "")); textBoxTruecryptPath.Text = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Truecryptpath, ""); } else { string pp = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), "VeraCrypt", "VeraCrypt.exe"); if (File.Exists(pp)) { select_truecrypt.InitialDirectory = Path.GetDirectoryName(pp); textBoxTruecryptPath.Text = pp; } else { select_truecrypt.InitialDirectory = textBoxTruecryptPath.Text = ""; } } select_konpath.InitialDirectory = textBoxContainerPath.Text = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Kontainerpath, ""); checkBoxSilentMode.Checked = !_config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Silentmode, true); checkBoxReadonly.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Readonly, false); checkBoxRemovable.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Removable, false); checkBoxNoKeyfilecontainer.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Nokeyfile, true); checkBoxAutomount.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Automount, false); checkBoxPim.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Pim, false); checkBox_startwithwin.Checked = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.AutostartWithWindows, false); // Fill lists for the comboboxdriveletter 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(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Driveletter, ""); comboBoxHash.Items.AddRange(_hashes); comboBoxHash.SelectedItem = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Hash, ""); }
/// <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; } }
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(); }
/// <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; } }
/// <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(); }