コード例 #1
0
        public static List <SaveSetItem> ReturnSaveSetList()
        {
            var retVal = new List <SaveSetItem>();

            string path = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "fileControl");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                return(retVal);
            }

            path = System.IO.Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "fileControl", "tbhtyplsd.txt");

            if (!File.Exists(path))
            {
                return(retVal);
            }


            using (var sr = new System.IO.StreamReader(path, Encoding.Default)) {
                //Only return the active sets
                string line = string.Empty;
                while ((line = sr.ReadLine()) != null)
                {
                    SaveSetItem i = SaveSetItem.MakeItem(line);
                    if (i.IsActive == true)
                    {
                        retVal.Add(i);
                    }
                }

                sr.Close();
            }
            return(retVal);
        }
コード例 #2
0
ファイル: FolderNode.cs プロジェクト: rickmmrr/FileControl
        /// <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.");
            }
        }