Esempio n. 1
0
    public override void Initialize(DownloadState downloadState, ServerConfiguration serverConfiguration, DownloadPresenter downloadPresenter)
    {
        base.Initialize(downloadState, serverConfiguration, downloadPresenter);

        pathToSaveFiles = serverConfiguration.GetPathToSaveFiles();
        port            = int.Parse(serverConfiguration.FileDownloadServerPort);
        filesToDownload = downloadState.FilesToDownload;
        resourcePathForFilesToDownload = downloadState.ResourcePathForFilesToDownload ?? "";
        numberOfFilesToDownload        = filesToDownload.Count;
        downloadPresenter.SetFileList(filesToDownload);
        downloadCoroutine = downloadPresenter.StartCoroutine(DownloadFiles());
    }
Esempio n. 2
0
    public void Enter()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        serverConfiguration = ServerConfigurationModel.ActiveConfiguration;
        pathToSaveFiles     = serverConfiguration.GetPathToSaveFiles();
        Debug.Log($"Downloading files to {pathToSaveFiles}");
        port = int.Parse(serverConfiguration.FileDownloadServerPort);

        if (serverConfiguration.AllFilesDownloaded || (Application.isEditor && forceDownloadsInEditor == false))
        {
            StateManager.GoToState <GameState>();
        }
        else
        {
            downloadPresenter.gameObject.SetActive(true);
            //Get list of files to download from server
            var uri     = GetUri(serverConfiguration.FileDownloadServerUrl, port);
            var request = UnityWebRequest.Get(uri);
            request.SendWebRequest().completed += operation =>
            {
                if (request.isHttpError || request.isNetworkError)
                {
                    var error = $"Error while getting list of files from server: {request.error}";
                    Debug.LogError(error);
                    downloadPresenter.ShowError(error);
                    return;
                }

                downloadingFilesList = new List <string>(Regex
                                                         .Matches(request.downloadHandler.text, H_REF_PATTERN, RegexOptions.IgnoreCase).Cast <Match>()
                                                         .Select(match => match.Groups[1].Value)
                                                         .Where(text => text.Contains(".") &&
                                                                text.Contains(".exe") == false &&
                                                                text.Contains(".app") == false &&
                                                                text.Contains(".dll") == false &&
                                                                text.Contains(".pdb") == false &&
                                                                text.Contains("/") == false));
                numberOfFilesToDownload = downloadingFilesList.Count;
                downloadPresenter.SetFileList(downloadingFilesList);
                downloadCoroutine = downloadPresenter.StartCoroutine(DownloadFiles());
            };
        }
    }