/// <summary> /// Заполняет аргументы запуска необходимыми либами /// </summary> private void FillLibrariesPaths() { // нашли папку с либами var dirs = Directory.GetDirectories(_minecraftPath, "libraries", SearchOption.AllDirectories); var dir = PathsHelper.GetTopPath(dirs); // проерили CheckFolderAndThrow(dir); // вытащили все jar var allJars = Directory.GetFiles(dir, "*.jar", SearchOption.AllDirectories).ToList(); var selected = new List <string>(); // ищем те, которые нужны foreach (var libName in LibraryNameRegexes) { var libs = allJars.Where(x => Regex.IsMatch(x, libName)).ToList(); if (libs.IsNullOrEmpty()) { continue; } var shortest = PathsHelper.GetShortestName(libs); selected.Add(shortest); allJars.Remove(shortest); } _libPaths = string.Join(";", selected); }
public void TestShortestName() { var paths = new List <string> { @"H:\Users\Tom\AppData\Roaming\.minecraft\libraries\net\minecraft\launchwrapper\1.12\launchwrapper-1.12.jar", @"H:\Users\Tom\AppData\Roaming\.minecraft\libraries\net\minecraft\launchwrapper\1.12\launchwrapper.jar", @"H:\Users\Tom\AppData\Roaming\.minecraft\libraries\net\minecraft\1.12\launchwrapper-1.12.jar", @"H:\Users\Tom\AppData\Roaming\\net\minecraft\launchwrapper\1.12\launchwrapper-1.12.jar", @"H:\launchwrapper-1.12.jar", @"H:\Users\Tom\AppData\Roaming\\net\minecraft\launchwrapper\1.12.jar", }; Assert.IsTrue(string.Equals(PathsHelper.GetShortestName(paths), paths.LastOrDefault())); }