|
|
@@ -26,6 +26,40 @@ namespace HotPatch
|
|
|
{
|
|
|
public const string ManifestFileName = "manifest.json";
|
|
|
|
|
|
+ public static async UniTask<HotPatchLocalResources> LoadBundledAsync(Uri bundledManifestUri,
|
|
|
+ string cacheDirectory, string assemblyName, string platform, Action<HotPatchProgress> progress, CancellationToken ct, string sceneName = null)
|
|
|
+ {
|
|
|
+ progress?.Invoke(new HotPatchProgress("Checking version", 0));
|
|
|
+ var json = await ReadTextAsync(bundledManifestUri, ct);
|
|
|
+ var manifest = Parse(json);
|
|
|
+ ValidateBundledManifest(manifest, assemblyName, platform, sceneName);
|
|
|
+ var root = Path.Combine(cacheDirectory, "LocalTest", HotPatchHash.Of(Encoding.UTF8.GetBytes(json)));
|
|
|
+ var resources = new[] { manifest.aotBundle }.Concat(manifest.resources).ToArray();
|
|
|
+ HotPatchLog.Info("local_test_cache path=" + root + " version=" + manifest.version);
|
|
|
+ for (int i = 0; i < resources.Length; i++)
|
|
|
+ {
|
|
|
+ ct.ThrowIfCancellationRequested();
|
|
|
+ var resource = resources[i];
|
|
|
+ var destination = Path.Combine(root, resource.RelativePath);
|
|
|
+ if (!IsVerified(destination, resource))
|
|
|
+ await DownloadFileAsync(new Uri(bundledManifestUri, resource.RelativePath), destination, resource,
|
|
|
+ bytes => progress?.Invoke(new HotPatchProgress("Checking version", .8f * (i + (float)bytes / resource.size) / resources.Length)), ct);
|
|
|
+ }
|
|
|
+ ct.ThrowIfCancellationRequested();
|
|
|
+ SaveManifest(Path.Combine(root, ManifestFileName), manifest);
|
|
|
+ HotPatchLog.Info("local_test_ready version=" + manifest.version + " remote_requests=0");
|
|
|
+ progress?.Invoke(new HotPatchProgress("Loading resources", .8f));
|
|
|
+ return new HotPatchLocalResources(root, manifest, manifest);
|
|
|
+ }
|
|
|
+
|
|
|
+ static void ValidateBundledManifest(HotPatchManifest manifest, string assemblyName, string platform, string sceneName)
|
|
|
+ {
|
|
|
+ manifest.Validate(assemblyName, platform, sceneName);
|
|
|
+ if (manifest.aotBundle == null || manifest.aotMetadata == null ||
|
|
|
+ !manifest.aotMetadata.Select(r => r.name).OrderBy(n => n).SequenceEqual(HotPatchBundleLoader.AotAssemblyNames.OrderBy(n => n)))
|
|
|
+ throw new InvalidDataException("Original resources must include an AOT bundle and verification records for all four AOT DLLs.");
|
|
|
+ }
|
|
|
+
|
|
|
public static async UniTask<HotPatchLocalResources> SynchronizeAsync(Uri bundledManifestUri, Uri remoteManifestUri,
|
|
|
string cacheDirectory, string assemblyName, string platform, Action<HotPatchProgress> progress, CancellationToken ct, string sceneName = null)
|
|
|
{
|
|
|
@@ -35,10 +69,7 @@ namespace HotPatch
|
|
|
progress?.Invoke(new HotPatchProgress("Checking version", 0));
|
|
|
var original = Parse(await ReadTextAsync(bundledManifestUri, ct));
|
|
|
HotPatchLog.Info($"bundled_manifest platform={original.platform} build={original.playerBuildId} version={original.version}");
|
|
|
- original.Validate(assemblyName, platform, sceneName);
|
|
|
- if (original.aotBundle == null || original.aotMetadata == null ||
|
|
|
- !original.aotMetadata.Select(r => r.name).OrderBy(n => n).SequenceEqual(HotPatchBundleLoader.AotAssemblyNames.OrderBy(n => n)))
|
|
|
- throw new InvalidDataException("Original resources must include an AOT bundle and verification records for all four AOT DLLs.");
|
|
|
+ ValidateBundledManifest(original, assemblyName, platform, sceneName);
|
|
|
var root = Path.Combine(cacheDirectory, HotPatchHash.Of(Encoding.UTF8.GetBytes(original.playerBuildId)));
|
|
|
Directory.CreateDirectory(root);
|
|
|
HotPatchLog.Info("cache_path path=" + root);
|