Introduced workarounds for errors in backend

This commit is contained in:
2018-12-24 14:49:42 +01:00
parent 9bf8505c77
commit bc4ceaef23
2 changed files with 30 additions and 11 deletions

View File

@@ -86,7 +86,11 @@ namespace RothenburgAR.Updater
this.Operation.completed += (_) => this.Operation.completed += (_) =>
{ {
this.isDone = true; 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);
}; };
} }
} }

View File

@@ -19,7 +19,7 @@ namespace RothenburgAR.Updater
public GameObject UpdateCompletedDialog; public GameObject UpdateCompletedDialog;
public GameObject UpdateFailedDialog; public GameObject UpdateFailedDialog;
private readonly float afterDownloadWaitTime = 10f; private float afterDownloadWaitTime = 10f;
private readonly int retriesUntilFailure = 3; private readonly int retriesUntilFailure = 3;
private readonly string trackerMainFile = "tracker.dat"; 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)) if (VersionAnswer.Data.TrueForAll(d => d.Meta.Status == VersionStatus.ok && d.Tracker.Status == VersionStatus.ok))
{ {
afterDownloadWaitTime = 0f;
StartCoroutine(CheckFiles()); StartCoroutine(CheckFiles());
return; return;
} }
@@ -277,8 +278,8 @@ namespace RothenburgAR.Updater
{ {
//+ create file list //+ create file list
//+ run updatemedia sequentially //+ run updatemedia sequentially
// write to cache until all subfiles are here, then to filesystem //+ write to cache until all subfiles are here, then to filesystem
// use progressbar //+ use progressbar
var usedFileList = new Dictionary<string, FileDownloadInfo>(); var usedFileList = new Dictionary<string, FileDownloadInfo>();
GenerateUsedFileList(usedFileList); GenerateUsedFileList(usedFileList);
@@ -306,7 +307,7 @@ namespace RothenburgAR.Updater
CleanupMediaFiles(); CleanupMediaFiles();
UpdateCompletedDialog.SetActive(true); UpdateCompletedDialog.SetActive(true);
StartCoroutine(LoadMainScene()); StartCoroutine(LoadMainSceneAfterTime());
} }
private void GenerateUsedFileList(Dictionary<string, FileDownloadInfo> downloadList) private void GenerateUsedFileList(Dictionary<string, FileDownloadInfo> downloadList)
@@ -410,10 +411,15 @@ namespace RothenburgAR.Updater
if (http.Request.responseCode != 304) if (http.Request.responseCode != 304)
{ {
// gzipped files are un-gzipped automagically // 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 subfilesHeader = http.Request.GetResponseHeader("subfiles");
var test = http.Request.GetResponseHeaders();
if (subfilesHeader != null) if (subfilesHeader != null)
{ {
string[] separator = new string[1] { ";;" }; string[] separator = new string[1] { ";;" };
@@ -426,7 +432,11 @@ namespace RothenburgAR.Updater
info.directory); info.directory);
var subfileETag = GenerateETag(info.filepath); 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) private void DeleteExhibition(ApiExhibitionVersion exhibition)
{ {
//TODO delete media as well if not used elsewhere?
var path = Path.Combine(PathHelper.ExhibitionPath, exhibition.Id); var path = Path.Combine(PathHelper.ExhibitionPath, exhibition.Id);
Directory.Delete(path, true); Directory.Delete(path, true);
} }
@@ -465,6 +474,7 @@ namespace RothenburgAR.Updater
var exhibitionDirs = rootDir.GetDirectories().ToList(); var exhibitionDirs = rootDir.GetDirectories().ToList();
foreach (var dir in exhibitionDirs) foreach (var dir in exhibitionDirs)
{ {
// HACK to preserve passion media files
if (!requiredMedia.Contains(dir.Name) && Regex.IsMatch(dir.Name, "/[0-9]/")) if (!requiredMedia.Contains(dir.Name) && Regex.IsMatch(dir.Name, "/[0-9]/"))
{ {
Directory.Delete(dir.FullName, true); Directory.Delete(dir.FullName, true);
@@ -484,10 +494,15 @@ namespace RothenburgAR.Updater
UpdateFailedDialog.SetActive(true); 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"); UnityEngine.SceneManagement.SceneManager.LoadScene("mainScene");
} }
} }