UpdaterBehaviour now treats tracker data like media data, as discussed in slack

This commit is contained in:
2018-12-22 15:28:19 +01:00
parent 455822ad8f
commit 9b12bf239a
3 changed files with 64 additions and 34 deletions

View File

@@ -16,6 +16,8 @@ namespace RothenburgAR.Exhibition
{
if (!Directory.Exists(exhibitionDirectory))
return false;
if (!File.Exists(Path.Combine(exhibitionDirectory, "version.txt")))
return false;
if (!File.Exists(Path.Combine(exhibitionDirectory, "tracker.xml")))
return false;
if (!File.Exists(Path.Combine(exhibitionDirectory, "tracker.dat")))

View File

@@ -65,11 +65,13 @@ namespace RothenburgAR.Updater
public UnityWebRequest Request { get; set; }
public UnityWebRequestAsyncOperation Operation { get; set; }
private bool isDone = false;
public bool IsDone
{
get
{
return Operation.isDone && Request.isDone;
return Operation.isDone && Request.isDone && this.isDone;
}
}
@@ -79,6 +81,11 @@ namespace RothenburgAR.Updater
this.Download = download;
this.Request = request;
this.Operation = operation;
this.Operation.completed += (_) =>
{
this.isDone = true;
};
}
}

View File

@@ -241,18 +241,17 @@ namespace RothenburgAR.Updater
downloadingMedia.Add(mediaId);
var path = PathHelper.CombinePaths(PathHelper.MediaPath, mediaId);
var filepath = Path.Combine(path, mediaId + ".med");
var filepath = Path.Combine(path, mediaId + ".obj");
// create dir if nonexistent
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
//System.Security.Cryptography.SHA1CryptoServiceProvider
//System.Security.Cryptography.SHA256
var eTag = GenerateETag(filepath);
var url = ApiInfo.FileEndpoint.Replace("{id}", mediaId);
var http = new HttpRequest(url, HttpVerb.GET)
.WithHeader("If-None-Match", eTag)
.WithHeader("Accept-Encoding", "gzip,deflate")
.Send();
httpHandlers.Add(http);
@@ -277,7 +276,7 @@ namespace RothenburgAR.Updater
var subfiles = subfilesHeader.Split(separator, StringSplitOptions.RemoveEmptyEntries);
foreach (var subfile in subfiles)
{
UpdateSubfile(path, mediaId, subfile);
UpdateSubfile(path, url, subfile);
}
}
@@ -286,6 +285,55 @@ namespace RothenburgAR.Updater
}
}
private void UpdateTracker(ApiExhibitionVersion exhibition)
{
var path = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id);
var filepath = Path.Combine(path, "tracker.dat"); //TODO test if it's the xml instead
// create dir if nonexistent
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
var eTag = GenerateETag(filepath);
var url = exhibition.Tracker.UpdateUrl;
var http = new HttpRequest(url, HttpVerb.GET)
.WithHeader("If-None-Match", eTag)
.Send();
httpHandlers.Add(http);
http.Operation.completed += ar =>
{
if (CheckNetworkErrors(http))
{
return;
}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
// do nothing if unchanged
if (http.Request.responseCode == 304) return;
// gzipped files are un-gzipped automagically
File.WriteAllBytes(filepath, http.Download.data);
var subfilesHeader = http.Request.GetResponseHeader("subfiles");
if (subfilesHeader != null)
{
string[] separator = new string[1] { ";;" };
var subfiles = subfilesHeader.Split(separator, StringSplitOptions.RemoveEmptyEntries);
foreach (var subfile in subfiles)
{
UpdateSubfile(path, url, subfile);
}
}
Debug.Log(string.Format("{1}-DONE with {0}", url, Time.realtimeSinceStartup));
};
}
private string GenerateETag(string filepath)
{
string eTag = "";
@@ -303,12 +351,12 @@ namespace RothenburgAR.Updater
return eTag;
}
private void UpdateSubfile(string path, string mediaId, string subfile)
private void UpdateSubfile(string path, string parentUrl, string subfile)
{
var filepath = Path.Combine(path, subfile);
var eTag = GenerateETag(filepath);
var url = ApiInfo.FileEndpoint.Replace("{id}", mediaId) + "/" + subfile;
var url = parentUrl + "/" + subfile;
var http = new HttpRequest(url, HttpVerb.GET)
.WithHeader("If-None-Match", eTag)
.Send();
@@ -355,33 +403,6 @@ namespace RothenburgAR.Updater
return false;
}
private void UpdateTracker(ApiExhibitionVersion exhibition)
{
//TODO test UpdateTracker
var path = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id);
var url = exhibition.Tracker.UpdateUrl;
var http = new HttpRequest(url, HttpVerb.GET).Send();
httpHandlers.Add(http);
http.Operation.completed += ar =>
{
if (CheckNetworkErrors(http))
{
return;
}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//TODO unzip, should be tracker.xml and tracker.dat files
var type = http.Request.GetResponseHeader("Content-Type");
File.WriteAllBytes(Path.Combine(path, "tracker.zip"), http.Download.data);
Debug.Log(string.Format("{1}-DONE with {0}", url, Time.realtimeSinceStartup));
};
}
public void LoadMainScene()
{
Debug.Log("Loading mainScene");