Esempio n. 1
0
        /// <summary>
        /// Set the languagestrings for the controls.
        /// </summary>
        private void LanguageFill()
        {
            try
            {
                Text = LanguagePool.GetInstance().GetString(LanguageRegion, "Form", _language);
                groupBoxDescription.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxDescription", _language);
                groupBoxPath.Text        = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxPath", _language);
                groupBoxKyfilename.Text  = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxKyfilename", _language);

                groupBoxDriveletter.Text  = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxDriveletter", _language);
                groupBoxMountoptions.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxMountoptions", _language);
                checkBoxNoKeyfile.Text    = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxNoKeyfile", _language);

                checkBoxRemovable.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxRemovable", _language);
                checkBoxReadonly.Text    = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxReadonly", _language);
                buttonOk.Text            = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOk", _language);
                buttonClose.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonClose", _language);
                buttonOpenContainer.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOpenContainer", _language);

                checkBoxAutomountUsb.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxAutomountUsb", _language);
                checkBoxAutomountStart.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxAutomountStart", _language);
                groupBoxHash.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxHash", _language);
                groupBoxSavePassword.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxSavePassword", _language);
                buttonSavePassword.Text     = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonSavePassword", _language);
                buttonShowPassword.Text     = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonShowPassword", _language);
                checkBoxPassword.Text       = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxPassword", _language);
                //.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "", _language);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            //TODO Fehlerbahandlung

            string pnpdid;
            string partnummber;

            try
            {
                _drives.TryGetValue(comboBoxDisks.Text, out pnpdid);
                partnummber = comboBoxPartitions.SelectedItem.ToString();
            }
            catch (Exception)
            {
                DialogResult res = MessageBox.Show(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageSelectPartition", _language), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List <DriveInfo> dlist = _wmidriveinfo.GetDriveinfo(pnpdid);
            DriveInfo        info  = dlist[0];

            _diskmodel   = info.Model;
            _disknummber = info.Index;
            _diskserial  = info.SerialNumber;
            _partnummber = partnummber;
            _pNPDeviceID = info.PNPDeviceID;
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 3
0
 /// <summary>
 /// Set the languagestrings for the controls.
 /// </summary>
 private void LanguageFill()
 {
     try
     {
         lableDescription.Text       = LanguagePool.GetInstance().GetString(LanguageRegion, "lableDescription", _language);
         lablePartition.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "lablePartition", _language);
         lableKeyfile.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "lableKeyfile", _language);
         checkBoxNoKeyfile.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxNoKeyfile", _language);
         groupBoxMountoptions.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxMountoptions", _language);
         checkBoxRemovable.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxRemovable", _language);
         checkBoxReadonly.Text       = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxReadonly", _language);
         groupBoxDriveletter.Text    = LanguagePool.GetInstance().GetString(LanguageRegion, "lableDriveletter", _language);
         buttonOk.Text               = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOk", _language);
         buttonCancel.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonCancel", _language);
         checkBoxAutomountUsb.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxAutomountUsb", _language);
         checkBoxAutomountStart.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxAutomountStart", _language);
         checkBoxTruecrypt.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxTruecrypt", _language);
         checkBoxPim.Text            = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxPim", _language);
         groupBox_PNPDeviceID.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxPNPDeviceID", _language);
         buttonShowPassword.Text     = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonShowPassword", _language);
         checkBoxPassword.Text       = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxPassword", _language);
         buttonSavePassword.Text     = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonSavePassword", _language);
         groupBoxSavePassword.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxSavePassword", _language);
         //.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "", _language);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         throw;
     }
 }
Esempio n. 4
0
        private void buttonChosePartition_Click(object sender, EventArgs e)
        {
            var          sp  = new SelectPartition();
            DialogResult res = sp.ShowDialog();

            _partnummber = sp._partnummber;
            _diskmodel   = sp._diskmodel;
            _disknummber = sp._disknummber;
            _diskserial  = sp._diskserial;
            _pnpdeviceid = sp._pNPDeviceID;

            if (res == DialogResult.OK)
            {
                if (string.IsNullOrEmpty(_partnummber))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePartnumberEmpty", _language));
                }
                if (string.IsNullOrEmpty(_disknummber))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessageDisknumberEmpty", _language));
                }
                if (string.IsNullOrEmpty(_pnpdeviceid))
                {
                    throw new Exception(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePNPDeviceIDEmpty", _language));
                }

                textBoxPartition.Text    = "\\Device\\Harddisk" + _disknummber + "\\Partition" + _partnummber;
                textBox_PNPDeviceID.Text = _pnpdeviceid;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Shows the saved password after confirm the master password.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonShowPassword_Click(object sender, EventArgs e)
        {
            Passwordinput pin = new Passwordinput();
            DialogResult  res = pin.ShowDialog();

            if (res == DialogResult.OK)
            {
                if (Password_helper.Check_password(pin._password))
                {
                    Passwordinput pinshow       = new Passwordinput("drive", checkBoxPim.Checked, _password, _pim);
                    DialogResult  pinshowresult = pinshow.ShowDialog();
                    if (pinshowresult == DialogResult.OK)
                    {
                        _password = pinshow._password;
                        _pim      = pinshow._pim;
                        buttonShowPassword.Enabled = true;
                    }
                    pinshow._password = null;
                    pinshow._pim      = null;
                    pinshow.Dispose();
                }
                else
                {
                    DialogResult wrongres = MessageBox.Show(this, LanguagePool.GetInstance().GetString(LanguageRegion, "MessageMasterPasswordWrong", _language), "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (wrongres == DialogResult.Retry)
                    {
                        buttonShowPassword_Click(sender, e);
                    }
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Fill all controllements with selected language texts.
 /// </summary>
 private void LanguageFill()
 {
     Text                            = LanguagePool.GetInstance().GetString(LanguageRegion, "Form", _language);
     checkBoxPim.Text                = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxPim", _language);
     labelHash.Text                  = LanguagePool.GetInstance().GetString(LanguageRegion, "labelHash", _language);
     labelTruecryptPath.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "labelTruecryptPath", _language);
     buttonTruecryptPath.Text        = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonTruecryptPath", _language);
     buttonContainerPath.Text        = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonContainerPath", _language);
     groupBoxKeyfileContainer.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxKeyfileContainer", _language);
     labelKeyfilecontainer.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "labelKeyfilecontainer", _language);
     labelDriveletter.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "labelDriveletter", _language);
     checkBoxReadonly.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxReadonly", _language);
     checkBoxRemovable.Text          = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxRemovable", _language);
     groupBoxUsesettings.Text        = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxUsesettings", _language);
     checkBoxNoKeyfilecontainer.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxNoKeyfilecontainer", _language);
     groupBoxLanguage.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxLanguage", _language);
     groupBoxDebug.Text              = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxDebug", _language);
     checkBoxSilentMode.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxSilentMode", _language);
     buttonOk.Text                   = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOk", _language);
     buttonClose.Text                = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonClose", _language);
     checkBoxAutomount.Text          = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBoxAutomount", _language);
     groupBoxConfigPath.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "groupBoxConfigPath", _language);
     buttonShowConfig.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonShowConfig", _language);
     checkBox_startwithwin.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "checkBox_startwithwin", _language);
     //.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "", _language);
 }
Esempio n. 7
0
        /// <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 the secelcted language into form.
 /// </summary>
 private void LanguageFill()
 {
     Text = LanguagePool.GetInstance().GetString(LanguageRegion, "Form", _language);
     labelPassword.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPassword", _language);
     buttonOk.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOk", _language);
     labelPim.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPim", _language);
 }
 private void LanguageFill()
 {
     buttonOK.Text       = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOK", _language);
     buttonCancel.Text   = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonCancel", _language);
     labelDisk.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "labelDisk", _language);
     labelPartition.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPartition", _language);
     this.Text           = LanguagePool.GetInstance().GetString(LanguageRegion, "SelectPartition", _language);
 }
Esempio n. 10
0
 private void FillLanguage()
 {
     this.Text                 = LanguagePool.GetInstance().GetString(LanguageRegion, "Caption", _language);
     buttonCancel.Text         = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonCancel", _language);
     buttonChangePassword.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonChangePassword", _language);
     buttonOK.Text             = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonOK", _language);
     buttonReset.Text          = LanguagePool.GetInstance().GetString(LanguageRegion, "buttonReset", _language);
     labelOldPassword.Text     = LanguagePool.GetInstance().GetString(LanguageRegion, "labelOldPassword", _language);
     labelPassword_first.Text  = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPassword_first", _language);
     labelPassword_second.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPassword_second", _language);
     //LanguagePool.GetInstance().GetString(LanguageRegion, "", _language);
 }
Esempio n. 11
0
        /// <summary>
        /// To enter master password.
        /// </summary>
        public Passwordinput()
        {
            InitializeComponent();
            _config = Singleton <ConfigManager> .Instance.Init(_config);

            _language = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, "");
            LanguageFill();
            Text = LanguagePool.GetInstance().GetString(LanguageRegion, "FormMaster", _language);
            labelPassword.Text = LanguagePool.GetInstance().GetString(LanguageRegion, "labelPasswordMaster", _language);
            labelPim.Visible   = false;
            textBoxPim.Visible = false;
        }
Esempio n. 12
0
 private void textBoxPassword_second_TextChanged(object sender, EventArgs e)
 {
     if (textBoxPassword_first.Text == textBoxPassword_second.Text)
     {
         toolStripStatusLabel1.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "equel", _language);
         toolStripStatusLabel1.ForeColor = Color.Green;
     }
     else
     {
         toolStripStatusLabel1.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "not equel", _language);
         toolStripStatusLabel1.ForeColor = Color.Red;
     }
 }
Esempio n. 13
0
        private void buttonReset_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show(LanguagePool.GetInstance().GetString(LanguageRegion, "resetMessage", _language), "Delete Config", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            if (File.Exists(_confDir))
            {
                File.Delete(_confDir);
            }
            Application.Restart();
        }
Esempio n. 14
0
        private void set_wrong()
        {
            //close after 3 wrong inputs
            if (fail <= 3)
            {
                fail++;
            }
            else
            {
                buttonCancel_Click(this, EventArgs.Empty);
            }

            toolStripStatusLabel1.Text      = LanguagePool.GetInstance().GetString(LanguageRegion, "password wrong", _language);
            textBoxPassword_first.Text      = "";
            toolStripStatusLabel1.ForeColor = Color.Red;
            return;
        }
Esempio n. 15
0
        /// <summary>
        /// Liefert eine Instanz von StringPool (Singleton)
        /// </summary>
        /// <returns></returns>
        public static LanguagePool GetInstance()
        {
            // Erstelle Cache-Objekt je nach Plattform (Web- / Winform)
            Cache myCache = HttpContext.Current == null ? HttpRuntime.Cache : HttpContext.Current.Cache;

            // Prüfe ob Cache leer ist
            if (myCache[CacheKey] == null)
            {
                // Erstelle StringPool-Instanz und lade Strings
                var st = new LanguagePool();
                st.LoadStrings();

                // Cache neu füllen
                myCache.Insert(CacheKey, st, new CacheDependency(_sourceFile));
            }

            // Gebe StringPool-Objekt aus Cache zurück
            return((LanguagePool)myCache[CacheKey]);
        }
Esempio n. 16
0
        /// <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;
            }
        }
Esempio n. 17
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;
            }
        }
Esempio n. 18
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            _password = textBoxPassword.Text;
            _pim      = textBoxPim.Text;

            var t = 0;

            try
            {
                if (string.IsNullOrEmpty(_password))
                {
                    throw new ArgumentException(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePasswordEmty", _language));
                }

                if (_pimchosen)
                {
                    if (!int.TryParse(_pim, out t))
                    {
                        throw new FormatException(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePimWrongValue", _language));
                    }
                    if (_password.Length < 20 && t < 485)
                    {
                        throw new FormatException(LanguagePool.GetInstance().GetString(LanguageRegion, "MessagePimWrongValue", _language));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _password = null;
                _pim      = null;
                return;
            }
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 19
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
Esempio n. 20
0
        /// <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, "");
        }
Esempio n. 21
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;
            }
        }
Esempio n. 22
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();
        }
Esempio n. 23
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;
            }
        }
Esempio n. 24
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();
        }
Esempio n. 25
0
        //TODO check for partition

        /// <summary>
        ///
        /// </summary>
        /// <param name="pnpid"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public Automountusb MountUsb(string pnpid)
        {
            if (string.IsNullOrEmpty(pnpid))
            {
                throw new ArgumentNullException("pnpid");
            }

            // Get Singelton for config
            _config = Singleton <ConfigManager> .Instance.Init(_config);

            _language = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, "");
            ValidateMount vm = new ValidateMount();

            pnpid = pnpid.Replace(@"\\", @"\");
            string[]       stringindex = { "USBSTOR", "SCSI\\DISK" };
            MountVareables mvd;

            State = false;
            int start;

            foreach (string sindex in stringindex)
            {
                if (pnpid.Contains(sindex))
                {
                    try
                    {
                        start = pnpid.IndexOf(sindex);
                        pnpid = pnpid.Substring(start, pnpid.Length - start - 1);
                    }
                    catch (Exception)
                    {
                        pnpid = "";
                    }
                }
            }



            string[] sections    = _config.GetSectionNames();
            string   configPnPid = "";

            foreach (string section in sections)
            {
                Name = section;
                string configtype = _config.GetValue(section, ConfigTrm.Drive.Type, "");

                if (configtype.Equals("Container"))
                {
                    configPnPid = _config.GetValue(section, ConfigTrm.Container.Pnpid, "");
                    if (configPnPid.Equals(pnpid))
#if DEBUG
                    { MessageBox.Show(pnpid + "  " + configPnPid); }
#endif
                    {
                        if (_config.GetValue(section, ConfigTrm.Container.Automountusb, false))
                        {
                            try
                            {
                                mvd = vm.ValidateMountContainer(section, _language);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return(this);
                            }

                            int ret = Mount.MountContainer(mvd.path, mvd.driveletter, mvd.key, mvd.password, mvd.silent, mvd.beep, mvd.force, mvd.readOnly, mvd.removalbe, mvd.tc, mvd.pim, mvd.hash);

                            if (ret == 0)
                            {
                                State = true;
                            }
                            return(this);
                        }
                    }
                }


                if (configtype.Equals("Drive"))
                {
                    configPnPid = _config.GetValue(section, ConfigTrm.Drive.Pnpdeviceid, "");

                    if (configPnPid.Equals(pnpid))
                    {
#if DEBUG
                        MessageBox.Show(pnpid + "  " + configPnPid);
#endif
                        if (_config.GetValue(section, ConfigTrm.Drive.Automountusb, false))
                        {
                            try
                            {
                                mvd = vm.ValidateMountDrive(section, _language);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return(this);
                            }

                            int res = Mount.MountDrive(mvd.partitionlist, mvd.driveletter, mvd.key, mvd.password, mvd.silent, mvd.beep, mvd.force, mvd.readOnly, mvd.removalbe, mvd.pim, mvd.hash, mvd.tc);

                            if (res == 0)
                            {
                                State = true;
                            }

                            return(this);
                        }
                    }
                }
            }
            return(this);
        }
        /// <summary>
        /// Mount all containers and drives witch automountstart flag
        /// </summary>
        public void StartMount()
        {
            string         _language = _config.GetValue(ConfigTrm.Mainconfig.Section, ConfigTrm.Mainconfig.Language, "");
            ValidateMount  vm        = new ValidateMount();
            MountVareables mvd       = new MountVareables();
            List <string>  containers;
            List <string>  drives;

            containers = GetAutoContainers();
            drives     = GetAutoDrives();
            bool error = false;
            int  ret;
            int  res;

            foreach (string name in containers)
            {
                error = false;
                try
                {
                    mvd = vm.ValidateMountContainer(name, _language);
                }
                catch (DrivletterUsedException dx)
                {
                    //Dont show error if drivletter is used. Drive is probalbly mounted
                    error = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    error = true;
                }
                if (!error)
                {
                    try
                    {
                        ret = Mount.MountContainer(mvd.path, mvd.driveletter, mvd.key, mvd.password, mvd.silent, mvd.beep, mvd.force, mvd.readOnly, mvd.removalbe, mvd.tc, mvd.pim, mvd.hash);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            foreach (string name in drives)
            {
                error = false;
                try
                {
                    mvd = vm.ValidateMountDrive(name, _language);
                }
                catch (DrivletterUsedException dx)
                {
                    //Dont show error if drivletter is used. Drive is probalbly mounted
                    error = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    error = true;
                }
                if (!error)
                {
                    try
                    {
                        res = Mount.MountDrive(mvd.partitionlist, mvd.driveletter, mvd.key, mvd.password, mvd.silent, mvd.beep, mvd.force, mvd.readOnly, mvd.removalbe, mvd.pim, mvd.hash, mvd.tc);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, LanguagePool.GetInstance().GetString(LanguageRegion, "Error", _language), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }