Example #1
0
        // Encode File
        private void button1_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.InitialDirectory = _directoryPath;
            ofd.Filter           = "All Files(*.*) | *.*";
            ofd.FilterIndex      = 1;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileCryptor.EncryptFile(ofd.FileName, _authorizationForm._userCryptor);
            }
        }
Example #2
0
        public void onCreateEncryptEvent(object source, FileSystemEventArgs e)
        {
            string         newPath = this._directoryPath + "\\My sharing";
            FileAttributes atributes;

            try
            {
                atributes = File.GetAttributes(e.FullPath);
            }
            catch
            {
                return;
            }
            if ((atributes & FileAttributes.Directory) != FileAttributes.Directory)
            {
                var ext = (Path.GetExtension(e.FullPath) ?? string.Empty).ToLower();
                if (!_extensionsToBeIgnoredByWatcher.Any(ext.Equals))
                {
                    while (IsFileLocked(e.FullPath))
                    {
                        //MessageBox.Show("The requested file " + Path.GetFileName(e.FullPath) + " already exists and is used by another process!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //return;
                        Thread.Sleep(100);
                    }
                    string newFilePath = e.FullPath;
                    newPath = newFilePath.Replace(newPath, this._directoryPath);

                    System.IO.FileInfo file = new System.IO.FileInfo(newPath);
                    file.Directory.Create();
                    File.Copy(e.FullPath, newPath, true);
                    while (IsFileLocked(newPath))
                    {
                        //MessageBox.Show("The requested file " + Path.GetFileName(e.FullPath) + " already exists and is used by another process!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //return;
                        Thread.Sleep(100);
                    }
                }

                if (!_extensionsToBeIgnoredByWatcher.Any(ext.Equals))
                {
                    if ((atributes & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        FileCryptor.EncryptFile(e.FullPath, _authorizationForm._userCryptor);
                        File.Delete(e.FullPath);
                    }
                }
            }
        }