From bc4ceaef23905d8367b4ef31686a75a48a5bdeba Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 24 Dec 2018 14:49:42 +0100 Subject: [PATCH] Introduced workarounds for errors in backend --- .../Scripts/Updater/HttpHandler.cs | 6 +++- .../Scripts/Updater/UpdaterBehaviour.cs | 35 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs b/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs index b27b857..6d5a38f 100644 --- a/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs +++ b/Assets/RothenburgAR/Scripts/Updater/HttpHandler.cs @@ -86,7 +86,11 @@ namespace RothenburgAR.Updater this.Operation.completed += (_) => { this.isDone = true; - this.IsError = request.isNetworkError || request.isHttpError || download.data.Length == 0; + this.IsError = + request.isNetworkError + || request.isHttpError + // Error when answer is empty except when it's a 300 error code + || (!(request.responseCode >= 300 && request.responseCode < 400) && download.data.Length == 0); }; } } diff --git a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs index 06ee324..192831d 100644 --- a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs @@ -19,7 +19,7 @@ namespace RothenburgAR.Updater public GameObject UpdateCompletedDialog; public GameObject UpdateFailedDialog; - private readonly float afterDownloadWaitTime = 10f; + private float afterDownloadWaitTime = 10f; private readonly int retriesUntilFailure = 3; private readonly string trackerMainFile = "tracker.dat"; @@ -89,6 +89,7 @@ namespace RothenburgAR.Updater if (VersionAnswer.Data.TrueForAll(d => d.Meta.Status == VersionStatus.ok && d.Tracker.Status == VersionStatus.ok)) { + afterDownloadWaitTime = 0f; StartCoroutine(CheckFiles()); return; } @@ -277,8 +278,8 @@ namespace RothenburgAR.Updater { //+ create file list //+ run updatemedia sequentially - // write to cache until all subfiles are here, then to filesystem - // use progressbar + //+ write to cache until all subfiles are here, then to filesystem + //+ use progressbar var usedFileList = new Dictionary(); GenerateUsedFileList(usedFileList); @@ -306,7 +307,7 @@ namespace RothenburgAR.Updater CleanupMediaFiles(); UpdateCompletedDialog.SetActive(true); - StartCoroutine(LoadMainScene()); + StartCoroutine(LoadMainSceneAfterTime()); } private void GenerateUsedFileList(Dictionary downloadList) @@ -410,10 +411,15 @@ namespace RothenburgAR.Updater if (http.Request.responseCode != 304) { // gzipped files are un-gzipped automagically - data.Add(info.filepath, http.Download.data); + + if (!data.ContainsKey(info.filepath)) + { + data.Add(info.filepath, http.Download.data); + } } var subfilesHeader = http.Request.GetResponseHeader("subfiles"); + var test = http.Request.GetResponseHeaders(); if (subfilesHeader != null) { string[] separator = new string[1] { ";;" }; @@ -426,7 +432,11 @@ namespace RothenburgAR.Updater info.directory); var subfileETag = GenerateETag(info.filepath); - yield return UpdateFile(subfileInfo, subfileETag, data); + // HACK to kill errorneous recursive file definition on server + if (!data.ContainsKey(subfileInfo.filepath) && subfileName != "brick.png") + { + yield return UpdateFile(subfileInfo, subfileETag, data); + } } } @@ -452,7 +462,6 @@ namespace RothenburgAR.Updater private void DeleteExhibition(ApiExhibitionVersion exhibition) { - //TODO delete media as well if not used elsewhere? var path = Path.Combine(PathHelper.ExhibitionPath, exhibition.Id); Directory.Delete(path, true); } @@ -465,6 +474,7 @@ namespace RothenburgAR.Updater var exhibitionDirs = rootDir.GetDirectories().ToList(); foreach (var dir in exhibitionDirs) { + // HACK to preserve passion media files if (!requiredMedia.Contains(dir.Name) && Regex.IsMatch(dir.Name, "/[0-9]/")) { Directory.Delete(dir.FullName, true); @@ -484,10 +494,15 @@ namespace RothenburgAR.Updater UpdateFailedDialog.SetActive(true); } - public IEnumerator LoadMainScene() + public IEnumerator LoadMainSceneAfterTime() + { + Debug.Log("Loading mainScene in " + afterDownloadWaitTime + "s"); + yield return new WaitForSecondsRealtime(afterDownloadWaitTime); + LoadMainScene(); + } + + public void LoadMainScene() { - yield return new WaitForSecondsRealtime(10f); - Debug.Log("Loading mainScene"); UnityEngine.SceneManagement.SceneManager.LoadScene("mainScene"); } }