progressbar now also shows subfile download progress

tested dropped http connections
tested retriesUntilFailure feature
replaced workarounds for backend errors with sanity checks
This commit is contained in:
2018-12-27 18:03:26 +01:00
parent bc4ceaef23
commit 284e64e75f

View File

@@ -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<ApiVersioncheckAnswer>(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<string, FileDownloadInfo>();
GenerateUsedFileList(usedFileList);
int progress = 0;
ProgressBar.maxValue = usedFileList.Count;
foreach (var file in usedFileList)
{
var fileInfo = file.Value;
Dictionary<string, byte[]> data = new Dictionary<string, byte[]>();
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<string, byte[]> data)
private IEnumerator DownloadFile(FileDownloadInfo info, Dictionary<string, byte[]> 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<string, byte[]> data, int retries = 0)
private IEnumerator DownloadFile(FileDownloadInfo info, string eTag, Dictionary<string, byte[]> 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)