public static PluginInfo GetPlugin( string searchName, ulong[] searchIds = null, SearchOptionT searchOptions = DefaultsearchOptions) { foreach (PluginInfo current in PluginManager.instance.GetPluginsInfo()) { if (current == null) { continue; } bool match = Matches(current, searchIds); IUserMod userModInstance = current.userModInstance as IUserMod; if (userModInstance == null) { continue; } if (searchOptions.IsFlagSet(SearchOptionT.UserModName)) { match = match || Match(userModInstance.Name, searchName, searchOptions); } Type userModType = userModInstance.GetType(); if (searchOptions.IsFlagSet(SearchOptionT.UserModType)) { match = match || Match(userModType.Name, searchName, searchOptions); } if (searchOptions.IsFlagSet(SearchOptionT.RootNameSpace)) { string ns = userModType.Namespace; string rootNameSpace = ns.Split('.')[0]; match = match || Match(rootNameSpace, searchName, searchOptions); } if (searchOptions.IsFlagSet(SearchOptionT.PluginName)) { match = match || Match(current.name, searchName, searchOptions); } if (searchOptions.IsFlagSet(SearchOptionT.AssemblyName)) { Assembly asm = current.GetMainAssembly(); match = match || Match(asm?.Name(), searchName, searchOptions); } if (match) { Log.Info("Found plug-in:" + current.GetModName()); return(current); } } Log.Info($"plug-in not found: keyword={searchName} options={searchOptions}"); return(null); }
public static bool Match(string name1, string name2, SearchOptionT searchOptions = DefaultsearchOptions) { if (string.IsNullOrEmpty(name1)) { return(false); } Assertion.Assert((searchOptions & SearchOptionT.AllTargets) != 0); if (searchOptions.IsFlagSet(SearchOptionT.CaseInsensetive)) { name1 = name1.ToLower(); name2 = name2.ToLower(); } if (searchOptions.IsFlagSet(SearchOptionT.IgnoreWhiteSpace)) { name1 = name1.Replace(" ", ""); name2 = name2.Replace(" ", ""); } if (Log.VERBOSE) { Log.Debug($"[MATCHING] : {name1} =? {name2} " + searchOptions); } if (name1 == name2) { return(true); } if (searchOptions.IsFlagSet(SearchOptionT.Contains)) { if (name1.Contains(name2)) { return(true); } } if (searchOptions.IsFlagSet(SearchOptionT.StartsWidth)) { if (name1.StartsWith(name2)) { return(true); } } return(false); }