internal static void AddOrUpdateResource(this IUsesCloudStorage storageUser, CompanionProject project,
                                                 string resourceFolder, string key, string name, ResourceType type, long fileSize, bool hasBundle,
                                                 Stack <RequestHandle> requests, Action <bool, ResourceList> callback = null)
        {
            var localResourceList = GetLocalResourceList(project, resourceFolder) ?? new ResourceList();
            var resource          = localResourceList.AddOrUpdateResource(key, name, type, fileSize, hasBundle);

            WriteLocalResourceList(project, resourceFolder, localResourceList);

            void LocalOnlyUpdate(bool success, ResourceList resourceList)
            {
                resourceList = ResourceList.MergeResourceLists(localResourceList, resourceList);
                ResourceListChanged?.Invoke(false, resourceList);
                callback?.Invoke(success, resourceList);
            }

            if (!project.linked)
            {
                LocalOnlyUpdate(true, new ResourceList());
                return;
            }

            // Get the latest list to make sure we don't lose scenes in case of stale data
            requests.Push(storageUser.GetCloudResourceList(project, resourceFolder, (getListSuccess, cloudResourceList) =>
            {
                if (getListSuccess)
                {
                    cloudResourceList.AddOrOverwriteExistingResource(resource);
                    requests.Push(storageUser.WriteCloudResourceList(project, resourceFolder, cloudResourceList, writeListSuccess =>
                    {
                        if (writeListSuccess)
                        {
#if UNITY_EDITOR
                            CloudResourceListChanged?.Invoke(cloudResourceList);
#endif

                            WriteFallbackCloudResourceList(project, resourceFolder, cloudResourceList);
                            cloudResourceList = ResourceList.MergeResourceLists(localResourceList, cloudResourceList);
                            ResourceListChanged?.Invoke(true, cloudResourceList);
                            callback?.Invoke(true, cloudResourceList);
                        }
                        else
                        {
                            LocalOnlyUpdate(false, cloudResourceList);
                        }
                    }));
                }
                else
                {
                    LocalOnlyUpdate(false, cloudResourceList);
                }
            }));
        }
 internal static void OnCloudResourceListChanged(ResourceList resourceList)
 {
     CloudResourceListChanged?.Invoke(resourceList);
 }