Esempio n. 1
0
 private bool ImportAttachment()
 {
     foreach (String att in Operations.Content.Message.Attachments.Split(new string[] { "||" }, StringSplitOptions.None))
     {
         try
         {
             if (!att.Contains("|"))
             {
                 continue;
             }
             WorkSpace.Attachments GetAtt = new WorkSpace.Attachments();
             string[] Temp = GetAtt.Download(att.Split('|')[1]);
             Attachments.Add(att.Split('|')[0], Temp[0]);
         }
         catch (Exception)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
        private void DownloadNow()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(DownloadNow));
                return;
            }
            DialogResult A = MessageBox.Show("Download '" + FileNameX + "'?", "DOWLOAD?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (A == DialogResult.No)
            {
                CallDefaultIcon();
                return;
            }
            // OpenDialog to select local
            FolderBrowserDialog Folder = new FolderBrowserDialog();

            Folder.ShowNewFolderButton = true;
            Folder.Description         = "Select folder to save this file!";
            Folder.ShowDialog();
            if (String.IsNullOrEmpty(Folder.SelectedPath))
            {
                MessageBox.Show("No path selected!", "EMPTY!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CallDefaultIcon();
                return;
            }
            // Finish all pre then download
            Attachments DownloadAtt = new Attachments();

            string[] TempData = DownloadAtt.Download(AttachmentId);
            if (IsEncrypted == true)
            {
                DialogResult ask = MessageBox.Show("This file is encrypted! Do you want decrypt it now?", "DECRYPT THIS FILE?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (ask == DialogResult.Yes)
                {
                    // Check key
                    EnterKey KeyIn = new EnterKey();
                    while (true)
                    {
                        Operations.Content.Message.CurrentPassword = string.Empty;
                        KeyIn.ShowDialog();
                        if (Operations.Content.Message.CurrentPassword == string.Empty)
                        {
                            MessageBox.Show("This content is WhiteSpace or Empty!",
                                            "NO CONTENT", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            continue;
                        }
                        #region For Decrypt
                        byte[] Temp;
                        switch (Operations.GlobalVarriable.KindOfCrypt)
                        {
                        case 0:
                        {
                            Temp = Operations.AES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 1:
                        {
                            Temp = Operations.DES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 2:
                        {
                            Temp = Operations.TwoFish.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        case 3:
                        {
                            Temp = Operations.BlowFish.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }

                        default:
                            Temp = Operations.AES.DecryptFile(TempData[0], Operations.Content.Message.CurrentPassword);
                            break;
                        }
                        #endregion
                        if (Temp == null)
                        {
                            DialogResult C = MessageBox.Show("Wrong password! Do you want to try again?", "TRY AGAIN?", MessageBoxButtons.YesNo,
                                                             MessageBoxIcon.Question);
                            if (C == DialogResult.No)
                            {
                                DialogResult D = MessageBox.Show("Try to download without decrypt?", "TRY TO DOWNLOAD?",
                                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (DialogResult.No == D)
                                {
                                    CallDefaultIcon();
                                    return;
                                }
                                else
                                {
                                    Operations.Content.Message.CurrentPassword = string.Empty;
                                    break;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            try
                            {
                                string SavePath = Path.Combine(Folder.SelectedPath, FileNameX);
                                while (File.Exists(SavePath))
                                {
                                    System.Security.Cryptography.MD5 Hash = System.Security.Cryptography.MD5.Create();
                                    SavePath = Folder.SelectedPath + "\\" +
                                               Path.GetFileNameWithoutExtension(FileNameX) +
                                               "_" + BitConverter.ToString(Hash.ComputeHash(
                                                                               Encoding.UTF8.GetBytes(DateTime.Now.ToString()))).Replace("-", "") +
                                               Path.GetExtension(FileNameX);
                                }
                                File.WriteAllBytes(SavePath, Temp);
                                SuccessBox.Show("Successfully decrypted!");
                                Temp        = null;
                                TempData    = null;
                                DownloadAtt = null;
                                CallDefaultIcon();
                                return;
                            }
                            catch (Exception ee)
                            {
                                MessageBox.Show("Can not save '" + FileNameX + "', Try run this program with administration and try again!",
                                                "CAN NOT SAVE!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                CallDefaultIcon();
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    }
                }
            }
            // No encrypt
            try
            {
                string SavePath = Path.Combine(Folder.SelectedPath, FileNameX);
                while (File.Exists(SavePath))
                {
                    System.Security.Cryptography.MD5 Hash = System.Security.Cryptography.MD5.Create();
                    SavePath = Folder.SelectedPath + "\\" +
                               Path.GetFileNameWithoutExtension(FileNameX) +
                               "_" + BitConverter.ToString(Hash.ComputeHash(
                                                               Encoding.UTF8.GetBytes(DateTime.Now.ToString()))).Replace("-", "") +
                               Path.GetExtension(FileNameX);
                }
                File.WriteAllBytes(SavePath, Convert.FromBase64String(TempData[0]));
                SuccessBox.Show("Successfully saved!");
                TempData    = null;
                DownloadAtt = null;
                CallDefaultIcon();
                return;
            }
            catch (Exception ee)
            {
                MessageBox.Show("Can not save '" + FileNameX + "', Try run this program with administration and try again!",
                                "CAN NOT SAVE!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                CallDefaultIcon();
                MessageBox.Show(ee.ToString());
                return;
            }
        }