CreateLoader() static private method

static private CreateLoader ( string uri ) : ILoader
uri string
return ILoader
Beispiel #1
0
        public override async Task <bool> PrepareAsync(WebClient client, CancellationToken cancellation)
        {
            var downloadPage = await client.DownloadStringTaskAsync(Url);

            if (cancellation.IsCancellationRequested)
            {
                return(false);
            }

            var match = Regex.Match(downloadPage, @"<p class=""download""><a href=""([^""]+)");

            if (!match.Success)
            {
                NonfatalError.Notify(ToolsStrings.Common_CannotDownloadFile, ToolsStrings.DirectLoader_AcClubChanged);
                return(false);
            }

            Url = HttpUtility.HtmlDecode(match.Groups[1].Value);
            Logging.Write("AssettoCorsa.club download link: " + Url);

            _innerLoader = FlexibleLoader.CreateLoader(Url);
            if (_innerLoader is AcClubLoader)
            {
                throw new Exception(ToolsStrings.DirectLoader_RecursionDetected);
            }
            return(await _innerLoader.PrepareAsync(client, cancellation));
        }
        public async Task <bool> PrepareAsync(CookieAwareWebClient client, CancellationToken cancellation)
        {
            var url = await GetRedirect(_url, client, cancellation);

            if (url == null || cancellation.IsCancellationRequested)
            {
                return(false);
            }

            _url = url;
            Logging.Write($"{GetType().Name} download link: {_url}");

            _innerLoader = FlexibleLoader.CreateLoader(_url);
            if (_innerLoader.GetType() == GetType())
            {
                throw new Exception(ToolsStrings.DirectLoader_RecursionDetected);
            }
            return(await _innerLoader.PrepareAsync(client, cancellation));
        }