Ejemplo n.º 1
0
        /// <summary>
        /// 重新加密
        /// </summary>
        public void ReEncrypt()
        {
            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                try
                {
                    InvokeDelegate invokeDelegate = delegate()
                    {
                        pbDir.Value             = 0;
                        lblProgressDir.Text     = "0%";
                        pbFile.Value            = 0;
                        lblProgressFile.Text    = "0%";
                        pbDir.Visible           = true;
                        lblProgressDir.Visible  = true;
                        pbFile.Visible          = false;
                        lblProgressFile.Visible = false;
                        lblShowPath.Text        = "加密文件夹:" + Application.StartupPath;
                        lblShowPath.Visible     = true;
                        DisableBtns();
                    };
                    InvokeUtil.Invoke(this, invokeDelegate);
                    DateTime t1 = DateTime.Now;
                    DirectoryEncrypt.EncryptCurrentDirectory(Application.StartupPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                    DateTime t2 = DateTime.Now;
                    string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                    if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                    {
                        invokeDelegate = delegate()
                        {
                            EnableBtns();
                            Application.Exit(); //加密成功后关闭程序
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK)
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            EnableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
            }));

            thread.Start();
        }
Ejemplo n.º 2
0
        private void btnEncryptThis_Click(object sender, EventArgs e)
        {
            #region 验证
            if (txtPwd.Text == "")
            {
                MessageBox.Show("密码不能为空", "提示");
                return;
            }

            if (txtPwdCfm.Text == "")
            {
                MessageBox.Show("xwuser密码不能为空", "提示");
                return;
            }
            #endregion

            if (MessageBox.Show(string.Format("确定加密当前文件夹?"),
                                "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                try
                {
                    InvokeDelegate invokeDelegate = delegate()
                    {
                        pbDir.Value             = 0;
                        lblProgressDir.Text     = "0%";
                        pbFile.Value            = 0;
                        lblProgressFile.Text    = "0%";
                        pbDir.Visible           = true;
                        lblProgressDir.Visible  = true;
                        pbFile.Visible          = false;
                        lblProgressFile.Visible = false;
                        lblShowPath.Text        = "加密文件夹:" + Application.StartupPath;
                        lblShowPath.Visible     = true;
                        DisableBtns();
                    };
                    InvokeUtil.Invoke(this, invokeDelegate);
                    DateTime t1 = DateTime.Now;
                    DirectoryEncrypt.EncryptCurrentDirectory(Application.StartupPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                    DateTime t2 = DateTime.Now;
                    string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                    if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                    {
                        invokeDelegate = delegate()
                        {
                            EnableBtns();
                            Application.Exit(); //加密成功后关闭程序
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK)
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            EnableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
            }));
            thread.Start();
        }
Ejemplo n.º 3
0
        private void btnDecryptThis_Click(object sender, EventArgs e)
        {
            #region 验证
            if (txtPwd.Text == "")
            {
                MessageBox.Show("密码不能为空", "提示");
                return;
            }
            #endregion

            if (MessageBox.Show(string.Format("确定解密当前文件夹?"),
                                "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                try
                {
                    InvokeDelegate invokeDelegate = delegate()
                    {
                        pbDir.Value             = 0;
                        lblProgressDir.Text     = "0%";
                        pbFile.Value            = 0;
                        lblProgressFile.Text    = "0%";
                        pbDir.Visible           = true;
                        lblProgressFile.Visible = true;
                        pbFile.Visible          = false;
                        lblProgressFile.Visible = false;
                        lblShowPath.Text        = "解密文件夹:" + Application.StartupPath;
                        lblShowPath.Visible     = true;
                        DisableBtns();
                    };
                    InvokeUtil.Invoke(this, invokeDelegate);
                    DateTime t1 = DateTime.Now;
                    DirectoryEncrypt.DecryptCurrentDirectory(Application.StartupPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                    DateTime t2 = DateTime.Now;
                    string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                    if (MessageBox.Show("解密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                    {
                        invokeDelegate = delegate()
                        {
                            EnableBtns();
                            if (Properties.Settings.Default.NotifyUse)
                            {
                                //解密成功后最小化程序
                                txtPwdCfm.Text      = txtPwd.Text;
                                this.WindowState    = FormWindowState.Minimized;
                                this.Visible        = false;
                                notifyIcon1.Visible = true;
                            }
                            else
                            {
                                Application.Exit();
                            }
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show("解密失败:" + ex.Message, "提示") == DialogResult.OK)
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            EnableBtns();
                            tryCount++;
                            if (tryCount == maxTryCount)
                            {
                                this.Close();
                            }
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
            }));
            thread.Start();
        }
Ejemplo n.º 4
0
        private void btnDecryptDir_Click(object sender, EventArgs e)
        {
            #region 验证
            if (txtPwd.Text == "")
            {
                MessageBox.Show("密码不能为空", "提示");
                return;
            }
            #endregion

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                if (MessageBox.Show(string.Format("确定解密文件夹{0}?", folderBrowserDialog1.SelectedPath),
                                    "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }

                Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
                {
                    try
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            pbDir.Value             = 0;
                            lblProgressDir.Text     = "0%";
                            pbFile.Value            = 0;
                            lblProgressFile.Text    = "0%";
                            pbDir.Visible           = true;
                            lblProgressFile.Visible = true;
                            pbFile.Visible          = false;
                            lblProgressFile.Visible = false;
                            lblShowPath.Text        = "解密文件夹:" + folderBrowserDialog1.SelectedPath;
                            lblShowPath.Visible     = true;
                            DisableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                        DateTime t1 = DateTime.Now;
                        DirectoryEncrypt.DecryptDirectory(folderBrowserDialog1.SelectedPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                        DateTime t2 = DateTime.Now;
                        string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                        if (MessageBox.Show("解密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                        {
                            invokeDelegate = delegate()
                            {
                                EnableBtns();
                            };
                            InvokeUtil.Invoke(this, invokeDelegate);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (MessageBox.Show("解密失败:" + ex.Message, "提示") == DialogResult.OK)
                        {
                            InvokeDelegate invokeDelegate = delegate()
                            {
                                EnableBtns();
                                tryCount++;
                                if (tryCount == maxTryCount)
                                {
                                    this.Close();
                                }
                            };
                            InvokeUtil.Invoke(this, invokeDelegate);
                        }
                    }
                }));
                thread.Start();
            }
        }