Skip to content

Commit 7388d28

Browse files
authored
Implemented support for selecting multiple packages for installation (GlitchEnzo#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
1 parent 17c6330 commit 7388d28

File tree

9 files changed

+227
-43
lines changed

9 files changed

+227
-43
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Click the **Install** to install the package version specified in the dropdown l
8787
Note: If the package is already installed, the currently installed version will be displayed in the upper right corner instead.
8888
If the **Install** button is disabled, it means the package is already imported by Unity.
8989

90+
You can also select multiple packages for installation and install them all at once.
91+
92+
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.
93+
Note that if the package is already installed or available in Unity it will not show up in the selected list.
94+
9095
The **Installed** tabs shows the packages already installed in the current Unity project.
9196

9297
<img alt="Installed Packages Tap" src="docs/screenshots/installed.png" height="500px" />

docs/screenshots/online.png

7.73 KB
Loading

src/NuGetForUnity.Cli/Fakes/UnityPreImportedLibraryResolver.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#nullable enable
22

3-
using NugetForUnity.Models;
4-
53
namespace NugetForUnity
64
{
75
/// <summary>
@@ -12,10 +10,10 @@ internal static class UnityPreImportedLibraryResolver
1210
/// <summary>
1311
/// Check if a package is already imported in the Unity project e.g. is a part of Unity.
1412
/// </summary>
15-
/// <param name="package">The package of witch the identifier is checked.</param>
13+
/// <param name="packageId">The package of witch the identifier is checked.</param>
1614
/// <param name="log">Whether to log a message with the result of the check.</param>
1715
/// <returns>If it is included in Unity.</returns>
18-
public static bool IsAlreadyImportedInEngine(INugetPackageIdentifier package, bool log = true)
16+
public static bool IsAlreadyImportedInEngine(string packageId, bool log = true)
1917
{
2018
// the CLI is running outside of Unity so we can't easily detect what libraries are imported by the Unity Engine.
2119
return false;
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
{
22
"name": "NuGetForUnity.Editor.Tests",
3-
"rootNamespace": "NugetForUnity.Tests",
43
"references": [
5-
"NuGetForUnity",
6-
"UnityEngine.TestRunner",
7-
"UnityEditor.TestRunner"
4+
"NuGetForUnity"
5+
],
6+
"optionalUnityReferences": [
7+
"TestAssemblies"
88
],
99
"includePlatforms": [
1010
"Editor"
1111
],
1212
"excludePlatforms": [],
1313
"allowUnsafeCode": false,
1414
"overrideReferences": false,
15-
"precompiledReferences": [
16-
"nunit.framework.dll"
17-
],
18-
"autoReferenced": false,
19-
"defineConstraints": [
20-
"UNITY_INCLUDE_TESTS"
21-
],
22-
"versionDefines": [],
23-
"noEngineReferences": false
15+
"precompiledReferences": [],
16+
"autoReferenced": true,
17+
"defineConstraints": []
2418
}

src/NuGetForUnity/Editor/InstalledPackagesManager.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ internal static bool RemoveUnnecessaryPackages()
304304
/// <returns>True if the given package is installed. False if it is not.</returns>
305305
internal static bool IsInstalled([NotNull] INugetPackageIdentifier package, bool checkIsAlreadyImportedInEngine)
306306
{
307-
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package))
307+
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id))
308308
{
309309
return true;
310310
}
@@ -318,6 +318,22 @@ internal static bool IsInstalled([NotNull] INugetPackageIdentifier package, bool
318318
return isInstalled;
319319
}
320320

321+
/// <summary>
322+
/// Checks if any version of the given package Id is installed.
323+
/// </summary>
324+
/// <param name="packageId">The package to check if is installed.</param>
325+
/// <param name="checkIsAlreadyImportedInEngine">Determine if it should check if the package is already imported by unity itself.</param>
326+
/// <returns>True if the given package is installed. False if it is not.</returns>
327+
internal static bool IsInstalled([NotNull] string packageId, bool checkIsAlreadyImportedInEngine)
328+
{
329+
if (checkIsAlreadyImportedInEngine && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(packageId))
330+
{
331+
return true;
332+
}
333+
334+
return InstalledPackagesDictionary.ContainsKey(packageId);
335+
}
336+
321337
/// <summary>
322338
/// Gets a list of all root packages that are installed in the project.
323339
/// Root packages are packages that are not depended on by any other package.

src/NuGetForUnity/Editor/NugetPackageInstaller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class NugetPackageInstaller
2727
/// <returns>True if the package was installed successfully, otherwise false.</returns>
2828
public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package, bool refreshAssets = true, bool isSlimRestoreInstall = false)
2929
{
30-
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
30+
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
3131
{
3232
NugetLogger.LogVerbose("Package {0} is already imported in engine, skipping install.", package);
3333
return true;
@@ -54,7 +54,7 @@ public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package,
5454
/// <returns>True if the package was installed successfully, otherwise false.</returns>
5555
private static bool Install([NotNull] INugetPackage package, bool refreshAssets, bool isSlimRestoreInstall)
5656
{
57-
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
57+
if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
5858
{
5959
NugetLogger.LogVerbose("Package {0} is already imported in engine, skipping install.", package);
6060
return true;

src/NuGetForUnity/Editor/NugetPackageUninstaller.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
2424
{
2525
// Checking for pre-imported packages also ensures that the pre-imported package list is up-to-date before we uninstall packages.
2626
// Without this the pre-imported package list can contain the package as we delete the .dll before we call 'AssetDatabase.Refresh()'.
27-
if (UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package, false))
27+
if (UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
2828
{
2929
Debug.LogWarning($"Uninstalling {package} makes no sense because it is a package that is 'pre-imported' by Unity.");
3030
}
@@ -73,7 +73,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
7373
}
7474

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

8888
AssetDatabase.Refresh();
8989
}
90+
91+
/// <summary>
92+
/// Uninstalls all of the currently installed packages.
93+
/// </summary>
94+
public static void UninstallAll()
95+
{
96+
UninstallAll(InstalledPackagesManager.InstalledPackages.ToList());
97+
}
9098
}
9199
}

0 commit comments

Comments
 (0)