private void btnManualEncode_Click(object sender, EventArgs e) { try { string pass = GetMessagePasswordNoID(); if (pass == null) return; if (radioManualEncode.Checked) { string messagePath = GetMessageInput(cmbManualFileType, tbManualText, tbManualStatus); if (String.IsNullOrEmpty(tbManualImage.Text)) { return; } int size = GetSplitSize(); if (size < 0) return; string encodeFile = tbManualImage.Text; SimplerAES aes = new SimplerAES(pass); messagePath = aes.EncryptFile(messagePath); List<string> a = SplitFileIntoPart(messagePath, size); List<string> coverFile = new List<string>(); coverFile.Add(encodeFile); if (!GetMoreImage(a, coverFile)) return; List<string> FailFile = new List<string>(); string flag = ""; int count = 0; string successFile = ""; for (int i = 0; i < a.Count; i++) { //string newFile = Common.AppendFileName(encodeFile, i.ToString()); //File.Copy(encodeFile, newFile, true); bool isTest = Path.GetDirectoryName(coverFile[i]).Equals(Path.Combine(FB_Image.RelativeDirectory, "SuccessImage")); flag = EncodeImage(coverFile[i], a[i], null, isTest); if (flag != null) { string outputdir = Path.Combine(Path.Combine(FB_Image.RelativeDirectory, FB_Image.OutputDir)); if (!Directory.Exists(outputdir)) { Directory.CreateDirectory(outputdir); } successFile = MyHelper.CopyFileTo(Path.Combine(FB_Image.BaseDirectory, flag), outputdir); count++; } else { FailFile.Add(a[i]); } } if (FailFile.Count > 0) { MessageBox.Show("These images are not ready for sending your message"); } else { OpenFolder(successFile); MessageBox.Show("Encoding Success"); } } else { if (manualListFile != null && manualListFile.Length >= 1) { manualInbox = new InboxUser("1", "Manual"); foreach (string item in manualListFile) { byte[] content = MyHelper.GetByteFromImage(item); if (content != null) { string s_content = CorrectErrorString(content); if (s_content != null) { //userInbox.Messages.Add(new FB_Message(content, new FB_Image(imageId,imagePath),createdTime,isSent)); bool flag = manualInbox.AddMessageToInbox(s_content, "1", item, 0); if (flag) manualInbox.CountNew++; } } } if (manualInbox.Messages.Count >= 0) { foreach (FB_Message mes in manualInbox.Messages) { string s = ""; if (mes.Part.Count >= 1) { s += "Images path:" + Environment.NewLine; foreach (MessagePart p in mes.Part) { s += p.ImagePath + Environment.NewLine; } s += "Message: "; string content = mes.GetContent(pass); if (content != null) s += content + Environment.NewLine; else s += "No Output" + Environment.NewLine; s += "---------------------------------" + Environment.NewLine; tbManualStatus.AppendText(s); } } } } } } catch (Exception ex) { Log(ex); } }
private async void uploadImage_Click(object sender, EventArgs e) { try { int size = GetSplitSize(); if (size == -1) return; if (lbFriendID.Text != "...") { string messagePath = GetMessageInput(cmbSelectTextType, tbMessagePath, tbInputMessage); string bkMessagePath= messagePath; string encodeFile = tbImagePath.Text; List<string> tagList = new List<string>(); tagList.Add(lbFriendID.Text); if (sentPass == null) return; SimplerAES aes = new SimplerAES(sentPass); messagePath = aes.EncryptFile(messagePath); List<string> a = SplitFileIntoPart(messagePath, size); List<string> coverFile = new List<string>(); coverFile.Add(encodeFile); bool retry = false; while (true) { if (!GetMoreImage(a, coverFile, retry)) return; List<string> FailFile = new List<string>(); string albumId = cmbInputAlbum.SelectedValue.ToString(); var progress = new Progress<string>(s => { MyHelper.ShowProgressBar(s, pbStatus, lbStatusBar, lbDoing); }); int count = 0; for (int i = 0; i < a.Count; i++) { //string newFile = Common.AppendFileName(encodeFile, i.ToString()); //File.Copy(encodeFile, newFile, true); string flag = ""; if (Path.GetDirectoryName(coverFile[i]).Equals(Path.Combine(FB_Image.RelativeDirectory, "SuccessImage"))) await Task.Factory.StartNew(() => flag = SendImageWithTag(progress, coverFile[i], a[i], tagList, albumId), TaskCreationOptions.LongRunning); else await Task.Factory.StartNew(() => flag = SendNoTestImageWithTag(progress, coverFile[i], a[i], albumId, tagList), TaskCreationOptions.LongRunning); if (flag != null) { count++; } else { FailFile.Add(a[i]); } } if (FailFile.Count > 0) { if (DialogResult.Retry == MessageBox.Show("There are " + FailFile.Count.ToString() + " fail images. Do you want to retry ?", "Sent Fail", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)) { coverFile.Clear(); a.Clear(); a.AddRange(FailFile); retry = true; } else { break; } } else { MessageBox.Show("The message has been sent"); InboxUser currentSentInbox = MyHelper.GetInboxByUserID(lbFriendID.Text, ListInboxUser); FB_Message sentMes = new FB_Message(File.ReadAllText(bkMessagePath), new FB_Image("0", encodeFile), MyHelper.GetUnixTimesStamp(DateTime.Now), true); currentSentInbox.Messages.Add(sentMes); break; } } MyHelper.ResetStatusTrip(pbStatus, lbStatusBar, lbDoing); // Common.DeleteFile(Common.listFileDelete); } else { MessageBox.Show("Please choose a Friend", "Choose A Friend", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log(ex); MyHelper.ResetStatusTrip(pbStatus, lbStatusBar, lbDoing); MessageBox.Show("There are some error with these images","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } }