Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (data[0] == null || data[1] == null || data[2] == null)
            {
                //MessageBox.Show("Some information is missing..\n please provide all information...");
                string message = "Some information is missing !\nPlease provide all information";
                string title   = "Folder Locker";
                MessageBox.Show(message, title);

                data[0] = null;
                data[1] = null;
                data[2] = null;
                data[3] = null;
                this.Close();
            }

            if (data[0] != null && data[1] != null && data[2] != null)
            {
                try
                {
                    ch = new DirectoryInfo(data[1]);
                    // ch.Attributes = FileAttributes.Hidden;
                    // File.SetAttributes(ofd.SelectedPath, FileAttributes.Hidden);
                    // File.SetAttributes(ofd.SelectedPath, FileAttributes.System);

                    client = new FireSharp.FirebaseClient(ifc);
                    if (client == null)
                    {
                        MessageBox.Show("there was some internet error");
                    }

                    // string temp = @"C:\Users\Nikunj\Desktop\test1.aes";
                    zipFolder();
                    FileEncrypt(data[1], data[2]);
                    //  FileDecrypt(temp, @"C:\Users\Nikunj\Desktop\test1.zip", data[2]);


                    // data store in database


                    fileData fd1 = new fileData()
                    {
                        DeviceAddress = data[0],
                        FolderPath    = data[1],
                        Password      = data[2],
                        DeviceName    = data[3]
                    };

                    var set = client.Set(@"fileData/" + data[0], fd1);

                    MessageBox.Show("Folder encrypted successfully!");
                }
                catch (Exception ex) {
                    MessageBox.Show("Error occur due to " + ex);
                }

                this.Close();
            }
        }
Beispiel #2
0
        public void listBox1_DoubleClick(object sender, EventArgs e)
        {
            deviceInfo = devices.ElementAt(listBox1.SelectedIndex);
            updateUI(deviceInfo.DeviceName + "  was selected.");

            data[0] = deviceInfo.DeviceAddress.ToString();
            // data[1] = zipFolderPath;
            // data[2] = password_result;
            //  data[3] = deviceInfo.DeviceName;
            client = new FireSharp.FirebaseClient(ifc);
            if (client == null)
            {
                MessageBox.Show("there was some internet error");
            }

            var res = client.Get(@"fileData/" + data[0]);
            // var set = client.Set(@"fileData/" + data[key, 0], fd);

            fileData fd = res.ResultAs<fileData>();

            if(fd == null)
            {
                MessageBox.Show("Selected Device is not registered!");
            }
            else
            {
                data[1] = fd.FolderPath;
                data[2] = fd.Password;
                data[3] = fd.DeviceName;
               // button1.Enabled = true;
                using (Form_password f_password = new Form_password())
                {
                    f_password.ShowDialog();

                    password_result = f_password.returnValue();
                    if (password_result.Trim() == string.Empty)
                    {
                        MessageBox.Show("This Field cannot left empty!");
                        return; // return because we don't want to run normal code of buton click
                    }
                    // MessageBox.Show(password_result);

                }

                if(password_result == data[2])
                {
                    updateUI2("Device Address : "+data[0]);
                    updateUI2("Encrypted Folder : " + data[1].Remove(data[1].Length - 4, 4));
                    updateUI2("Password : "******"Device Name : "+ data[3]);
                    button1.Enabled = true;
                    updateUI("Press OK to decrypt folder.");
                }
                else
                {
                    MessageBox.Show("Please Enter Correct password!");
                    return;
                }

            }   

        }
Beispiel #3
0
        public void listBox1_DoubleClick(object sender, EventArgs e)
        {
            deviceInfo = devices.ElementAt(listBox1.SelectedIndex);
            updateUI(deviceInfo.DeviceName + "  was selected.");

            client = new FireSharp.FirebaseClient(ifc);
            if (client == null)
            {
                MessageBox.Show("there was some internet error");
            }
            var res = client.Get(@"fileData/" + deviceInfo.DeviceAddress.ToString());


            fileData fd = res.ResultAs <fileData>();

            if (fd != null)
            {
                MessageBox.Show("You have already resisterd one folder for this device!\n\nplease " +
                                "decrypt first then use this device for encryption of another folder.");
                return;
            }

            //OpenFileDialog ofd = new OpenFileDialog();
            FolderBrowserDialog ofd = new FolderBrowserDialog();

            ofd.Description = "Select your folder";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                updateUI(ofd.SelectedPath + "  Folder selected.");

                FolderPathToZip = ofd.SelectedPath.Trim();
                //to store the value of folderapth
            }
            //String path = ofd.SelectedPath;

            /*String path = @"C:\Users\Nikunj\Desktop\test1";
             * Thread thread = new Thread(t =>
             * {
             *  using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
             *  {
             *      zip.AddDirectory(path);
             *      System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
             *      // zip.SaveProgress += Zip_SaveProgress;
             *      zip.Save(string.Format("{0}{1}.zip", di.Parent.FullName, di.Name));
             *
             *  }
             * })
             * { IsBackground = true };
             * thread.Start();
             */


            /* f_password.ShowDialog();
             *
             * string deviceName = deviceInfo.DeviceName;
             * string folderName =ofd.SelectedPath ;
             *
             *
             * Form_password f_p = new Form_password();
             * string Final_password = null;
             * Final_password= f_p.returnValue();
             * updateUI(Final_password + " Set Sucessfully");
             * textBox1.Text = folderName;
             *   MessageBox.Show(Final_password);
             */
            using (Form_password f_password = new Form_password())
            {
                f_password.ShowDialog();

                password_result = f_password.returnValue();
                if (password_result.Trim() == string.Empty)
                {
                    MessageBox.Show("This Field cannot left empty!");
                    return; // return because we don't want to run normal code of buton click
                }
                // MessageBox.Show(password_result);

                updateUI(password_result + " Set Sucessfully");
            }

            for (int j = 0; j < 4; j++)
            {
                data[j] = null;
            }

            data[0] = deviceInfo.DeviceAddress.ToString();
            // data[1, key] = ofd.SelectedPath;
            //data[1] = ofd.SelectedPath;
            data[1] = FolderPathToZip + ".zip";
            data[2] = password_result;
            data[3] = deviceInfo.DeviceName;

            updateUI2("Device Address : " + data[0]);
            updateUI2("Folder path : " + data[1].Remove(data[1].Length - 4, 4));
            updateUI2("Password : "******"Device name : " + data[3]);

            button1.Enabled = true;
            updateUI("Press OK to Encrypt Selected folder.");
        }