first commit to make Updates a background task for normal app launch

This commit is contained in:
2018-12-28 17:17:07 +01:00
parent 7f521b6b94
commit d71221883c
7 changed files with 3176 additions and 53 deletions

View File

@@ -913,8 +913,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 114224566756848850} m_TargetGraphic: {fileID: 114224566756848850}
m_HandleRect: {fileID: 224135889778237342} m_HandleRect: {fileID: 224135889778237342}
m_Direction: 2 m_Direction: 2
m_Value: 0.9999998 m_Value: 0.50000024
m_Size: 0.5452254 m_Size: 0.5452256
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:
@@ -1343,7 +1343,7 @@ MonoBehaviour:
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 2100000, guid: 184173fb9a2399341882a894edcac032, type: 2} m_Material: {fileID: 2100000, guid: a5b7496cf6d1ca34bab1a076f7b545e0, type: 2}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0 m_RaycastTarget: 0
m_OnCullStateChanged: m_OnCullStateChanged:
@@ -1579,7 +1579,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -195.90994} m_AnchoredPosition: {x: 0, y: -0.000076293945}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224254431283456606 --- !u!224 &224254431283456606

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ab149fbc9d7dc3d40ac85af2e411788a
timeCreated: 1546010792
licenseType: Free
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,6 +2,7 @@
using RothenburgAR.Exhibition; using RothenburgAR.Exhibition;
using RothenburgAR.PointOfInterest; using RothenburgAR.PointOfInterest;
using RothenburgAR.UI; using RothenburgAR.UI;
using RothenburgAR.Updater;
using UnityEngine; using UnityEngine;
using Vuforia; using Vuforia;
@@ -15,6 +16,15 @@ namespace RothenburgAR
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
#if !UNITY_EDITOR
logFileHandler = new LogFileHandler();
#else
Debug.Log("Found Unity Editor; Disabled logging into file.");
#endif
//OBJLoader.defaultShader = Shader.Find("Standard (Specular setup)")
OBJLoader.defaultShader = Shader.Find("Standard");
OBJLoader.defaultMaterial = new Material(OBJLoader.defaultShader);
LanguageManager.Instance.LoadLanguagesFromXml(); LanguageManager.Instance.LoadLanguagesFromXml();
UIColorSchemeManager.Instance.Initialize(); UIColorSchemeManager.Instance.Initialize();
@@ -26,11 +36,8 @@ namespace RothenburgAR
UIManager.Instance.InitStartView(); UIManager.Instance.InitStartView();
InputManager.Instance.Initialize(); InputManager.Instance.Initialize();
var init = DisplayManager.Instance; var initDisplayManagerSingleton = DisplayManager.Instance;
var initUpdaterSingleton = UpdaterBehaviour.Instance;
//OBJLoader.defaultShader = Shader.Find("Standard (Specular setup)")
OBJLoader.defaultShader = Shader.Find("Standard");
OBJLoader.defaultMaterial = new Material(OBJLoader.defaultShader);
} }
void InitializeData() void InitializeData()

View File

@@ -0,0 +1,69 @@
using RothenburgAR.Updater;
using UnityEngine;
namespace RothenburgAR.UI
{
public class UpdaterViewBehaviour : MonoBehaviour
{
public UnityEngine.UI.Slider ProgressBar;
public GameObject UpdateDialog;
public GameObject UpdateConfirmationDialog;
public GameObject UpdateCompletedDialog;
public GameObject UpdateFailedDialog;
private void Start()
{
UpdateDialog.SetActive(false);
UpdateConfirmationDialog.SetActive(false);
UpdateCompletedDialog.SetActive(false);
UpdateFailedDialog.SetActive(false);
ProgressBar.value = 0;
ProgressBar.maxValue = 1;
}
private void Update()
{
var state = UpdaterBehaviour.Instance.UpdateState;
UpdateDialog.SetActive(false);
UpdateConfirmationDialog.SetActive(false);
UpdateCompletedDialog.SetActive(false);
UpdateFailedDialog.SetActive(false);
switch (state)
{
case UpdateState.ConfirmationPending:
UpdateConfirmationDialog.SetActive(true);
break;
case UpdateState.UpdatesFound:
case UpdateState.Downloading:
UpdateDialog.SetActive(true);
ProgressBar.value = UpdaterBehaviour.Instance.CurrentProgress;
ProgressBar.maxValue = UpdaterBehaviour.Instance.MaxProgress;
break;
case UpdateState.Completed:
UpdateCompletedDialog.SetActive(true);
//TODO add "apply upgrades" button or sth that Destroys all DontDestroyOnLoads and reloads the scene, use AppInitializerBehaviour for that
break;
case UpdateState.Failed:
UpdateFailedDialog.SetActive(true);
break;
}
}
public void TriggerUpdate()
{
UpdaterBehaviour.Instance.TriggerUpdate();
}
public void ExitView()
{
UIManager.Instance.SwitchToView(ViewName.ARView);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 49d9434809cb84c44ae021b275939980
timeCreated: 1546011854
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -11,51 +11,43 @@ using System.Text.RegularExpressions;
namespace RothenburgAR.Updater namespace RothenburgAR.Updater
{ {
public class UpdaterBehaviour : MonoBehaviour public enum UpdateState
{ {
public UnityEngine.UI.Slider ProgressBar; UpdatesFound,
public GameObject UpdateDialog; ConfirmationPending,
public GameObject UpdateConfirmationDialog; Downloading,
public GameObject UpdateCompletedDialog; Completed,
public GameObject UpdateFailedDialog; Failed
}
public class UpdaterBehaviour : Singleton<UpdaterBehaviour>
{
public UpdateState UpdateState { get; private set; }
public int CurrentProgress { get; private set; }
public int MaxProgress { get; private set; }
private float afterDownloadWaitTime = 10f; private float afterDownloadWaitTime = 10f;
private readonly int retriesUntilFailure = 4; private readonly int retriesUntilFailure = 4;
private readonly string trackerMainFile = "tracker.dat"; private readonly string trackerMainFile = "tracker.dat";
public ApiVersioncheckAnswer VersionAnswer { get; set; } public ApiVersioncheckAnswer VersionAnswer { get; set; }
Dictionary<string, List<ApiExhibit>> ExhibitMetas = new Dictionary<string, List<ApiExhibit>>(); Dictionary<string, List<ApiExhibit>> ExhibitMetas = new Dictionary<string, List<ApiExhibit>>();
private LogFileHandler logFileHandler; private LogFileHandler logFileHandler;
void Start() void Start()
{ {
#if !UNITY_EDITOR
logFileHandler = new LogFileHandler();
#else
Debug.Log("Found Unity Editor; Disabled logging into file.");
#endif
InitUI();
if (Application.internetReachability == NetworkReachability.NotReachable) if (Application.internetReachability == NetworkReachability.NotReachable)
{ {
// just continue to app // just continue to app
LoadMainScene(); UpdatesCompleted();
return; return;
} }
CheckForUpdates(); CheckForUpdates();
} }
private void InitUI()
{
FindObjectsOfType<Camera>().First().enabled = true;
UpdateDialog.SetActive(false);
UpdateConfirmationDialog.SetActive(false);
UpdateCompletedDialog.SetActive(false);
UpdateFailedDialog.SetActive(false);
ProgressBar.value = 0;
}
private void CheckForUpdates() private void CheckForUpdates()
{ {
// check for updates and ask for permission to download if there are any // check for updates and ask for permission to download if there are any
@@ -94,7 +86,7 @@ namespace RothenburgAR.Updater
return; return;
} }
UpdateDialog.SetActive(true); UpdateState = UpdateState.UpdatesFound;
if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{ {
@@ -102,7 +94,7 @@ namespace RothenburgAR.Updater
} }
else else
{ {
UpdateConfirmationDialog.SetActive(true); UpdateState = UpdateState.ConfirmationPending;
} }
}; };
} }
@@ -174,8 +166,7 @@ namespace RothenburgAR.Updater
- progressbar vllt ersetzen durch durchlaufdingens? - progressbar vllt ersetzen durch durchlaufdingens?
*/ */
UpdateConfirmationDialog.SetActive(false); UpdateState = UpdateState.Downloading;
UpdateFailedDialog.SetActive(false);
if (VersionAnswer == null) if (VersionAnswer == null)
{ {
@@ -279,7 +270,7 @@ namespace RothenburgAR.Updater
var usedFileList = new Dictionary<string, FileDownloadInfo>(); var usedFileList = new Dictionary<string, FileDownloadInfo>();
GenerateUsedFileList(usedFileList); GenerateUsedFileList(usedFileList);
ProgressBar.maxValue = usedFileList.Count; MaxProgress = usedFileList.Count;
foreach (var file in usedFileList) foreach (var file in usedFileList)
{ {
var fileInfo = file.Value; var fileInfo = file.Value;
@@ -299,8 +290,7 @@ namespace RothenburgAR.Updater
deletedData.ForEach(d => DeleteExhibition(d)); deletedData.ForEach(d => DeleteExhibition(d));
CleanupMediaFiles(); CleanupMediaFiles();
UpdateCompletedDialog.SetActive(true); UpdatesCompleted();
StartCoroutine(LoadMainSceneAfterTime());
} }
private void GenerateUsedFileList(Dictionary<string, FileDownloadInfo> downloadList) private void GenerateUsedFileList(Dictionary<string, FileDownloadInfo> downloadList)
@@ -404,7 +394,7 @@ namespace RothenburgAR.Updater
{ {
var subfiles = subfilesHeader.Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries).ToList(); var subfiles = subfilesHeader.Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries).ToList();
ProgressBar.maxValue += subfiles.Count(subfileName => !data.Keys.Contains(Path.Combine(info.directory, subfileName))); MaxProgress += subfiles.Count(subfileName => !data.Keys.Contains(Path.Combine(info.directory, subfileName)));
foreach (var subfileName in subfiles) foreach (var subfileName in subfiles)
{ {
@@ -423,7 +413,7 @@ namespace RothenburgAR.Updater
} }
Debug.Log(string.Format("{1}-DONE with {0}", url, Time.realtimeSinceStartup)); Debug.Log(string.Format("{1}-DONE with {0}", url, Time.realtimeSinceStartup));
ProgressBar.value += 1; CurrentProgress += 1;
} }
private string GenerateETag(string filepath) private string GenerateETag(string filepath)
@@ -473,20 +463,13 @@ namespace RothenburgAR.Updater
http.Request.isHttpError, http.Request.isHttpError,
http.Request.responseCode)); http.Request.responseCode));
UpdateDialog.SetActive(true); UpdateState = UpdateState.Failed;
UpdateFailedDialog.SetActive(true);
} }
public IEnumerator LoadMainSceneAfterTime() public void UpdatesCompleted()
{ {
Debug.Log("Loading mainScene in " + afterDownloadWaitTime + "s"); //TODO force switch to UpdaterView when update needs to be applied
yield return new WaitForSecondsRealtime(afterDownloadWaitTime); UpdateState = UpdateState.Completed;
LoadMainScene();
}
public void LoadMainScene()
{
UnityEngine.SceneManagement.SceneManager.LoadScene("mainScene");
} }
} }
} }