private void _loadPlugins() { var pluginsDirectory = new DirectoryInfo(_pluginsPath); if (!pluginsDirectory.Exists) { pluginsDirectory.Create(); } foreach (var file in pluginsDirectory.GetFiles("*.dll")) { var assembly = Assembly.LoadFrom(file.FullName); foreach (var type in assembly.GetTypes()) { if (!type.IsSubclassOf(typeof(IPlugin)) || type.IsAbstract) { continue; } Longship.Log($"Loading plugin {file.Name}..."); try { _plugins[type] = new LoadedPlugin() { Plugin = type.InvokeMember( null, BindingFlags.CreateInstance, null, null, null) as IPlugin, Name = file.Name }; } catch (Exception e) { Longship.LogError($"Can't load plugin {file.Name}."); Longship.LogException(e); } } } }
public bool DisablePlugin <T>() where T : IPlugin { if (!_plugins.TryGetValue(typeof(T), out var value)) { return(false); } Longship.Log($"Disabling {value.Name}..."); try { Longship.Instance.EventManager.ClearListeners(value.Plugin); Longship.Instance.CommandsManager.ClearListeners(value.Plugin); value.Plugin.OnDisable(); } catch (Exception e) { Longship.LogError($"Error while disabling plugin {value.Name}"); Longship.LogException(e); } Longship.Log($"{value.Name} disabled."); return(false); }
public static bool CheckForUpdate(out string url) { var client = new WebClient(); try { var lastRelease = JsonUtility.FromJson <LastRelease>(client.DownloadString(RELEASES_URL)); if (!lastRelease.draft && !lastRelease.prerelease) { url = lastRelease.url; return(lastRelease.tag_name != Longship.BuildTag); } } catch (Exception e) { Longship.LogWarning("Can't check if updates are available."); Longship.LogException(e); } url = null; return(false); }