From 284e64e75f368b9a8d2932c4049c4ca1e69b0415 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 27 Dec 2018 18:03:26 +0100 Subject: [PATCH] progressbar now also shows subfile download progress tested dropped http connections tested retriesUntilFailure feature replaced workarounds for backend errors with sanity checks --- .../Scripts/Updater/UpdaterBehaviour.cs | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs index 192831d..a7ef4c1 100644 --- a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs @@ -20,7 +20,7 @@ namespace RothenburgAR.Updater public GameObject UpdateFailedDialog; private float afterDownloadWaitTime = 10f; - private readonly int retriesUntilFailure = 3; + private readonly int retriesUntilFailure = 4; private readonly string trackerMainFile = "tracker.dat"; public ApiVersioncheckAnswer VersionAnswer { get; set; } @@ -72,7 +72,7 @@ namespace RothenburgAR.Updater var answer = JsonConvert.DeserializeObject(http.Download.text); if (http.IsError) { - if (retries <= retriesUntilFailure) + if (retries < retriesUntilFailure) { CheckForUpdates(versionMap, retries + 1); return; @@ -248,7 +248,7 @@ namespace RothenburgAR.Updater { if (http.IsError) { - if (retries <= retriesUntilFailure) + if (retries < retriesUntilFailure) { exhibitionDownloads.Remove(http); UpdateMetaFile(exhibition, path, lang, exhibitionDownloads, retries + 1); @@ -284,20 +284,17 @@ namespace RothenburgAR.Updater var usedFileList = new Dictionary(); GenerateUsedFileList(usedFileList); - int progress = 0; + ProgressBar.maxValue = usedFileList.Count; foreach (var file in usedFileList) { + var fileInfo = file.Value; Dictionary data = new Dictionary(); - yield return UpdateFile(file.Value, data); + yield return DownloadFile(fileInfo, data); foreach (var item in data) { File.WriteAllBytes(item.Key, item.Value); } - - float downloadProgress = progress / usedFileList.Count; - ProgressBar.value = ProgressBar.value < downloadProgress ? downloadProgress : ProgressBar.value; - progress++; } var deletedData = VersionAnswer.Data.Where(d => @@ -376,16 +373,16 @@ namespace RothenburgAR.Updater } } - private IEnumerator UpdateFile(FileDownloadInfo info, Dictionary data) + private IEnumerator DownloadFile(FileDownloadInfo info, Dictionary data) { // create dir if nonexistent if (!Directory.Exists(info.directory)) Directory.CreateDirectory(info.directory); var eTag = GenerateETag(info.filepath); - yield return UpdateFile(info, eTag, data); + yield return DownloadFile(info, eTag, data); } - private IEnumerator UpdateFile(FileDownloadInfo info, string eTag, Dictionary data, int retries = 0) + private IEnumerator DownloadFile(FileDownloadInfo info, string eTag, Dictionary data, int retries = 0) { var url = info.url; var http = new HttpRequest(url, HttpVerb.GET) @@ -397,9 +394,9 @@ namespace RothenburgAR.Updater if (http.IsError) { - if (retries <= retriesUntilFailure) + if (retries < retriesUntilFailure) { - yield return UpdateFile(info, eTag, data, retries + 1); + yield return DownloadFile(info, eTag, data, retries + 1); } else { @@ -410,10 +407,9 @@ namespace RothenburgAR.Updater if (http.Request.responseCode != 304) { - // gzipped files are un-gzipped automagically - if (!data.ContainsKey(info.filepath)) { + // gzipped files are un-gzipped automagically data.Add(info.filepath, http.Download.data); } } @@ -422,8 +418,11 @@ namespace RothenburgAR.Updater var test = http.Request.GetResponseHeaders(); if (subfilesHeader != null) { - string[] separator = new string[1] { ";;" }; - var subfiles = subfilesHeader.Split(separator, StringSplitOptions.RemoveEmptyEntries); + var subfiles = subfilesHeader.Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries); + + //TODO: will add already downloaded files to maxValue, fix by filtering? + ProgressBar.maxValue += subfiles.Length; + foreach (var subfileName in subfiles) { var subfileInfo = new FileDownloadInfo( @@ -432,15 +431,15 @@ namespace RothenburgAR.Updater info.directory); var subfileETag = GenerateETag(info.filepath); - // HACK to kill errorneous recursive file definition on server - if (!data.ContainsKey(subfileInfo.filepath) && subfileName != "brick.png") + if (!data.ContainsKey(subfileInfo.filepath)) { - yield return UpdateFile(subfileInfo, subfileETag, data); + yield return DownloadFile(subfileInfo, subfileETag, data); } } } Debug.Log(string.Format("{1}-DONE with {0}", url, Time.realtimeSinceStartup)); + ProgressBar.value += 1; } private string GenerateETag(string filepath)