simplified coroutine calls

This commit is contained in:
2018-11-24 16:18:38 +01:00
parent 24b998c20b
commit 93aef95cdb
2 changed files with 11 additions and 20 deletions

View File

@@ -54,7 +54,7 @@ namespace RothenburgAR.UI
if (!data.HasModelDescription) return;
this.currentPoiData = data;
StartCoroutine("SetModelCoroutine", data);
StartCoroutine(SetModelCoroutine(data));
}
public IEnumerator SetModelCoroutine(PoiData data)

View File

@@ -116,6 +116,7 @@ namespace RothenburgAR.Updater
};
result = result.Substring(0, result.Length - 1) + "}";
return "{}";
return result;
}
@@ -179,12 +180,7 @@ namespace RothenburgAR.Updater
private void UpdateMeta(ApiExhibitionVersion exhibition)
{
var versionData = new UpdateVersionFileCoroutineData
{
path = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id, "version.txt"),
httpHandlers = new List<HttpHandler>(),
version = exhibition.Meta.UpdateVersion.ToString()
};
var currentHandlers = new List<HttpHandler>();
foreach (var lang in VersionAnswer.Languages)
{
@@ -192,7 +188,7 @@ namespace RothenburgAR.Updater
var url = exhibition.Meta.UpdateUrl.Replace("{lang}", lang);
var http = new HttpRequest(url, HttpVerb.GET).Send();
httpHandlers.Add(http);
versionData.httpHandlers.Add(http);
currentHandlers.Add(http);
http.Operation.completed += ar =>
{
@@ -217,23 +213,18 @@ namespace RothenburgAR.Updater
};
}
StartCoroutine("UpdateVersionFileCoroutine", versionData);
var versionPath = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id, "version.txt");
var version = exhibition.Meta.UpdateVersion.ToString();
StartCoroutine(UpdateVersionFileCoroutine(currentHandlers, versionPath, version));
}
private IEnumerator UpdateVersionFileCoroutine(UpdateVersionFileCoroutineData versionData)
private IEnumerator UpdateVersionFileCoroutine(List<HttpHandler> currentHandlers, string versionPath, string version)
{
// updates version file only if all sub files were downloaded successfully
yield return new WaitUntil(() => versionData.httpHandlers.All(h => h.IsDone));
if (versionData.httpHandlers.Any(http => http.Request.isNetworkError || http.Request.isHttpError)) yield break;
yield return new WaitUntil(() => httpHandlers.All(h => h.IsDone));
if (httpHandlers.Any(http => http.Request.isNetworkError || http.Request.isHttpError)) yield break;
File.WriteAllText(versionData.path, versionData.version);
}
private class UpdateVersionFileCoroutineData
{
public List<HttpHandler> httpHandlers;
public string path;
public string version;
File.WriteAllText(versionPath, version);
}
private void UpdateMedia(ApiExhibit exhibit)