From 0cfeddb88eb748c6b9f34449161eb7996896e4d0 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Fri, 16 Dec 2022 22:52:46 +0100 Subject: [PATCH] GenArray: Add methods to get project references --- Ryujinx.CustomTasks/GenerateArrays.cs | 140 ++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/Ryujinx.CustomTasks/GenerateArrays.cs b/Ryujinx.CustomTasks/GenerateArrays.cs index aad6127..3a2523b 100644 --- a/Ryujinx.CustomTasks/GenerateArrays.cs +++ b/Ryujinx.CustomTasks/GenerateArrays.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using Ryujinx.CustomTasks.SyntaxWalker; using Ryujinx.CustomTasks.Helper; +using System; using System.Linq; using Task = Microsoft.Build.Utilities.Task; @@ -65,6 +66,145 @@ namespace Ryujinx.CustomTasks return size; } + private string[] GetProjectFiles() + { + if (ScanSolution) + { + return Directory.GetFiles(SolutionDir, "*.csproj", SearchOption.AllDirectories); + } + else + { + return Directory.GetFiles(ProjectDir, "*.csproj", SearchOption.TopDirectoryOnly); + } + } + + private bool TryGetNugetAssemblyPath(string package, string version, out string assemblyPath) + { + if (string.IsNullOrEmpty(version)) + { + assemblyPath = ""; + + return false; + } + + string basePath = Path.Combine(NugetPackagePath, package.ToLower(), version, "lib"); + string filePath; + + if (Directory.Exists(Path.Combine(basePath, TargetFramework))) + { + filePath = Directory.GetFiles(Path.Combine(basePath, TargetFramework), "*.dll", SearchOption.TopDirectoryOnly).FirstOrDefault(); + + if (string.IsNullOrEmpty(filePath)) + { + assemblyPath = ""; + + return false; + } + + assemblyPath = filePath; + + return true; + } + + string[] frameworks = Directory.GetDirectories(basePath); + + List standardList = frameworks.Where(framework => framework.Contains("netstandard")).ToList(); + + if (standardList.Count > 0) + { + filePath = Directory.GetFiles(Path.Combine(basePath, standardList.Max()), "*.dll", SearchOption.TopDirectoryOnly).FirstOrDefault(); + + if (string.IsNullOrEmpty(filePath)) + { + assemblyPath = ""; + + return false; + } + + assemblyPath = filePath; + + return true; + } + + assemblyPath = Directory.GetFiles(Path.Combine(basePath, frameworks.Max()), "*.dll", SearchOption.TopDirectoryOnly).FirstOrDefault(); + + return !string.IsNullOrEmpty(assemblyPath); + } + + private string GetAttributeValue(string line, string attribute) + { + int startIndex = line.IndexOf($"{attribute}=\"", StringComparison.OrdinalIgnoreCase) + 1; + int length = line.Substring(startIndex).IndexOf("\"", StringComparison.OrdinalIgnoreCase); + + return line.Substring(startIndex, length); + } + + private string GetCentralPackageVersion(string packageName) + { + string packagePropsPath = Path.Combine(SolutionDir, "Directory.Packages.props"); + + if (!File.Exists(packagePropsPath)) + { + return ""; + } + + foreach (var line in File.ReadLines(packagePropsPath)) + { + string trimmedLine = line.Trim(); + + if (trimmedLine.StartsWith(" GetReferences(string projectPath) + { + bool isItemGroup = false; + HashSet references = new HashSet(); + + // Filter for PackageReference and ProjectReference + foreach (string line in File.ReadLines(projectPath)) + { + string trimmedLine = line.Trim(); + + if (!isItemGroup && trimmedLine.Contains("")) + { + isItemGroup = true; + } + + switch (isItemGroup) + { + case true when trimmedLine.Contains("", StringComparison.OrdinalIgnoreCase): + isItemGroup = false; + break; + } + } + + return references; + } + private void AddGeneratedSource(string filePath, string content) { bool addToOutputFiles = true;