Пример #1
0
        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);
                }
        }
Пример #2
0
        /// <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.");
            }
        }