public async Task Install(UnityInstaller.Queue queue, UnityInstaller.QueueItem item, CancellationToken cancellation = default) { if (item.package.name != PackageMetadata.EDITOR_PACKAGE_NAME && !installedEditor && upgradeOriginalPath == null) { throw new InvalidOperationException("Cannot install package without installing editor first."); } var extentsion = Path.GetExtension(item.filePath).ToLower(); if (extentsion == ".pkg") { await InstallPkg(item.filePath, cancellation); } else if (extentsion == ".dmg") { await InstallDmg(item.filePath, cancellation); } else if (extentsion == ".zip") { await InstallZip(item.filePath, item.package.destination, item.package.renameFrom, item.package.renameTo, cancellation); } else if (extentsion == ".po") { await InstallFile(item.filePath, item.package.destination, cancellation); } else { throw new Exception("Cannot install package of type: " + extentsion); } if (item.package.name == PackageMetadata.EDITOR_PACKAGE_NAME) { installedEditor = true; } }
public async Task PrepareInstall(UnityInstaller.Queue queue, string installationPaths, CancellationToken cancellation = default) { if (installing.version.IsValid) { throw new InvalidOperationException($"Already installing another version: {installing.version}"); } installing = queue.metadata; this.installationPaths = installationPaths; installedEditor = false; // Move existing installation out of the way movedExisting = false; if (Directory.Exists(INSTALL_PATH)) { if (Directory.Exists(INSTALL_PATH_TMP)) { throw new InvalidOperationException($"Fallback installation path '{INSTALL_PATH_TMP}' already exists."); } Logger.LogInformation("Temporarily moving existing installation at default install path: " + INSTALL_PATH); await Move(INSTALL_PATH, INSTALL_PATH_TMP, cancellation); movedExisting = true; } // Check for upgrading installation upgradeOriginalPath = null; if (!queue.items.Any(i => i.package.name == PackageMetadata.EDITOR_PACKAGE_NAME)) { var installs = await FindInstallations(cancellation); var existingInstall = installs.Where(i => i.version == queue.metadata.version).FirstOrDefault(); if (existingInstall == null) { throw new InvalidOperationException($"Not installing editor but version {queue.metadata.version} not already installed."); } upgradeOriginalPath = existingInstall.path; Logger.LogInformation($"Temporarily moving installation to upgrade from '{existingInstall}' to default install path"); await Move(existingInstall.path, INSTALL_PATH, cancellation); } }