12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace BepInEx.Common
- {
-
-
-
- public static class Utility
- {
-
-
-
- public static string ExecutingDirectory => Path.GetDirectoryName(Environment.CommandLine);
-
-
-
- public static string PluginsDirectory => Path.Combine(ExecutingDirectory, "BepInEx");
-
-
-
-
-
- public static string CombinePaths(params string[] parts) => parts.Aggregate(Path.Combine);
-
-
-
-
-
- public static string ConvertToWWWFormat(string path)
- {
- return $"file://{path.Replace('\\', '/')}";
- }
-
-
-
-
-
- public static bool IsNullOrWhiteSpace(this string self)
- {
- return self == null || self.Trim().Length == 0;
- }
- public static IEnumerable<TNode> TopologicalSort<TNode>(IEnumerable<TNode> nodes, Func<TNode, IEnumerable<TNode>> dependencySelector)
- {
- List<TNode> sorted_list = new List<TNode>();
- HashSet<TNode> visited = new HashSet<TNode>();
- HashSet<TNode> sorted = new HashSet<TNode>();
- 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);
- }
- }
- }
- }
- }
|