diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index 9de2f81..2ad396c 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -122,8 +122,8 @@ namespace Il2CppInspector.CLI var unityAssembliesPath = string.Empty; if (options.CreateSolution) { - unityPath = FindPath(options.UnityPath); - unityAssembliesPath = FindPath(options.UnityAssembliesPath); + unityPath = Utils.FindPath(options.UnityPath); + unityAssembliesPath = Utils.FindPath(options.UnityAssembliesPath); if (!Directory.Exists(unityPath)) { Console.Error.WriteLine($"Unity path {unityPath} does not exist"); @@ -224,34 +224,5 @@ namespace Il2CppInspector.CLI // Success exit code return 0; } - - private static string FindPath(string pathWithWildcards) { - var absolutePath = Path.GetFullPath(pathWithWildcards); - - if (absolutePath.IndexOf("*", StringComparison.Ordinal) == -1) - return absolutePath; - - Regex sections = new Regex(@"((?:[^*]*)\\)((?:.*?)\*.*?)(?:$|\\)"); - var matches = sections.Matches(absolutePath); - - var pathLength = 0; - var path = ""; - foreach (Match match in matches) { - path += match.Groups[1].Value; - var search = match.Groups[2].Value; - - var dir = Directory.GetDirectories(path, search, SearchOption.TopDirectoryOnly) - .OrderByDescending(x => x) - .FirstOrDefault(); - - path = dir + @"\"; - pathLength += match.Groups[1].Value.Length + match.Groups[2].Value.Length + 1; - } - - if (pathLength < absolutePath.Length) - path += absolutePath.Substring(pathLength); - - return path; - } } } diff --git a/Il2CppInspector.CLI/Utils.cs b/Il2CppInspector.CLI/Utils.cs new file mode 100644 index 0000000..ab211bb --- /dev/null +++ b/Il2CppInspector.CLI/Utils.cs @@ -0,0 +1,45 @@ +// Copyright (c) 2017-2020 Katy Coe - https://www.djkaty.com - https://github.com/djkaty +// All rights reserved + +using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Il2CppInspector +{ + public class Utils + { + public static string FindPath(string pathWithWildcards) { + var absolutePath = Path.GetFullPath(pathWithWildcards); + + if (absolutePath.IndexOf("*", StringComparison.Ordinal) == -1) + return absolutePath; + + Regex sections = new Regex(@"((?:[^*]*)\\)((?:.*?)\*.*?)(?:$|\\)"); + var matches = sections.Matches(absolutePath); + + var pathLength = 0; + var path = ""; + foreach (Match match in matches) { + path += match.Groups[1].Value; + var search = match.Groups[2].Value; + + if (!Directory.Exists(path)) + return null; + + var dir = Directory.GetDirectories(path, search, SearchOption.TopDirectoryOnly) + .OrderByDescending(x => x) + .FirstOrDefault(); + + path = dir + @"\"; + pathLength += match.Groups[1].Value.Length + match.Groups[2].Value.Length + 1; + } + + if (pathLength < absolutePath.Length) + path += absolutePath.Substring(pathLength); + + return path; + } + } +} \ No newline at end of file