Skip to content

Commit

Permalink
Implemented support for selecting multiple packages for installation (#…
Browse files Browse the repository at this point in the history
…611)

* Implemented support for selecting multiple packages for installation

* Fixed install selection with already installed packages and added Select all from clipboard button

* Fixed UnityPreImportedLibraryResolver fake in Cli version
  • Loading branch information
igor84 authored Jan 10, 2024
1 parent 17c6330 commit 7388d28
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 43 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Click the **Install** to install the package version specified in the dropdown l
Note: If the package is already installed, the currently installed version will be displayed in the upper right corner instead.
If the **Install** button is disabled, it means the package is already imported by Unity.

You can also select multiple packages for installation and install them all at once.

In addition to manual selection you can also copy a list of packageIds that you need to install, separated by new line or comma, and simply click the "Select all from clipboard" button at the top right to add them all to the selection.
Note that if the package is already installed or available in Unity it will not show up in the selected list.

The **Installed** tabs shows the packages already installed in the current Unity project.

<img alt="Installed Packages Tap" src="docs/screenshots/installed.png" height="500px" />
Expand Down
Binary file modified docs/screenshots/online.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#nullable enable

using NugetForUnity.Models;

namespace NugetForUnity
{
/// <summary>
Expand All @@ -12,10 +10,10 @@ internal static class UnityPreImportedLibraryResolver
/// <summary>
/// Check if a package is already imported in the Unity project e.g. is a part of Unity.
/// </summary>
/// <param name="package">The package of witch the identifier is checked.</param>
/// <param name="packageId">The package of witch the identifier is checked.</param>
/// <param name="log">Whether to log a message with the result of the check.</param>
/// <returns>If it is included in Unity.</returns>
public static bool IsAlreadyImportedInEngine(INugetPackageIdentifier package, bool log = true)
public static bool IsAlreadyImportedInEngine(string packageId, bool log = true)
{
// the CLI is running outside of Unity so we can't easily detect what libraries are imported by the Unity Engine.
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
{
"name": "NuGetForUnity.Editor.Tests",
"rootNamespace": "NugetForUnity.Tests",
"references": [
"NuGetForUnity",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
"NuGetForUnity"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}
18 changes: 17 additions & 1 deletion src/NuGetForUnity/Editor/InstalledPackagesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ internal static bool RemoveUnnecessaryPackages()
/// <returns>True if the given package is installed. False if it is not.</returns>
internal static bool IsInstalled([NotNull] INugetPackageIdentifier package, bool checkIsAlreadyImportedInEngine)
{
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package))
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id))
{
return true;
}
Expand All @@ -318,6 +318,22 @@ internal static bool IsInstalled([NotNull] INugetPackageIdentifier package, bool
return isInstalled;
}

/// <summary>
/// Checks if any version of the given package Id is installed.
/// </summary>
/// <param name="packageId">The package to check if is installed.</param>
/// <param name="checkIsAlreadyImportedInEngine">Determine if it should check if the package is already imported by unity itself.</param>
/// <returns>True if the given package is installed. False if it is not.</returns>
internal static bool IsInstalled([NotNull] string packageId, bool checkIsAlreadyImportedInEngine)
{
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(packageId))
{
return true;
}

return InstalledPackagesDictionary.ContainsKey(packageId);
}

/// <summary>
/// Gets a list of all root packages that are installed in the project.
/// Root packages are packages that are not depended on by any other package.
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetForUnity/Editor/NugetPackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class NugetPackageInstaller
/// <returns>True if the package was installed successfully, otherwise false.</returns>
public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package, bool refreshAssets = true, bool isSlimRestoreInstall = false)
{
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
{
NugetLogger.LogVerbose("Package {0} is already imported in engine, skipping install.", package);
return true;
Expand All @@ -54,7 +54,7 @@ public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package,
/// <returns>True if the package was installed successfully, otherwise false.</returns>
private static bool Install([NotNull] INugetPackage package, bool refreshAssets, bool isSlimRestoreInstall)
{
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
{
NugetLogger.LogVerbose("Package {0} is already imported in engine, skipping install.", package);
return true;
Expand Down
12 changes: 10 additions & 2 deletions src/NuGetForUnity/Editor/NugetPackageUninstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
{
// Checking for pre-imported packages also ensures that the pre-imported package list is up-to-date before we uninstall packages.
// Without this the pre-imported package list can contain the package as we delete the .dll before we call 'AssetDatabase.Refresh()'.
if (UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
if (UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
{
Debug.LogWarning($"Uninstalling {package} makes no sense because it is a package that is 'pre-imported' by Unity.");
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
}

/// <summary>
/// Uninstalls all of the currently installed packages.
/// Uninstalls all given installed packages.
/// </summary>
/// <param name="packagesToUninstall">The list of packages to uninstall.</param>
public static void UninstallAll([NotNull] [ItemNotNull] List<INugetPackage> packagesToUninstall)
Expand All @@ -87,5 +87,13 @@ public static void UninstallAll([NotNull] [ItemNotNull] List<INugetPackage> pack

AssetDatabase.Refresh();
}

/// <summary>
/// Uninstalls all of the currently installed packages.
/// </summary>
public static void UninstallAll()
{
UninstallAll(InstalledPackagesManager.InstalledPackages.ToList());
}
}
}
Loading

0 comments on commit 7388d28

Please sign in to comment.