public bool SearchSaveSets(string searchString, ListView view) { List <SaveSetItem> l = ManageSaveSet.ReturnSaveSetList(); List <SaveSetItem> retList = new List <SaveSetItem>(); searchString = searchString.ToLower(); foreach (SaveSetItem ssi in l) { string name = ssi.SaveSetName.ToLower(); string comment = ssi.Comment.ToLower(); if (name.Contains(searchString)) { retList.Add(ssi); continue; } if (comment.Contains(searchString)) { retList.Add(ssi); continue; } } if (retList.Count > 0) { view.Items.Clear(); foreach (SaveSetItem i in retList) { var t = new string[5]; t[0] = i.SaveSetName; t[1] = i.CreationDate.ToShortDateString(); t[2] = i.Comment; t[3] = i.Password; t[4] = i.TotalFileCount.ToString(); view.Items.Add(new ListViewItem(t)); view.Items[view.Items.Count - 1].Tag = i.IndexIntoFile; } return(true); } else { MessageBox.Show("No encrypted files contain that search phrase."); } return(false); }
public void PopulateTheItemsFromSaveSetOnSelect(ListView ssDetails, ListView ssSaveSet) { //It should be only one var indexCollection = ssSaveSet.SelectedIndices; ListViewItem lvi = ssSaveSet.Items[indexCollection[0]]; long indexIntoFile = (long)lvi.Tag; int totalFiles = Convert.ToInt32(lvi.SubItems[4].Text); List <EncryptedFileItem> r = ManageSaveSet.ReturnEncryptedFolderList(indexIntoFile, totalFiles); ssDetails.Items.Clear(); foreach (EncryptedFileItem i in r) { string[] t = new string[4]; t[0] = i.originalName; t[1] = i.newName; t[2] = "File Type"; t[3] = "Launch"; ListViewItem lvin = new ListViewItem(t); ssDetails.Items.Add(lvin); } }
public void PopulateSaveSetListView(ListView ssDetails, ListView ssListView) { ssListView.Items.Clear(); ssDetails.Items.Clear(); List <SaveSetItem> l = ManageSaveSet.ReturnSaveSetList(); if (l.Count == 0) { return; } foreach (SaveSetItem i in l) { var t = new string[5]; t[0] = i.SaveSetName; t[1] = i.CreationDate.ToShortDateString(); t[2] = i.Comment; t[3] = i.Password; t[4] = i.TotalFileCount.ToString(); ssListView.Items.Add(new ListViewItem(t)); ssListView.Items[ssListView.Items.Count - 1].Tag = i.IndexIntoFile; } }
public bool SearchFileNames(string searchString, ListView view) { var ssL = ManageSaveSet.ReturnSaveSetList(); return(true); }
/// <summary> /// Convert all the files /// Encrypt all the files /// </summary> /// <param name="listViewFiles"></param> public void ConvertFiles(ListView listViewFiles, string encryptionKey) { const bool ACTUALLY_ENCRYPT = false; //Create a list of original file names var f = new List <string>(); foreach (ListViewItem i in listViewFiles.Items) { f.Add(i.SubItems[0].Text); } NewSaveSetDlg dlg = new NewSaveSetDlg(); dlg.fileList = f; dlg.ShowDialog(); if (dlg.dialogResult == NewSaveSetDlg.DialogResult.OK) { var finishedList = new List <EncryptedFileItem>(); try { foreach (ListViewItem i in listViewFiles.Items) { string originalName = i.SubItems[0].Text; string newName = i.SubItems[1].Text; string status = i.SubItems[2].Text; string count = i.SubItems[3].Text; string path = i.SubItems[4].Text; finishedList.Add(EncryptedFileItem.MakeItem(dlg.Name, originalName, newName, path, count)); string source = Path.Combine(path, originalName); string destination = Path.Combine(path, newName); i.SubItems[2].Text = "Encrypting File"; Application.DoEvents(); SimpleEncryption.EncryptFile(source, destination, encryptionKey, ACTUALLY_ENCRYPT); i.SubItems[2].Text = "Convertion Complete"; Application.DoEvents(); } } catch (Exception ex) { //delete any converted file so as to resore directory before conversion foreach (EncryptedFileItem fi in finishedList) { string destination = Path.Combine(fi.path, fi.newName); if (File.Exists(destination)) { File.Delete(destination); } } foreach (ListViewItem i in listViewFiles.Items) { i.SubItems[2].Text = "To Convert"; } Application.DoEvents(); throw new Exception("An error occured in the conversion process. Restored all files back to before conversion started. ERROR = " + ex.Message); } if (ACTUALLY_ENCRYPT) { //now delete the original foreach (EncryptedFileItem fi in finishedList) { string source = Path.Combine(fi.path, fi.originalName); if (File.Exists(source)) { File.Delete(source); } } } //Now create the saveSetItem var ssi = SaveSetItem.MakeItem(dlg.Name, dlg.Comment, encryptionKey); ManageSaveSet.UpdateSaveSet(finishedList, ssi); } else { MessageBox.Show("Canceled encryption of files."); } }