//@TODO: Support some sort of transaction like API so we can reload all changed things in batch. unsafe void ReceiveAsset(MessageEventArgs args) { LiveLinkMsg.LogReceived($"AssetBundle: '{args.data.Length}' bytes"); fixed(byte *ptr = args.data) { var reader = new UnsafeAppendBuffer.Reader(ptr, args.data.Length); var asset = reader.ReadNext <ResolvedAssetID>(); var assetBundleCachePath = EntityScenesPaths.GetCachePath(asset.TargetHash); // Not printing error because this can happen when running the same player multiple times on the same machine if (File.Exists(assetBundleCachePath)) { LiveLinkMsg.LogInfo($"Received {asset.GUID} | {asset.TargetHash} but it already exists on disk"); } else { // cache: look up asset by target hash to see if the version we want is already on the target device //if we already have the asset bundle revision we want, then just put that in the resolver as the active revision of the asset // cache: if not in cache, write actual file to Application.persistentDatapath var tempCachePath = EntityScenesPaths.GetTempCachePath(); LiveLinkMsg.LogInfo($"ReceiveAssetBundle => {asset.GUID} | {asset.TargetHash}, '{tempCachePath}' => '{assetBundleCachePath}'"); using (var stream = File.OpenWrite(tempCachePath)) stream.Write(args.data, reader.Offset, args.data.Length - reader.Offset); try { File.Move(tempCachePath, assetBundleCachePath); } catch (Exception e) { File.Delete(tempCachePath); if (!File.Exists(assetBundleCachePath)) { Debug.LogError($"Failed to move temporary file. Source: {tempCachePath} | Destination: {assetBundleCachePath} - Exception: {e.Message}"); LiveLinkMsg.LogInfo($"Failed to move temporary file. Exception: {e.Message}"); } } } if (!m_WaitingForAssets.ContainsKey(asset.GUID)) { LiveLinkMsg.LogInfo($"Received {asset.GUID} | {asset.TargetHash} without requesting it"); } m_WaitingForAssets[asset.GUID] = asset.TargetHash; } }
static unsafe void ReceiveBuildArtifact(MessageEventArgs args) { fixed(byte *ptr = args.data) { LiveLinkMsg.LogInfo($"ReceiveBuildArtifact => Buffer Size: {args.data.Length}"); var reader = new UnsafeAppendBuffer.Reader(ptr, args.data.Length); reader.ReadNext(out string artifactFileName); string artifactPath = EntityScenesPaths.ComposeLiveLinkCachePath(artifactFileName); if (!File.Exists(artifactPath)) { LiveLinkMsg.LogInfo($"ReceiveBuildArtifact => {artifactPath}"); var tempCachePath = EntityScenesPaths.GetTempCachePath(); try { using (var stream = File.OpenWrite(tempCachePath)) { stream.Write(args.data, reader.Offset, args.data.Length - reader.Offset); } File.Move(tempCachePath, artifactPath); LiveLinkMsg.LogInfo($"ReceiveBuildArtifact => Successfully written to disc."); } catch (Exception e) { if (File.Exists(tempCachePath)) { File.Delete(tempCachePath); } if (!File.Exists(artifactPath)) { Debug.LogError($"Failed to move temporary file. Exception: {e.Message}"); } } } } }