public static EncryptedFileItem MakeItem(string saveSet, string originalName, string newName, string path, string count) { var c = new EncryptedFileItem(); c.count = int.Parse(count); c.newName = newName; c.originalName = originalName; c.path = path; c.SaveSetName = saveSet; return(c); }
public static EncryptedFileItem MakeItem(string fromFile) { string[] split = fromFile.Split(new char[] { '|' }); var i = new EncryptedFileItem(); i.count = Convert.ToInt32(split[4]); i.newName = split[2]; i.originalName = split[1]; i.path = split[3]; i.SaveSetName = split[0]; return(i); }
public static string MakeLine(EncryptedFileItem c) { StringBuilder sb = new StringBuilder(); sb.Append(c.SaveSetName); sb.Append("|"); sb.Append(c.originalName); sb.Append("|"); sb.Append(c.newName); sb.Append("|"); sb.Append(c.path); sb.Append("|"); sb.Append(c.count.ToString()); return(sb.ToString()); }
public static void UpdateSaveSet(List <EncryptedFileItem> items, SaveSetItem saveSet) { //first append the file items to the file item file long locStartIndex = 0; string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FileControl"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path = System.IO.Path.Combine(path, "edcvfgtbn.txt"); using (var fs = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) using (var sw = new System.IO.StreamWriter(fs)) { locStartIndex = fs.Seek(0, System.IO.SeekOrigin.End); foreach (EncryptedFileItem ii in items) { sw.WriteLine(EncryptedFileItem.MakeLine(ii)); } sw.Flush(); sw.Close(); } //add index and count saveSet.IndexIntoFile = locStartIndex; saveSet.TotalFileCount = items.Count; saveSet.IsActive = true; //now save the save set using (var sw = new System.IO.StreamWriter(System.IO.Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "fileControl", "tbhtyplsd.txt") , true, Encoding.Default)) { sw.WriteLine(SaveSetItem.MakeLine(saveSet)); sw.Flush(); sw.Close(); } Properties.Settings.Default.themeIndex += items.Count; Properties.Settings.Default.Save(); }
public static List <EncryptedFileItem> ReturnEncryptedFolderList(long fileIndex, int totalCount) { string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FileControl"); path = System.IO.Path.Combine(path, "edcvfgtbn.txt"); var retVal = new List <EncryptedFileItem>(); using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read)) using (var sw = new System.IO.StreamReader(fs)) { fs.Seek(fileIndex, System.IO.SeekOrigin.Begin); for (int x = 0; x < totalCount; x++) { retVal.Add(EncryptedFileItem.MakeItem(sw.ReadLine())); } sw.Close(); return(retVal); } }
/// <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."); } }