/// <summary>
        /// Attempts to install the sample associated with the currently active Content Pack.
        /// </summary>
        static void ProcessSampleEvent()
        {
            var targetPack = s_CurrentEvent.targetPack;
            var samples    = Sample.FindByPackage(targetPack.PackageName, targetPack.Version);

            // We manually set the event null this time because we have no asynchronous request to process
            s_CurrentEvent = null;

            if (!samples.Any())
            {
                targetPack.InstallStatus &= ~InstallationStatus.Installing;
                OnInstallContent?.Invoke(false, $"Can't install content - no sample available.");
                OnContentChanged?.Invoke();
                return;
            }

            var targetSample = samples.First();

            if (!targetSample.Import())
            {
                targetPack.InstallStatus &= ~InstallationStatus.Installing;
                OnInstallContent?.Invoke(false, $"Failed to import associated content sample.");
                OnContentChanged?.Invoke();
                return;
            }

            FinishInstallation(targetPack);
        }
        static void FinishInstallation(ContentPack targetPack)
        {
            targetPack.InstallStatus = InstallationStatus.Installed;
            OnInstallContent?.Invoke(true, $"Successfully installed {targetPack.PackageName}");
            OnContentChanged?.Invoke();

            // We do an update here to ensure icon state is maintained - enough can change between dependencies and cross-references that just changing the target pack can be misleading
            if (QueuedEvents.Count == 0)
            {
                UpdateContentStatus();
            }
        }
        /// <summary>
        /// Called when Package Manager has completed the embed request.
        /// </summary>
        static void CompleteEmbedEvent()
        {
            var targetPack   = s_CurrentEvent.targetPack;
            var embedRequest = s_CurrentEvent.request as EmbedRequest;

            ConditionalLog($"Complete Embed Event {targetPack.DisplayName}");

            if (embedRequest == null)
            {
                return;
            }

            if (embedRequest.Status == StatusCode.Failure)
            {
                targetPack.InstallStatus &= ~InstallationStatus.Installing;
                OnInstallContent?.Invoke(false, $"Embed: {embedRequest.Error.message}");
                OnContentChanged?.Invoke();
                return;
            }

            FinishInstallation(targetPack);
        }
        /// <summary>
        /// Called when the Package Manager has completed the add request.
        /// Queues up additional actions if the content is set to be installed to the project folder.
        /// </summary>
        static void CompleteAddEvent()
        {
            var targetPack = s_CurrentEvent.targetPack;
            var addRequest = s_CurrentEvent.request as AddRequest;

            if (addRequest == null)
            {
                return;
            }

            if (addRequest.Status == StatusCode.Failure)
            {
                targetPack.InstallStatus &= ~InstallationStatus.Installing;
                OnInstallContent?.Invoke(false, addRequest.Error.message);
                OnContentChanged?.Invoke();
                return;
            }

            switch (targetPack.InstallType)
            {
            case InstallationType.Package:
                FinishInstallation(targetPack);
                break;

            case InstallationType.WriteablePackage:
                EmbedContent(targetPack);
                break;

            case InstallationType.UnityPackage:
                InstallContentSample(targetPack);

                // Update the status so the sample can be found
                UpdateContentStatus();
                break;
            }
        }
        /// <summary>
        /// Attempts to install a package specified within the currently active Content Pack.
        /// </summary>
        static void StartAddEvent()
        {
            // Is the package already installed? Do nothing
            // Otherwise, start an add action
            if (s_CurrentEvent.targetPack.InstallStatus.HasFlag(InstallationStatus.Installed) && !s_CurrentEvent.targetPack.InstallStatus.HasFlag(InstallationStatus.DifferentVersion))
            {
                OnInstallContent?.Invoke(true, $"{s_CurrentEvent.targetPack.PackageName} already installed");
                s_CurrentEvent = null;
                return;
            }

            s_CurrentEvent.targetPack.InstallStatus |= InstallationStatus.Locked;
            var currentUrl = s_CurrentEvent.targetPack.Url.ToLower();

            if (currentUrl.StartsWith(k_PackageReferenceKey))
            {
                // Local content packs can be in embedded packages, which is fine
                // Or they can be in the library folder, in which case we need to copy them to a temporary folder for installation
                currentUrl = Path.GetFullPath(currentUrl).ToLower();

                if (currentUrl.StartsWith(s_CachedPackagePath))
                {
                    try
                    {
                        // The content pack is located within the library folder - we must copy it to a temporary folder
                        var localPackageInfo = new DirectoryInfo(currentUrl);
                        if (localPackageInfo.Exists)
                        {
                            var localFolder = localPackageInfo.Name;
                            var targetPath  = $"{Path.GetDirectoryName(Application.dataPath)}{Path.DirectorySeparatorChar}{k_LocalPackagePath}{Path.DirectorySeparatorChar}{localFolder}";

                            Directory.CreateDirectory(targetPath);
                            FileUtil.ReplaceDirectory(currentUrl.Replace(Path.DirectorySeparatorChar, '/'), targetPath.Replace(Path.DirectorySeparatorChar, '/'));
                            currentUrl = $"file:{ToRelativeUnityPath(targetPath)}";
                        }
                        else
                        {
                            OnInstallContent?.Invoke(false, $"{s_CurrentEvent.targetPack.PackageName} cannot be found");
                            s_CurrentEvent = null;
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        OnInstallContent?.Invoke(false, $"Exception installing {s_CurrentEvent?.targetPack.PackageName}:{ex.Message}");
                        s_CurrentEvent = null;
                        return;
                    }
                }
                else
                {
                    // Convert the packages path to a relative path for version control niceness
                    currentUrl = $"file:{ToRelativeUnityPath(Path.GetFullPath(currentUrl))}";
                }
            }

            if (!string.IsNullOrEmpty(s_CurrentEvent.targetPack.AutoVersion))
            {
                currentUrl += $"@{s_CurrentEvent.targetPack.AutoVersion}";
            }

            s_CurrentEvent.request = Client.Add(currentUrl);
            OnContentChanged?.Invoke();
        }