Пример #1
0
        public static Chapter testChapter(string url, DownloaderBase _base)
        {
            Chapter c = new Chapter {
                chapterLink = new Uri(url)
            };
            HtmlDocument docu = new HtmlDocument();
            WebClient    wc   = new WebClient();

            c.text = _base.GetText(c, docu, wc);
            return(c);
        }
Пример #2
0
        public void MainTask(int taskId)
        {
            DownloaderBase downloader = DownloaderFactory.Create(this.Type);

            while (true)
            {
                TaskInfo taskInfo = this.TaskQueue.Take();
                Diagnostics.WriteDebugTrace($"TaskId={taskId}. Get task from queue. Url={taskInfo.Url}", Diagnostics.DebugLevel.Debug);
                this.DownloaderDict.AddOrUpdate(taskId, downloader, (k, v) => downloader);
                downloader.Download(taskInfo);
            }
        }
Пример #3
0
        public bool ParseBookFromWeb(string url)
        {
            statusUpdate(ti, $"{metaData?.name} Creating Novel Object");
            DownloaderBase dbase = null;

            switch (site)
            {
            case Site.AsianHobbyist:
                dbase = new AsianHobbyist(url, ti, statusUpdate);
                break;

            case Site.wuxiaWorldA:
                dbase = new dWuxiaWorld(url, ti, statusUpdate);
                break;

            case Site.wuxiaWorldB:
                dbase = new cWuxiaWorld(url, ti, statusUpdate);
                break;

            case Site.ScribbleHub:
                dbase = new cScribbleHub(url, ti, statusUpdate);
                break;

            case Site.NovelFull:
                dbase = new cNovelFull(url, ti, statusUpdate);
                break;

            case Site.NovelHall:
                dbase = new NovelHall(url, ti, statusUpdate);
                break;

            case Site.Error:
                ADLUpdates.CallUpdate("Error: This site doesn't seem to be supported.");
                return(false);

            default:
                ADLUpdates.CallUpdate("Unknown error");
                return(false);
            }
            statusUpdate(ti, $"{metaData?.name} Getting MetaData");
            metaData = dbase.GetMetaData();
            statusUpdate(ti, $"{metaData?.name} Getting Chapter links");
            chapters     = dbase.GetChapterLinks();
            fileLocation = $"{chapterDir}/{metaData.name}";
            ADLUpdates.CallUpdate($"Downloading Chapters for {metaData.name}");
            return(true);
        }
Пример #4
0
 public Chapter(DownloaderBase _base = null)
 {
     parent = _base;
 }
Пример #5
0
    public void Enter()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        serverConfiguration = ServerConfigurationModel.ActiveConfiguration;
        Debug.Log($"Downloading files to {serverConfiguration.GetPathToSaveFiles()}");
        var port = int.Parse(serverConfiguration.FileDownloadServerPort);

        if (serverConfiguration.AllFilesDownloaded || Application.isEditor && string.IsNullOrEmpty(serverConfiguration.ClientPathForUnityEditor) == false)
        {
            StateManager.GoToState <GameState>();
        }
        else
        {
            downloadPresenter.gameObject.SetActive(true);

            //Figure out what kind of downloader we should use
            if (serverConfiguration.FileDownloadServerUrl.ToLowerInvariant().Contains("uooutlands.com"))
            {
                downloader = new OutlandsDownloader();
                downloader.Initialize(this, serverConfiguration, downloadPresenter);
            }
            else if (serverConfiguration.FileDownloadServerUrl.ToLowerInvariant().Contains("uorenaissance.com"))
            {
                downloader = new RenaissanceDownloader();
                downloader.Initialize(this, serverConfiguration, downloadPresenter);
            }
            else
            {
                //Get list of files to download from server
                var uri     = GetUri(serverConfiguration.FileDownloadServerUrl, port);
                var request = UnityWebRequest.Get(uri);
                //This request should not take more than 5 seconds, the amount of data being received is very small
                request.timeout = 5;
                request.SendWebRequest().completed += operation =>
                {
                    if (request.isHttpError || request.isNetworkError)
                    {
                        var error = $"Error while making initial request to server: {request.error}";
                        StopAndShowError(error);
                        return;
                    }

                    var headers = request.GetResponseHeaders();

                    if (headers.TryGetValue("Content-Type", out var contentType))
                    {
                        if (contentType.Contains("application/json"))
                        {
                            //Parse json response to get list of files
                            Debug.Log($"Json response: {request.downloadHandler.text}");
                            FilesToDownload = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(request.downloadHandler.text);
                        }
                        else if (contentType.Contains("text/html"))
                        {
                            FilesToDownload = new List <string>(Regex
                                                                .Matches(request.downloadHandler.text, H_REF_PATTERN, RegexOptions.IgnoreCase)
                                                                .Cast <Match>()
                                                                .Select(match => match.Groups[1].Value));
                        }
                    }

                    if (FilesToDownload != null)
                    {
                        FilesToDownload.RemoveAll(file => NeededUoFileExtensions.Any(file.Contains) == false);
                        SetFileListAndDownload(FilesToDownload);
                    }
                    else
                    {
                        StopAndShowError("Could not determine file list to download");
                    }
                };
            }
        }
    }
Пример #6
0
 private void StartDirectoryDownloader()
 {
     downloader = new DirectoryDownloader();
     downloader.Initialize(this, serverConfiguration, downloadPresenter);
 }