public async Task Symbols_ValidationVerifyMissingAssemblyIndexCausesFailure(string isSymbolsString) { var isSymbols = bool.Parse(isSymbolsString); using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var service = new Symbols(context); // Add packages await AddPackageAsync(isSymbols, testContext, service); // Corrupt feed var path = SymbolsIndexUtility.GetAssemblyToPackageIndexPath("a.dll", "A7F83EF08000"); var assemblyPackageIndex = new AssetIndexFile(testContext.SleetContext, path, new PackageIdentity("a", NuGetVersion.Parse("1.0.0"))); var exists = await assemblyPackageIndex.File.Exists(context.Log, context.Token); exists.Should().BeTrue(); assemblyPackageIndex.File.Delete(context.Log, context.Token); // Validate var messages = await service.ValidateAsync(); var hasErrors = messages.Any(e => e.Level == LogLevel.Error); hasErrors.Should().BeTrue(); } }
public async Task AssetIndexFile_RemoveAllAssets() { using (var testContext = new SleetTestContext()) { var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var file = new AssetIndexFile(testContext.SleetContext, "test.json", identity); var asset = new AssetIndexEntry(new Uri("http://tempuri.org/a.json"), new Uri("http://tempuri.org/b.json")); var symAsset = new AssetIndexEntry(new Uri("http://tempuri.org/x.json"), new Uri("http://tempuri.org/y.json")); await file.AddAssetsAsync(new[] { asset }); await file.AddSymbolsAssetsAsync(new[] { symAsset }); await file.RemoveAssetsAsync(new[] { asset, symAsset }); await file.RemoveSymbolsAssetsAsync(new[] { asset, symAsset }); var assets = await file.GetAssetsAsync(); var symbolsAssets = await file.GetSymbolsAssetsAsync(); assets.Should().BeEmpty(); symbolsAssets.Should().BeEmpty(); await testContext.SleetContext.Source.Commit(testContext.SleetContext.Log, testContext.SleetContext.Token); var path = Path.Combine(testContext.Target, "test.json"); File.Exists(path).Should().BeFalse(); } }
public async Task AssetIndexFile_AddAssets() { using (var testContext = new SleetTestContext()) { var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var file = new AssetIndexFile(testContext.SleetContext, "test.json", identity); await file.AddAssetsAsync(new[] { new AssetIndexEntry(new Uri("http://tempuri.org/a.json"), new Uri("http://tempuri.org/b.json")) }); await file.AddSymbolsAssetsAsync(new[] { new AssetIndexEntry(new Uri("http://tempuri.org/x.json"), new Uri("http://tempuri.org/y.json")) }); var assets = await file.GetAssetsAsync(); var symbolsAssets = await file.GetSymbolsAssetsAsync(); assets.Count.Should().Be(1); symbolsAssets.Count.Should().Be(1); assets.Single().PackageIndex.Should().Be(new Uri("http://tempuri.org/b.json")); assets.Single().Asset.Should().Be(new Uri("http://tempuri.org/a.json")); symbolsAssets.Single().PackageIndex.Should().Be(new Uri("http://tempuri.org/y.json")); symbolsAssets.Single().Asset.Should().Be(new Uri("http://tempuri.org/x.json")); } }
// 开始更新 private void StartHotUpdate() { // 初始化数据 _updateSetting = null; _updateConfig = null; _latest = null; _latestVersion = null; _updateList = null; _updateSize = 0; _downloadedSize = 0; _downloader = null; _updateStatus = STATUS_WORK; StartCoroutine(HotUpdate()); }
// 5.比较文件数据生成下载列表 private bool CheckDiff() { // Debug.Log("Updater.CheckDiff"); AssetIndexFile oldAssets = AssetIndexData.Instance().GetIndex(); // 本地比服务器版本还新, 跳过更新步骤 if (oldAssets.GetVersion() > _latest.GetVersion()) { return(true); } // 检查是否大版本更新 if (!VersionHelper.IsCompatible(oldAssets.GetVersion(), _latest.GetVersion())) { return(false); } // 文件比较 var allAssets = _latest.FetchAll(); _updateList = new List <AssetInfo>(allAssets.Count); _updateSize = 0; foreach (AssetInfo asset in allAssets) { if (asset == null) { continue; } FileInfo fi = new FileInfo(asset.GetWritePath()); // 检查是否匹配 AssetInfo old = oldAssets.GetAssetInfo(asset.hash); if (old == null || old.IsDiff(asset) || old.IsDiff(fi)) { _updateList.Add(asset); _updateSize += asset.size; } } return(true); }
// 4.下载最新的文件索引 private IEnumerator DownloadLatestIndex() { if (GameConfig.PLATFORM == null) { yield break; } byte[] bytes = null; string url = _updateSetting.resUrl + _latestVersion + '-' + GameConfig.PLATFORM + "/media/file.list?spm=" + GetRandomValue(); // Debug.Log("Updater.DownloadLatestIndex " + url); for (int i = 0; i < DOWNLOAD_RETRY_TIMES; i++) { WWW downloader = new WWW(url); yield return(downloader); // 下载成功 if (downloader.error == null) { bytes = downloader.bytes; break; } yield return(new WaitForSeconds(DOWNLOAD_RETRY_DELAY)); } if (bytes == null) { yield break; } try { _latest = new AssetIndexFile(); _latest.Load(new MemoryStream(bytes), AssetInfo.STORAGE_PERSISTEN); } catch (Exception) { _latest = null; } }
public async Task AssetIndexFile_EmptyFile() { using (var testContext = new SleetTestContext()) { var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var file = new AssetIndexFile(testContext.SleetContext, "test.json", identity); await file.InitAsync(); await testContext.SleetContext.Source.Commit(testContext.SleetContext.Log, testContext.SleetContext.Token); var path = Path.Combine(testContext.Target, "test.json"); File.Exists(path).Should().BeTrue(); var assets = await file.GetAssetsAsync(); var symbolsAssets = await file.GetSymbolsAssetsAsync(); assets.Should().BeEmpty(); symbolsAssets.Should().BeEmpty(); file.Package.Should().Be(identity); } }
// 6.下载所有更新文件 private IEnumerator DownloadAssets() { // Debug.Log("Updater.DownloadAssets " + _updateList.Count); Directory.CreateDirectory(GameConfig.PERSISTENT_PATH + "media"); AssetIndexFile oldAssets = AssetIndexData.Instance().GetIndex(); int accumSize = 0; _downloadedSize = 0; UpdateProgress(); string rootUrl = _updateSetting.resUrl + _latestVersion + '-' + GameConfig.PLATFORM + '/'; foreach (var asset in _updateList) { byte[] bytes = null; _currentAssetSize = asset.size; _currentAssetDownloaded = 0; string url = rootUrl + asset.GetFilename() + "?spm=" + GetRandomValue(); for (int i = 0; i < DOWNLOAD_RETRY_TIMES; i++) { WWW downloader = new WWW(url); _downloader = downloader; yield return(downloader); // 下载成功 if (downloader.error == null) { bytes = downloader.bytes; break; } yield return(new WaitForSeconds(DOWNLOAD_RETRY_DELAY)); } if (bytes == null || bytes.Length != asset.size) { if (bytes == null) { Debug.LogWarning("Updater.DownloadAssets failed " + url); } else { Debug.LogWarning("Updater.DownloadAssets invalid size of " + url); } // 下载更新包失败,弹出重试窗口 _confirmDownload = false; ShowNoticeDialog(GetText(MESSAGE_NETWORK_ERROR), BUTTON_RETRY, OnRetryCallback); yield break; } // 写入文件 File.WriteAllBytes(asset.GetWritePath(), bytes); _currentAssetSize = 0; _currentAssetDownloaded = 0; _downloader = null; _downloadedSize += asset.size; accumSize += asset.size; UpdateProgress(); // 替换索引 oldAssets.AddAssetInfo(asset); // 凑齐若干字节后写入索引文件 if (accumSize >= DOWNLOAD_ACCUM_WRITE_INDEX) { accumSize = 0; AssetIndexData.Instance().Save(); } } oldAssets.SetVersion(_latest.GetVersion()); AssetIndexData.Instance().Save(); GameConfig.VERSION = AssetIndexData.Instance().GetVersionString(); SetProgressInfo(1, GetText(MESSAGE_COMPLETE), false); _updateStatus = STATUS_COMPLETE; NotifyUpdateEnd(); }