예제 #1
0
        private void ListView1_DragDrop(object sender, DragEventArgs e)
        {
            string filename;

            byte[] encbytes;
            key = GetDrivePassword(label_Path.Text.Substring(0, 1));

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            foreach (string file in files)
            {
                FileAttributes attr = File.GetAttributes(file);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    string logPath;
                    logPath  = label_Path.Text + "\\" + file + "\\";
                    filename = file.Substring(file.LastIndexOf('\\') + 1);
                    Encrypt_Directory(filename, label_Path.Text, file);
                }
                else
                {
                    string logPath;
                    //MessageBox.Show(file);
                    logPath  = label_Path.Text + "\\" + file.Replace("\\\\", "\\").Substring(file.LastIndexOf("\\") + 1);
                    filename = Path.GetFileName(file);
                    encbytes = k.AESEncrypto256(File.ReadAllBytes(file), key);
                    File.WriteAllBytes(label_Path.Text + "\\" + filename + ".enc", encbytes);
                    SslTcpClient.LogRunClient(StatUser.id, logPath, StatUser.state[1], StatUser.outip());
                }
            }
            SettingListView(label_Path.Text);
        }
예제 #2
0
 private void ListView1_KeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         if (e.KeyCode.Equals(Keys.Delete))
         {
             ListViewItem   item = listView1.SelectedItems[0];
             string         file = label_Path.Text + "\\" + item.Text;
             string         logPath;
             FileAttributes attr = File.GetAttributes(file);
             // 디렉토리는 하위폴더까지 다지워줘야함
             if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
             {
                 logPath = file + "\\";
                 DirectoryInfo di = new DirectoryInfo(file);
                 di.Delete(true);
                 SslTcpClient.LogRunClient(StatUser.id, logPath, "4", StatUser.outip());
             }
             File.Delete(file);
             logPath = label_Path.Text + "\\" + item.Text;
             SslTcpClient.LogRunClient(StatUser.id, logPath, "4", StatUser.outip());
             SettingListView(label_Path.Text);
         }
         else if (e.KeyCode.Equals(Keys.F5))
         {
             SettingListView(label_Path.Text);
         }
         else if (e.KeyData == Keys.F2)
         {
             listView1.SelectedItems[0].BeginEdit();
         }
     }
     catch (Exception e1)
     {
         //MessageBox.Show("error: " + e1);
     }
 }
예제 #3
0
        void Encrypt_Directory(string filename, string path, string copyfilepath)// filename: 디렉토리 이름, path: 파일경로, copyfilepath: 원본파일경로
        {
            // 1. 디렉토리 생성
            string        directory = path + "\\" + filename;
            DirectoryInfo di        = new DirectoryInfo(directory);

            di.Create();

            // 2. 파일을 모두 암호화함
            DirectoryInfo dir = new DirectoryInfo(copyfilepath);

            FileInfo[] files = dir.GetFiles();
            byte[]     encbytes;
            key = GetDrivePassword(label_Path.Text.Substring(0, 1));
            foreach (FileInfo fileinfo in files)
            {
                string logPath;
                logPath = label_Path.Text + "\\" + fileinfo.Name;
                //MessageBox.Show("name: " + fileinfo.Name);
                encbytes = k.AESEncrypto256(File.ReadAllBytes(fileinfo.FullName), key);
                File.WriteAllBytes(directory + "\\" + fileinfo.Name + ".enc", encbytes);
                SslTcpClient.LogRunClient(StatUser.id, logPath, "1", StatUser.outip());
            }
            // 3. 디렉토리를 모두 찾아서 재귀함수돌림
            foreach (DirectoryInfo dirItem in dir.GetDirectories())
            {
                Encrypt_Directory(dirItem.Name, directory, dirItem.FullName);
                string logPath;
                logPath = label_Path.Text + "\\" + dirItem.Name + "\\";
                SslTcpClient.LogRunClient(StatUser.id, logPath, "1", StatUser.outip());

                /*MessageBox.Show(
                 *  "filename: " + dirItem.Name +
                 *  "\npath: " + directory +
                 *  "\ncopyfilepath: " + dirItem.FullName);*/
            }
        }
예제 #4
0
        private void ListView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                //back = label1.Text;
                byte[]       decbytes;
                ListViewItem item = listView1.SelectedItems[0];
                string       file;

                file = (label_Path.Text + "\\" + item.Text).Replace("\\\\", "\\");

                FileAttributes attr = File.GetAttributes(file);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    back_stack.AddLast(label_Path.Text);
                    SetButtonEnable();
                    label_Path.Text = file;
                    SettingListView(file);
                }
                else
                {
                    if (file.Contains(".enc"))
                    {
                        Thread t1 = new Thread(new ThreadStart(Run));
                        t1.Start();
                        waitforsinglesignal.WaitOne();
                        void Run()
                        {
                            try
                            {
                                string logPath;
                                logPath = label_Path.Text + "\\" + file.Substring(file.LastIndexOf("\\") + 1);
                                //MessageBox.Show(logPath);

                                key      = GetDrivePassword(label_Path.Text.Substring(0, 1));
                                decbytes = k.AESDecrypto256(File.ReadAllBytes(file), key);
                                file     = file.Replace(".enc", "");
                                file     = label_Path.Text.Substring(0, label_Path.Text.IndexOf("\\")) + "\\.start\\" + file.Substring(file.LastIndexOf("\\") + 1);
                                FileStream fs = File.Create(file);
                                fs.Close();
                                File.WriteAllBytes(file, decbytes);
                                waitforsinglesignal.Set();
                                string filename = Path.GetFileName(file);
                                process_FileStart.StartInfo.FileName         = filename;
                                process_FileStart.StartInfo.WorkingDirectory = label_Path.Text.Substring(0, label_Path.Text.IndexOf("\\")) + "\\.start\\";
                                process_FileStart.StartInfo.WindowStyle      = ProcessWindowStyle.Normal;
                                FileInfo fi = new FileInfo(process_FileStart.StartInfo.WorkingDirectory + "\\" + process_FileStart.StartInfo.FileName);
                                process_FileStart.Start();
                                //MessageBox.Show(logPath);
                                SslTcpClient.LogRunClient(StatUser.id, logPath, StatUser.state[0], StatUser.outip());
                            }
                            catch (Exception e1)
                            {
                                MessageBox.Show(e1.Message);
                            }
                        }
                    }
                    SettingListView(label_Path.Text);
                }
            }
            catch (Exception e1)
            {
                //MessageBox.Show("에러 : " + e1.Message);
            }
        }