Abstract Unity path search to own class
This commit is contained in:
@@ -122,8 +122,8 @@ namespace Il2CppInspector.CLI
|
|||||||
var unityAssembliesPath = string.Empty;
|
var unityAssembliesPath = string.Empty;
|
||||||
|
|
||||||
if (options.CreateSolution) {
|
if (options.CreateSolution) {
|
||||||
unityPath = FindPath(options.UnityPath);
|
unityPath = Utils.FindPath(options.UnityPath);
|
||||||
unityAssembliesPath = FindPath(options.UnityAssembliesPath);
|
unityAssembliesPath = Utils.FindPath(options.UnityAssembliesPath);
|
||||||
|
|
||||||
if (!Directory.Exists(unityPath)) {
|
if (!Directory.Exists(unityPath)) {
|
||||||
Console.Error.WriteLine($"Unity path {unityPath} does not exist");
|
Console.Error.WriteLine($"Unity path {unityPath} does not exist");
|
||||||
@@ -224,34 +224,5 @@ namespace Il2CppInspector.CLI
|
|||||||
// Success exit code
|
// Success exit code
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
Il2CppInspector.CLI/Utils.cs
Normal file
45
Il2CppInspector.CLI/Utils.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user