private void delete_Click(object sender, EventArgs e) { if (profilesListView.SelectedItems.Count == 0) return; if (MessageBox.Show("Are you sure you want to delete the profile " + profilesListView.SelectedItems[0].Text + " and all the data it contains?", "Delete Profile", MessageBoxButtons.YesNo) == DialogResult.Yes) { // Delete the profile from the list ... if (profilesListView.SelectedItems.Count > 0) { CryptoEditorProfile tmpProfile = new CryptoEditorProfile(); tmpProfile.Load(SelectedProfileFile); tmpProfile.PasswordValidated = false; CryptoEditorPasswordForm formPassword = new CryptoEditorPasswordForm(); while (formPassword.ShowDialog() == DialogResult.OK) { string tmpPassword = CryptoEditorEncryption.Hash(formPassword.Password); if (tmpPassword.Equals(tmpProfile.EncryptedPassword)) { string toDelete = tmpProfile.Id + "*.*"; string[] filesToDelete = Directory.GetFiles(Path.GetDirectoryName(SelectedProfileFile), toDelete); foreach(string file in filesToDelete) { System.IO.File.Delete(file); } LoadProfiles(); break; } MessageBox.Show("The password is incorrect! Please retype your password.", "Incorrect password", MessageBoxButtons.OK, MessageBoxIcon.Stop); formPassword.Password = ""; } } } profilesListView.Select(); }
private void LoadProfiles() { profilesListView.Items.Clear(); CryptoEditorUtils.CheckApplicationDataFolder(); string[] files = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\CryptoEditor\", "*.profile"); foreach (string file in files) { CryptoEditorProfile profile = new CryptoEditorProfile(); profile.Load(file); ListViewItem item = profilesListView.Items.Add(profile.Name); item.Tag = file; item.SubItems.Add(profile.Email); } open.Enabled = false; delete.Enabled = false; }