Exemplo n.º 1
0
        private async void PlayGif_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ProcessingGif = true;
            var metadata = await HttpClientFactory.AppApiService().GetUgoiraMetadata(Illust.Id);

            var ugoiraZip = metadata.UgoiraMetadataInfo.ZipUrls.Medium;
            var delay     = metadata.UgoiraMetadataInfo.Frames.Select(f => f.Delay / 10).ToArray();
            var streams   = InternalIO.ReadGifZipEntries(await PixivIO.GetBytes(ugoiraZip)).ToArray();

            ProcessingGif = false;
            PlayingGif    = true;

#pragma warning disable 4014
            Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    for (var i = 0; i < streams.Length && !cancellationToken.IsCancellationRequested; i++)
                    {
                        streams[i].Position = 0;
                        ImgSource           = InternalIO.CreateBitmapImageFromStream(streams[i]);
                        await Task.Delay((int)delay[i], cancellationToken.Token);
                    }
                }
            });
#pragma warning restore 4014
        }
Exemplo n.º 2
0
 public static async Task <BitmapImage> FromByteArray(byte[] bArr)
 {
     if (bArr == null || bArr.Length == 0)
     {
         return(null);
     }
     await using var memoryStream = new MemoryStream(bArr);
     return(InternalIO.CreateBitmapImageFromStream(memoryStream));
 }
Exemplo n.º 3
0
        private async void LoadOrigin()
        {
            LoadingOrigin = true;
            var progress = new Progress <double>(p => Dispatcher.Invoke(() => LoadingIndicator = p));

            await using var mem = await PixivIO.Download(Illust.GetDownloadUrl(), progress, cancellationTokenSource.Token);

            ImgSource     = InternalIO.CreateBitmapImageFromStream(mem);
            LoadingOrigin = false;
            ((BlurEffect)ContentImage.Effect).Radius = 0;
        }
Exemplo n.º 4
0
        private async void DownloadGif()
        {
            var downloadPath = GetPath();

            try
            {
                var metadata = await HttpClientFactory.AppApiService().GetUgoiraMetadata(DownloadContent.Id);

                var ugoiraUrl = metadata.UgoiraMetadataInfo.ZipUrls.Medium;
                ugoiraUrl = !ugoiraUrl.EndsWith("ugoira1920x1080.zip")
                    ? Regex.Replace(ugoiraUrl, "ugoira(\\d+)x(\\d+).zip", "ugoira1920x1080.zip")
                    : ugoiraUrl;
                var delay = metadata.UgoiraMetadataInfo.Frames.Select(f => f.Delay / 10).ToArray();
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var memory = await PixivIO.Download(ugoiraUrl, new Progress <double>(d => Progress = d),
                                                                cancellationTokenSource.Token);

                await using var gifStream =
                                (MemoryStream)InternalIO.MergeGifStream(InternalIO.ReadGifZipEntries(memory), delay);
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var fileStream = new FileStream(downloadPath, FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                                            FileShare.None);
                gifStream.WriteTo(fileStream);
                DownloadState.Value = DownloadStateEnum.Finished;
            }
            catch (TaskCanceledException)
            {
                if (downloadPath != null && File.Exists(downloadPath))
                {
                    File.Delete(downloadPath);
                }
            }
            catch (Exception e)
            {
                if (!retried)
                {
                    Restart();
                    retried = true;
                }
                else
                {
                    HandleError(e, downloadPath);
                }
            }
        }
Exemplo n.º 5
0
        public bool TryGetIOInternal(string ioName, bool lookUp, out IContainerIO container)
        {
            if (NameToIO.TryGetValue(ioName, out FIRIO innerIO))
            {
                container = innerIO;
                return(true);
            }

            if (InternalIO.TryGetValue(ioName, out FIRIO io))
            {
                container = io;
                return(true);
            }

            if (lookUp)
            {
                foreach (var condNode in Nodes.OfType <Conditional>())
                {
                    foreach (var condMod in condNode.CondMods)
                    {
                        if (condMod.Mod.TryGetIO(ioName, out container))
                        {
                            return(true);
                        }
                    }
                }
            }

            if (IsConditional && ResideIn.TryGetIOInternal(ioName, false, out container))
            {
                return(true);
            }

            container = null;
            return(false);
        }