public static async Task <bool> Download(string url, string fileName, CancellationToken cancellationToken)
        {
            if (!Directory.Exists(DatabasePath))
            {
                Logger.Info($"Creating database directory \"{DatabasePath}\"");
                Directory.CreateDirectory(DatabasePath);
            }

            var encoding = new UTF8Encoding(false);
            var http     = await HTTP.Request(url, cancellationToken).ConfigureAwait(false);

            if (http.IsOK)
            {
                Logger.Info($"Database file \"{fileName}\" downloaded successfully");
                File.WriteAllText(Path.Combine(DatabasePath, fileName), http.Content, encoding);

                return(true);
            }

            return(false);
        }
예제 #2
0
        private static async Task <RemoteImageInfo> GetImageSizeAndValidate(RemoteImageInfo item, CancellationToken cancellationToken)
        {
            if (Plugin.Instance.Configuration.DisableImageValidation)
            {
                return(item);
            }

            var http = await HTTP.Request(item.Url, HttpMethod.Head, cancellationToken).ConfigureAwait(false);

            if (http.IsOK)
            {
                if (Plugin.Instance.Configuration.DisableImageSize)
                {
                    return(item);
                }

                http = await HTTP.Request(item.Url, cancellationToken).ConfigureAwait(false);

                if (http.IsOK)
                {
                    using (var img = SKBitmap.Decode(http.ContentStream))
                    {
                        if (img != null && img.Width > 100)
                        {
                            return(new RemoteImageInfo
                            {
                                ProviderName = item.ProviderName,
                                Url = item.Url,
                                Type = item.Type,
                                Height = img.Height,
                                Width = img.Width,
                            });
                        }
                    }
                }
            }

            return(null);
        }