예제 #1
0
        public static SaveSetItem MakeItem(string saveSetName, string comment, string password)
        {
            var s = new SaveSetItem();

            s.Comment      = comment;
            s.CreationDate = DateTime.Now;
            s.Password     = password;
            s.SaveSetName  = saveSetName;
            return(s);
        }
예제 #2
0
        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();
        }
예제 #3
0
        public static string MakeLine(SaveSetItem s)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(s.SaveSetName);
            sb.Append("|");
            sb.Append(s.CreationDate.ToString());
            sb.Append("|");
            sb.Append(s.Comment);
            sb.Append("|");
            sb.Append(s.Password);
            sb.Append("|");
            sb.Append(s.IndexIntoFile.ToString());
            sb.Append("|");
            sb.Append(s.TotalFileCount.ToString());
            sb.Append("|");
            sb.Append(s.IsActive.ToString());
            return(sb.ToString());
        }
예제 #4
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);
        }
예제 #5
0
        public static SaveSetItem MakeItem(string fromFile)
        {
            string[] split = fromFile.Split(new char[] { '|' });

            var s = new SaveSetItem();

            string[]      tc = split[2].Trim().Split(new string[] { "/CL/" }, StringSplitOptions.None);
            StringBuilder sb = new StringBuilder();

            foreach (string sc in tc)
            {
                sb.AppendLine(sc);
            }
            s.Comment        = sb.ToString();
            s.CreationDate   = DateTime.Parse(split[1]);
            s.Password       = split[3].Trim();
            s.SaveSetName    = split[0].Trim();
            s.TotalFileCount = Convert.ToInt32(split[5]);
            s.IndexIntoFile  = Convert.ToInt64(split[4]);
            s.IsActive       = bool.Parse(split[6]);
            return(s);
        }
예제 #6
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.");
            }
        }