diff --git a/Assets/Resources/OVRBuildConfig.asset b/Assets/Resources/OVRBuildConfig.asset index f2d36f8..cf5cd6c 100644 --- a/Assets/Resources/OVRBuildConfig.asset +++ b/Assets/Resources/OVRBuildConfig.asset @@ -12,6 +12,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 20553fac56ec59645857c0732b787431, type: 3} m_Name: OVRBuildConfig m_EditorClassIdentifier: - androidSDKPath: C:\Users\tvero\AppData\Local\Android\Sdk + androidSDKPath: gradlePath: jdkPath: diff --git a/Assets/Scripts/AssetsDownloader.cs b/Assets/Scripts/AssetsDownloader.cs index 6572135..8ca6adb 100644 --- a/Assets/Scripts/AssetsDownloader.cs +++ b/Assets/Scripts/AssetsDownloader.cs @@ -25,6 +25,9 @@ namespace QuestAppLauncher // Manifest file to track what we've downloaded const string DownloadManifestFile = "download_manifest.json"; + // Temporary filename for download + const string TempDownloadFileExtention = ".tmp_download"; + // GitHub API url const string GithubApiUrl = @"http://api.github.com/repos/"; @@ -179,7 +182,9 @@ namespace QuestAppLauncher { // Get asset info from repos var assetsInfo = new Dictionary(StringComparer.OrdinalIgnoreCase); - var reposLoaded = new HashSet(); + + // Get the set of repo URIs (removing any duplicates) + var configRepos = new HashSet(); foreach (var item in config.downloadRepos) { if (null == item.type || !string.Equals(item.type, Config.DownloadRepo_Type_GitHub, StringComparison.OrdinalIgnoreCase)) @@ -188,11 +193,17 @@ namespace QuestAppLauncher continue; } + configRepos.Add(item.repoUri); + } + + var reposLoaded = new HashSet(); + foreach (var repoUri in configRepos) + { // Get assets from the GitHub repo - var repoLoaded = await GetAssetsInfoFromGithubRepoAsync(item.repoUri, assetsInfo, downloadProgress); + var repoLoaded = await GetAssetsInfoFromGithubRepoAsync(repoUri, assetsInfo, downloadProgress); if (repoLoaded) { - reposLoaded.Add(item.repoUri); + reposLoaded.Add(repoUri); } } @@ -368,6 +379,7 @@ namespace QuestAppLauncher IDownloadProgress downloadProgress) { var filePath = Path.Combine(GetOrCreateDownloadPath(), name); + var tempFilePath = filePath + TempDownloadFileExtention; Debug.LogFormat("Downloading asset {0} from {1}", filePath, assetInfo.Url); try @@ -380,7 +392,7 @@ namespace QuestAppLauncher { downloadProgress.OnDownloadStart(name); } - var downloadHandler = new DownloadHandlerFileWithProgress(filePath, downloadProgress.OnDownloadProgress); + var downloadHandler = new DownloadHandlerFileWithProgress(tempFilePath, downloadProgress.OnDownloadProgress); downloadHandler.removeFileOnAbort = true; req.downloadHandler = downloadHandler; await req.SendWebRequest(); @@ -394,9 +406,24 @@ namespace QuestAppLauncher downloadProgress.OnError(string.Format("Error updating: {0} ({1})", req.error, assetInfo.Url)); } + + if (File.Exists(tempFilePath)) + { + File.Delete(tempFilePath); + } + return false; } + // Rename temp file to desination file to ensure that we are not downloading + // an error body message into the destination file. + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + File.Move(tempFilePath, filePath); + if (null != downloadProgress) { downloadProgress.OnDownloadFinish(); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 4597467..08298cb 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -67,10 +67,18 @@ namespace QuestAppLauncher public bool autoUpdate = false; // Github download repos - public List downloadRepos = new List() + public List downloadRepos = new List(); + + public Config(bool initDefaults = false) { - new DownloadRepo { repoUri = DownloadRepo_Default, type = DownloadRepo_Type_GitHub } - }; + if (initDefaults) + { + // We must initialize any default collection values here. Otherwise, if we initialize them inline, + // we'll keep adding duplicate values whenever we persist via JSON.NET (since it invokes the default contructor as part + // of deserialization, which again adds the default value). + this.downloadRepos.Add(new DownloadRepo { repoUri = DownloadRepo_Default, type = DownloadRepo_Type_GitHub }); + } + } } /// @@ -109,7 +117,7 @@ namespace QuestAppLauncher } // Return default config - return new Config(); + return new Config(true); } ///