コード例 #1
0
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document) || TLMessage.IsMusic(document))
                {
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
コード例 #2
0
        private bool TrySetWebPSource(TLDocument document, int phase)
        {
            if (phase >= Phase && document != null)
            {
                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    Phase = phase;

                    //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                    var decoded = WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName)));
                    if (decoded != null)
                    {
                        _bitmapImage.SetSource(decoded);
                    }
                    else
                    {
                        _bitmapImage.UriSource = FileUtils.GetTempFileUri(fileName);
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        private void SetWebPSource(ITLTransferable transferable, TLDocument document, int fileSize, int phase)
        {
            if (phase >= Phase && document != null)
            {
                Phase = phase;

                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                    Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadFileManager.DownloadFileAsync(fileName, document.DCId, document.ToInputFileLocation(), fileSize).AsTask(transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            Execute.BeginOnUIThread(() =>
                            {
                                if (transferable != null)
                                {
                                    transferable.IsTransferring = false;
                                }

                                //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                                Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))));
                            });
                        }
                    });
                }
            }
        }
コード例 #4
0
        private bool TrySetAnimatedSource(TLDocument document, int phase)
        {
            if (phase >= Phase && document != null)
            {
                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    Phase = phase;

                    //Image.UriSource = FileUtils.GetTempFileUri(fileName);
                    _renderer.SetSource(FileUtils.GetTempFileUri(fileName));
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                var message = DataContext as TLMessage;
                if (message != null && message.Media is TLMessageMediaDocument documentMedia && documentMedia.HasTTLSeconds)
                {
                    return("\uE60D");
                }

                if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsMusic(document))
                {
                    return("\uE102");
                }
                else if (TLMessage.IsGif(document))
                {
                    Visibility = Visibility.Collapsed;
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
コード例 #6
0
ファイル: TLBitmapSource.cs プロジェクト: nazzi88ua/Unigram
        private void SetDownloadSource(ITLTransferable transferable, TLDocument document, int fileSize, int phase)
        {
            if (phase >= Phase && document != null)
            {
                //Phase = phase;

                var fileName = document.GetFileName();
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadFileManager.DownloadFileAsync(fileName, document.DCId, document.ToInputFileLocation(), fileSize, transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            //Phase = phase;
                        }
                    });
                }
            }
        }
コード例 #7
0
 public override Uri GetVideoSource()
 {
     return(FileUtils.GetTempFileUri(_document.GetFileName()));
 }
コード例 #8
0
        public static async Task SaveDocumentAsync(TLDocument document, int date, bool downloads)
        {
            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                var extension  = document.GetFileExtension();
                var resultName = "document_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + extension;

                var fileNameAttribute = document.Attributes.OfType <TLDocumentAttributeFilename>().FirstOrDefault();
                if (fileNameAttribute != null)
                {
                    resultName = fileNameAttribute.FileName;
                }

                if (downloads)
                {
                    var folder = await GetDownloadsAsync();

                    if (folder == null)
                    {
                        return;
                    }

                    StorageFile file;
                    if (StorageApplicationPermissions.FutureAccessList.ContainsItem(fileName))
                    {
                        file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(fileName);
                    }
                    else
                    {
                        file = await folder.CreateFileAsync(resultName, CreationCollisionOption.GenerateUniqueName);

                        StorageApplicationPermissions.FutureAccessList.AddOrReplace(fileName, file);

                        var result = await FileUtils.GetTempFileAsync(fileName);

                        await result.CopyAndReplaceAsync(file);
                    }

                    if (UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse)
                    {
                        var options = new FolderLauncherOptions();
                        options.ItemsToSelect.Add(file);

                        await Launcher.LaunchFolderAsync(folder, options);
                    }
                }
                else
                {
                    var picker = new FileSavePicker();

                    if (!string.IsNullOrEmpty(extension))
                    {
                        picker.FileTypeChoices.Add($"{extension.TrimStart('.').ToUpper()} File", new[] { extension });
                    }
                    else
                    {
                        picker.FileTypeChoices.Add("Unknown", new[] { ".dat" });
                    }

                    picker.SuggestedStartLocation = PickerLocationId.Downloads;
                    picker.SuggestedFileName      = resultName;

                    var file = await picker.PickSaveFileAsync();

                    if (file != null)
                    {
                        var result = await FileUtils.GetTempFileAsync(fileName);

                        await result.CopyAndReplaceAsync(file);
                    }
                }
            }
        }