diff --git a/.gitignore b/.gitignore index a82d729..ec9b340 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /NuGetImporterForUnity/[Bb]uilds/ /NuGetImporterForUnity/[Ll]ogs/ /NuGetImporterForUnity/[Mm]emoryCaptures/ +/NuGetImporterForUnity/[Uu]ser[Ss]ettings/ /Packager/[Ll]ibrary/ /Packager/[Tt]emp/ /Packager/[Oo]bj/ @@ -89,4 +90,10 @@ crashlytics-build.properties /NuGetImporterForUnity/[Nn]u[Gg]et/ /NuGetImporterForUnity/[Pp]ackages/*/ -!/NuGetImporterForUnity/[Pp]ackages/[Nn]u[Gg]et [Ii]mporter/ \ No newline at end of file +!/NuGetImporterForUnity/[Pp]ackages/[Nn]u[Gg]et [Ii]mporter/ + +# MacOS attribute file +.DS_Store + +# VS Code meta files +.vscode diff --git a/NuGetImporterForUnity/Packages/NuGet Importer/Editor/DataClasses/NativePlatform.cs b/NuGetImporterForUnity/Packages/NuGet Importer/Editor/DataClasses/NativePlatform.cs index 916abb4..fedd935 100644 --- a/NuGetImporterForUnity/Packages/NuGet Importer/Editor/DataClasses/NativePlatform.cs +++ b/NuGetImporterForUnity/Packages/NuGet Importer/Editor/DataClasses/NativePlatform.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; namespace kumaS.NuGetImporter.Editor.DataClasses { @@ -54,25 +55,41 @@ public class NativePlatform public NativePlatform(string directoryPath) { Path = directoryPath; - var directoryName = System.IO.Path.GetFileName(directoryPath).ToLowerInvariant(); - (OS, OSPriority) = GetOSInfo(directoryName); - Architecture = GetArchInfo(directoryName); + // https://learn.microsoft.com/en-us/dotnet/core/rid-catalog + var rid = GetRidFrom(directoryPath); + (OS, OSPriority) = GetOSInfo(rid); + Architecture = GetArchInfo(rid); } - private (string os, int priority) GetOSInfo(string directoryName) + private static string GetRidFrom(string path) + { // https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders + // assumes right path is like "Packages/project/runtimes/RID/native/..." or somthing + path = path.Replace('\\', '/'); // in case of '\'(windows) + var pattern = "/?runtimes/(.+?)/?"; + var matched = Regex.Match( + path, + pattern, + RegexOptions.RightToLeft | // to choose last + RegexOptions.IgnoreCase); + if (!matched.Success) + return string.Empty; // failed to find + return matched.Groups[1].Value.Split('/')[0]; + } + + private (string os, int priority) GetOSInfo(string rid) { - var matchedPriority = PriorityTable.Where(table => directoryName.StartsWith(table.Item1.ToLowerInvariant())); + var matchedPriority = PriorityTable.Where(table => rid.StartsWith(table.Item1.ToLowerInvariant())); if (matchedPriority.Any()) { return matchedPriority.First(); } - return (directoryName.Split('-')[0], int.MaxValue); + return (rid.Split('-')[0], int.MaxValue); } - private string GetArchInfo(string directoryName) + private string GetArchInfo(string rid) { - var matchedArch = Enum.GetNames(typeof(ArchitectureType)).Where(table => directoryName.EndsWith(table.ToLowerInvariant())); + var matchedArch = Enum.GetNames(typeof(ArchitectureType)).Where(table => rid.EndsWith(table.ToLowerInvariant())); if (matchedArch.Any()) { return matchedArch.First(); diff --git a/NuGetImporterForUnity/Packages/NuGet Importer/Editor/NuGetNativeImportSetting.cs b/NuGetImporterForUnity/Packages/NuGet Importer/Editor/NuGetNativeImportSetting.cs index 386c3fa..de6c16b 100644 --- a/NuGetImporterForUnity/Packages/NuGet Importer/Editor/NuGetNativeImportSetting.cs +++ b/NuGetImporterForUnity/Packages/NuGet Importer/Editor/NuGetNativeImportSetting.cs @@ -127,13 +127,9 @@ string pluginPath BuildTarget target = BuildTarget.NoTarget; var architecture = ""; var enableOnEditor = false; - var platformPath = pluginPath; - while (platformPath!.Contains("native")) - { - platformPath = Path.GetDirectoryName(platformPath); - } - var platform = new NativePlatform(platformPath); + var directoryPath = Path.GetDirectoryName(pluginPath); + var platform = new NativePlatform(directoryPath); architecture = platform.Architecture switch { nameof(ArchitectureType.X64) => platform.OS == nameof(OSType.IOS) ? "X64" : "x86_64",