using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BepInEx.Common
{
///
/// Generic helper properties and methods.
///
public static class Utility
{
///
/// The directory that the Koikatsu .exe is being run from.
///
public static string ExecutingDirectory => Path.GetDirectoryName(Environment.CommandLine);
///
/// The path that the plugins folder is located.
///
public static string PluginsDirectory => Path.Combine(ExecutingDirectory, "BepInEx");
///
/// Combines multiple paths together, as the specfic method is not availble in .NET 3.5.
///
/// The multiple paths to combine together.
/// A combined path.
public static string CombinePaths(params string[] parts) => parts.Aggregate(Path.Combine);
///
/// Converts a file path into a UnityEngine.WWW format.
///
/// The file path to convert.
/// A converted file path.
public static string ConvertToWWWFormat(string path)
{
return $"file://{path.Replace('\\', '/')}";
}
///
/// Indicates whether a specified string is null, empty, or consists only of white-space characters.
///
/// The string to test.
/// True if the value parameter is null or empty, or if value consists exclusively of white-space characters.
public static bool IsNullOrWhiteSpace(this string self)
{
return self == null || self.Trim().Length == 0;
}
public static IEnumerable TopologicalSort(IEnumerable nodes, Func> dependencySelector)
{
List sorted_list = new List();
HashSet visited = new HashSet();
HashSet sorted = new HashSet();
foreach (TNode input in nodes)
Visit(input);
return sorted_list;
void Visit(TNode node)
{
if (visited.Contains(node))
{
if (!sorted.Contains(node))
throw new Exception("Cyclic Dependency");
}
else
{
visited.Add(node);
foreach (var dep in dependencySelector(node))
Visit(dep);
sorted.Add(node);
sorted_list.Add(node);
}
}
}
}
}