public void CancelDocumentDownloading(TLDecryptedMessageMediaDocument mediaDocument) { mediaDocument.DownloadingProgress = 0.0; var fileManager = IoC.Get <IEncryptedFileManager>(); fileManager.CancelDownloadFile(mediaDocument); }
private static TLDecryptedMessageMediaBase GetDecryptedMediaDocument(StorageFile file, TLEncryptedChat chat, TLPhotoSize thumb, ulong size, Telegram.Api.WindowsPhone.Tuple <TLString, TLString> keyIV, TLEncryptedFile fileLocation) { TLDecryptedMessageMediaBase decryptedMediaDocument; var chat17 = chat as TLEncryptedChat17; if (chat17 != null) { if (chat17.Layer.Value >= Constants.MinSecretChatWithCaptionsLayer) { decryptedMediaDocument = new TLDecryptedMessageMediaDocument45 { Thumb = thumb != null ? thumb.Bytes : TLString.Empty, ThumbW = thumb != null ? thumb.W : new TLInt(0), ThumbH = thumb != null ? thumb.H : new TLInt(0), FileName = new TLString(Path.GetFileName(file.Name)), MimeType = new TLString(file.ContentType), Size = new TLInt((int)size), Key = keyIV.Item1, IV = keyIV.Item2, Caption = TLString.Empty, File = fileLocation, StorageFile = file, UploadingProgress = 0.001 }; } else { decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = thumb != null ? thumb.Bytes : TLString.Empty, ThumbW = thumb != null ? thumb.W : new TLInt(0), ThumbH = thumb != null ? thumb.H : new TLInt(0), FileName = new TLString(Path.GetFileName(file.Name)), MimeType = new TLString(file.ContentType), Size = new TLInt((int)size), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, StorageFile = file, UploadingProgress = 0.001 }; } } else { decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = thumb != null ? thumb.Bytes : TLString.Empty, ThumbW = thumb != null ? thumb.W : new TLInt(0), ThumbH = thumb != null ? thumb.H : new TLInt(0), FileName = new TLString(Path.GetFileName(file.Name)), MimeType = new TLString(file.ContentType), Size = new TLInt((int)size), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, StorageFile = file, UploadingProgress = 0.001 }; } return(decryptedMediaDocument); }
private static TLDecryptedMessageMediaBase GetDecryptedMediaDocument(Photo p, TLEncryptedChat chat, TLString thumb, TLInt thumbW, TLInt thumbH, TLString mimeType, Telegram.Api.WindowsPhone.Tuple <TLString, TLString> keyIV, TLEncryptedFile fileLocation) { TLDecryptedMessageMediaBase decryptedMediaDocument; var chat17 = chat as TLEncryptedChat17; if (chat17 != null) { if (chat17.Layer.Value >= Constants.MinSecretChatWithCaptionsLayer) { decryptedMediaDocument = new TLDecryptedMessageMediaDocument45 { Thumb = thumb, ThumbW = thumbW, ThumbH = thumbH, FileName = new TLString(Path.GetFileName(p.FileName)), MimeType = mimeType, Size = new TLInt(p.Bytes.Length), Key = keyIV.Item1, IV = keyIV.Item2, Caption = TLString.Empty, File = fileLocation, UploadingProgress = 0.001 }; } else { decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = thumb, ThumbW = thumbW, ThumbH = thumbH, FileName = new TLString(Path.GetFileName(p.FileName)), MimeType = mimeType, Size = new TLInt(p.Bytes.Length), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, UploadingProgress = 0.001 }; } } else { decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = thumb, ThumbW = thumbW, ThumbH = thumbH, FileName = new TLString(Path.GetFileName(p.FileName)), MimeType = mimeType, Size = new TLInt(p.Bytes.Length), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, UploadingProgress = 0.001 }; } return(decryptedMediaDocument); }
private void SendDocument(Photo p) { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var dcId = TLInt.Random(); var id = TLLong.Random(); var accessHash = TLLong.Random(); var fileLocation = new TLEncryptedFile { Id = id, AccessHash = accessHash, DCId = dcId, Size = new TLInt(p.Bytes.Length), KeyFingerprint = new TLInt(0), FileName = new TLString(Path.GetFileName(p.FileName)) }; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.Id, fileLocation.DCId, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.CreateFile(fileName)) { fileStream.Write(p.Bytes, 0, p.Bytes.Length); } } var keyIV = GenerateKeyIV(); int thumbHeight; int thumbWidth; var thumb = ImageUtils.CreateThumb(p.Bytes, Constants.DocumentPreviewMaxSize, Constants.DocumentPreviewQuality, out thumbHeight, out thumbWidth); var decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = TLString.FromBigEndianData(thumb), ThumbW = new TLInt(thumbWidth), ThumbH = new TLInt(thumbHeight), FileName = new TLString(Path.GetFileName(p.FileName)), MimeType = new TLString("image/jpeg"), Size = new TLInt(p.Bytes.Length), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, UploadingProgress = 0.001 }; var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty, decryptedMediaDocument, chat, true); Items.Insert(0, decryptedTuple.Item1); RaiseScrollToBottom(); NotifyOfPropertyChange(() => DescriptionVisibility); BeginOnThreadPool(() => CacheService.SyncDecryptedMessage(decryptedTuple.Item1, chat, cachedMessage => SendDocumentInternal(p.Bytes, decryptedTuple.Item2))); }
public async void SendDocument(StorageFile file) { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } if (file == null) { return; } var properties = await file.GetBasicPropertiesAsync(); var size = properties.Size; if (!DialogDetailsViewModel.CheckDocumentSize(size)) { MessageBox.Show(string.Format(AppResources.MaximumFileSizeExceeded, MediaSizeConverter.Convert((int)Telegram.Api.Constants.MaximumUploadedFileSize)), AppResources.Error, MessageBoxButton.OK); return; } DialogDetailsViewModel.AddFileToFutureAccessList(file); var thumb = await DialogDetailsViewModel.GetFileThumbAsync(file) as TLPhotoSize; var dcId = TLInt.Random(); var id = TLLong.Random(); var accessHash = TLLong.Random(); var fileLocation = new TLEncryptedFile { Id = id, AccessHash = accessHash, DCId = dcId, Size = new TLInt((int)size), KeyFingerprint = new TLInt(0), FileName = new TLString(Path.GetFileName(file.Name)) }; var keyIV = GenerateKeyIV(); var decryptedMediaDocument = new TLDecryptedMessageMediaDocument { Thumb = thumb != null? thumb.Bytes : TLString.Empty, ThumbW = thumb != null? thumb.W : new TLInt(0), ThumbH = thumb != null? thumb.H : new TLInt(0), FileName = new TLString(Path.GetFileName(file.Name)), MimeType = new TLString(file.ContentType), Size = new TLInt((int)size), Key = keyIV.Item1, IV = keyIV.Item2, File = fileLocation, StorageFile = file, UploadingProgress = 0.001 }; var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty, decryptedMediaDocument, chat, true); BeginOnUIThread(() => { Items.Insert(0, decryptedTuple.Item1); RaiseScrollToBottom(); NotifyOfPropertyChange(() => DescriptionVisibility); BeginOnThreadPool(() => CacheService.SyncDecryptedMessage(decryptedTuple.Item1, chat, cachedMessage => SendDocumentInternal(file, decryptedTuple.Item2))); }); }