public void Enter() { serverConfiguration = ServerConfigurationModel.ActiveConfiguration; if (serverConfiguration.AllFilesDownloaded || Application.isEditor) { StateManager.GoToState <GameState>(); } else { downloadPresenter.gameObject.SetActive(true); //Get list of files to download from server var uriBuilder = new UriBuilder("http", serverConfiguration.FileDownloadServerUrl, 8080); var request = UnityWebRequest.Get(uriBuilder.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; } string hRefPattern = @"href\s*=\s*(?:[""'](?<1>[^""']*)[""']|(?<1>\S+))"; var filesList = new List <string>(Regex.Matches(request.downloadHandler.text, hRefPattern, RegexOptions.IgnoreCase). Cast <Match>().Select(match => match.Groups[1].Value) .Where(text => text.Contains(".")) .Where(text => text.Contains(".exe") == false)); numberOfFilesToDownload = filesList.Count; downloadCoroutine = downloadPresenter.StartCoroutine(DownloadFiles(filesList)); }; } }
public void StopAndShowError(string error) { Debug.LogError(error); //Stop downloads downloadPresenter.ShowError(error); downloadPresenter.ClearFileList(); inGameDebugConsoleCanvas.enabled = true; }
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()); }; } }