Skip to content

Commit

Permalink
Added support customizing installation folder name from the plugin (#662
Browse files Browse the repository at this point in the history
)

* Added support customizing installation folder name from the plugin

* Updated version of PluginAPI dll to 1.0.2
  • Loading branch information
igor84 authored Jul 22, 2024
1 parent 698989e commit 90fa6db
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace NugetForUnity.PluginAPI.ExtensionPoints
/// </summary>
public interface IPackageInstallFileHandler
{
/// <summary>
/// This will be called when name of the folder where package will be installed should be determined.
/// </summary>
/// <param name="package">The package whose folder name is being determined.</param>
/// <param name="startName">The starting default name that can be modified or replaced.</param>
/// <returns>New package folder name.</returns>
string GetPackageFolderName(INugetPackageIdentifier package, string startName);

/// <summary>
/// This will be called for each entry that is about to be processed from nupkg that is being installed.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity.PluginAPI/NuGetForUnity.PluginAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageTags>Unity</PackageTags>
<Title>NuGetForUnity PluginAPI</Title>
<Description>The API used to develop plug-ins for NuGetForUnity.</Description>
<Version>1.0.0</Version>
<Version>1.0.2</Version>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Release' ">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(MSBuildThisFileDirectory)..\NuGetForUnity\Editor\PluginAPI\" />
Expand Down
4 changes: 3 additions & 1 deletion src/NuGetForUnity/Editor/Models/NugetPackageIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using JetBrains.Annotations;
using NugetForUnity.Configuration;
using NugetForUnity.PluginSupport;
using UnityEngine;

#region No ReShaper
Expand Down Expand Up @@ -186,7 +187,8 @@ public string Version
/// <inheritdoc />
public string GetPackageInstallPath(string prefix = "")
{
return Path.Combine(ConfigurationManager.NugetConfigFile.RepositoryPath, $"{prefix}{Id}.{Version}");
var folderName = PluginRegistry.Instance.GetPackageFolderName(this, $"{prefix}{Id}.{Version}");
return Path.Combine(ConfigurationManager.NugetConfigFile.RepositoryPath, folderName);
}

/// <inheritdoc />
Expand Down
4 changes: 3 additions & 1 deletion src/NuGetForUnity/Editor/PackageContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NugetForUnity.Configuration;
using NugetForUnity.Helper;
using NugetForUnity.Models;
using NugetForUnity.PluginSupport;
using UnityEngine;

namespace NugetForUnity
Expand Down Expand Up @@ -349,7 +350,8 @@ internal static void MoveInstalledPackages(string oldPath, string newPath)
[NotNull]
private static string GetPackageOutsideInstallDirectory([NotNull] INugetPackageIdentifier package)
{
return Path.Combine(UnityPathHelper.AbsoluteProjectPath, "Packages", $"{package.Id}.{package.Version}");
var folderName = PluginRegistry.Instance.GetPackageFolderName(package, $"{package.Id}.{package.Version}");
return Path.Combine(UnityPathHelper.AbsoluteProjectPath, "Packages", folderName);
}
}
}
Binary file modified src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.dll
Binary file not shown.
42 changes: 19 additions & 23 deletions src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/NuGetForUnity/Editor/PluginSupport/PluginRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ public void DrawButtons(INugetPackage package, INugetPackage installedPackage, b
}
}

/// <inheritdoc/>
public string GetPackageFolderName(INugetPackageIdentifier package, string startName)
{
var newName = startName;
foreach (var packageInstallFileHandler in packageInstallFileHandlers)
{
try
{
newName = packageInstallFileHandler.GetPackageFolderName(package, newName);
}
catch (Exception e)
{
Debug.LogError($"Exception while executing GetPackageFolderName plugin handler {e}");
}
}

return newName;
}

/// <inheritdoc />
public bool HandleFileExtraction(INugetPackage package, ZipArchiveEntry entry, string extractDirectory)
{
Expand Down
2 changes: 0 additions & 2 deletions src/NuGetForUnity/Editor/Ui/NugetWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,6 @@ private void DrawPackage(INugetPackage package, GUIStyle backgroundStyle, bool c
var cloneButtonBoxStyle =
new GUIStyle("box") { stretchWidth = false, margin = { top = 0, bottom = 0 }, padding = { bottom = 4 } };

var normalButtonBoxStyle = new GUIStyle(cloneButtonBoxStyle) { normal = { background = backgroundStyle.normal.background } };

var showCloneWindow = openCloneWindows.Contains(package);
cloneButtonBoxStyle.normal.background = backgroundStyle.normal.background;

Expand Down

0 comments on commit 90fa6db

Please sign in to comment.