예제 #1
0
 public void FetchPlugins()
 {
     LoadedPlugins = FetchPluginsImpl().ToList();
     for (var i = 0; i < LoadedPlugins.Count; i++)
     {
         LoadedPlugins[i].Enabled = Globals.SettingsHelper.FetchPlugin(LoadedPlugins[i].PluginHostGuid).Enabled;
     }
     LoadedPlugins.ForEach(lp =>
     {
         var pluginMd = Globals.SettingsHelper.FetchPlugin(lp.PluginHostGuid);
         if (lp.PluginHost.Plugins != null && pluginMd.Enabled)
         {
             lp.PluginHost.Plugins.ForEach(lpp =>
             {
                 if (lpp.PluginPackets != null)
                 {
                     lpp.PluginPackets.ForEach(lppp =>
                     {
                         Globals.PacketProcessor.PacketTable.Add(lppp.PacketId, lppp.GetType());
                     });
                 }
                 lpp.Initialize();
             });
         }
     });
 }
예제 #2
0
        private IEnumerable <RemoteClientPlugin> FetchRemotePluginsImpl()
        {
            foreach (var file in Directory.GetFiles(Application.StartupPath + "\\plugins\\client"))

            {
                if (!file.GetFileName().ToLower().Contains("plugin"))
                {
                    continue;
                }
                if (!file.GetFileName().EndsWith(".dll"))
                {
                    continue;
                }
                var fileBuff     = File.ReadAllBytes(file);
                var asm          = Assembly.LoadFile(file);
                var attribute    = (GuidAttribute)asm.GetCustomAttributes(typeof(GuidAttribute), true)[0];
                var remotePlugin = new RemoteClientPlugin(file, fileBuff, HashHelper.CalculateSha256(fileBuff))
                {
                    PluginGuid = new Guid(attribute.Value)
                };
                remotePlugin.AssociatedServerPluginHost =
                    LoadedPlugins.First(p => p.PluginHost.AssociatedClientPlugin.Equals(new Guid(attribute.Value)));
                yield return(remotePlugin);
            }
        }
예제 #3
0
        private void CloseTab(Plugin plugin)
        {
            if (!CanClose(plugin))
            {
                return;
            }

            bool changeSelection = (plugin == SelectedPlugin);
            int  selectedIndex   = LoadedPlugins.IndexOf(plugin);

            _pluginController.RemovePlugin(plugin);

            if (changeSelection)
            {
                int count = LoadedPlugins.Count;

                if (count == 0)
                {
                    SelectedPlugin = null;
                }
                else
                {
                    if (selectedIndex >= count)
                    {
                        selectedIndex = count - 1;
                    }
                    SelectedPlugin = LoadedPlugins[selectedIndex];
                }
            }
        }
예제 #4
0
        public async Task AddPlugin(string settingFile, List <ZipArchiveEntry> files)
        {
            var plugin = JsonConvert.DeserializeObject <Plugin>(settingFile);

            plugin.Valid = true;
            if (LoadedPlugins.Any())
            {
                plugin.Priority = LoadedPlugins.Max(x => x.Priority) + 1;
            }
            else
            {
                plugin.Priority = 1;
            }
            var loadeds = new List <Plugin>(LoadedPlugins);

            Directory.CreateDirectory($"plugins/{plugin.PluginPath}");
            plugin.IsEnabled = false;
            foreach (var file in files)
            {
                file.ExtractToFile(Path.Combine($"plugins/{plugin.PluginPath}", file.FullName), true);
            }
            PreCompilePlugin(plugin);
            loadeds.Add(plugin);
            LoadedPlugins = loadeds;
            await File.WriteAllTextAsync(PluginSettingPath, JsonConvert.SerializeObject(LoadedPlugins));
        }
예제 #5
0
        public async Task PatchPluginPriority(string pluginPath, int priority)
        {
            var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == pluginPath);

            plugin.Priority = priority;
            await SavePluginInfo();
        }
예제 #6
0
        public async Task PatchPluginActivatedBoards(string pluginPath, string[] activatedBoards)
        {
            var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == pluginPath);

            plugin.ActivatedBoards = activatedBoards;
            await SavePluginInfo();
        }
예제 #7
0
    protected void OnRemoveActionActivated(object sender, EventArgs e)
    {
        Gtk.ResponseType responseType  = Gtk.ResponseType.None;
        LoadedPlugins    loadedPlugins = new LoadedPlugins(plugins);

        try {
            responseType = (Gtk.ResponseType)loadedPlugins.Run();

            if (responseType == Gtk.ResponseType.Ok)
            {
                Gtk.TreeModel     model;
                Gtk.TreeIter      iter;
                Gtk.TreeSelection selection = loadedPlugins.treeView.Selection;

                selection.GetSelected(out model, out iter);

                string pluginToDelete = (model.GetValue(iter, 0).ToString());
                removePlugin(pluginToDelete);
                //plugins.RemovePlugin(pluginToDelete);
                //DockItem item = DockFrame.GetItem(pluginToDelete);
                //item.Visible = false;
                //dockFrame.RemoveItem(item);
                SaveLayout();
            }
        }
        finally {
            loadedPlugins.Hide();
            loadedPlugins.Dispose();
        }
    }
예제 #8
0
        public async Task PatchPluginEnable(string pluginPath, bool enable)
        {
            var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == pluginPath);

            plugin.IsEnabled = enable;
            await SavePluginInfo();
        }
예제 #9
0
        // Board settings will allow only key-value pair and value is not nested item or array.
        // ex.
        // Settings: {
        //     "Name" : "text", // allow
        //     "Users" : [ "Kain", "KOJIMA" ] // allow
        //     "UserDetail" : [ { "name" : "kain", auth: false } ] // disallow
        // }
        public async Task <string> GetBoardPluginSetting(string boardKey, string pluginPath)
        {
            var path = GetPluginBoardSettingPath(boardKey, pluginPath);

            if (!File.Exists(path))
            {
                var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == pluginPath);
                if (plugin == null)
                {
                    throw new InvalidOperationException("Not found plugin");
                }
                else
                {
                    if (plugin.HasBoardSetting)
                    {
                        return(JsonConvert.SerializeObject(plugin.DefaultBoardSetting));
                    }
                    else
                    {
                        throw new InvalidOperationException("This plugin cannot has settings.");
                    }
                }
            }
            return(await File.ReadAllTextAsync(path));
        }
예제 #10
0
    protected void OnRemoveActionActivated(object sender, EventArgs e)
    {
        Gtk.ResponseType responseType  = Gtk.ResponseType.None;
        LoadedPlugins    loadedPlugins = new LoadedPlugins(plugins);

        try {
            responseType = (Gtk.ResponseType)loadedPlugins.Run();

            if (responseType == Gtk.ResponseType.Ok)
            {
                Gtk.TreeModel  treeModel;
                Gtk.TreeIter   iter;
                Gtk.TreePath[] selectedRows = null;
                selectedRows = loadedPlugins.treeView.Selection.GetSelectedRows();

                for (int i = 0; i < selectedRows.Length; i++)
                {
                    loadedPlugins.lsLoadedPlugins.GetIter(out iter, selectedRows[i]);
                    string          pluginPath = (string)loadedPlugins.lsLoadedPlugins.GetValue(iter, 0);
                    PluginInfo      pluginInfo = plugins.Plugins.Find(x => x.codeBase == pluginPath);
                    List <IService> services   = plugins.GetServices(pluginInfo);

                    foreach (IService service in services)
                    {
                        plugins.RemovePlugin(pluginInfo.codeBase);
                        (service as IPlugin).UnInit(null);
                    }
                }
            }
        }
        finally {
            loadedPlugins.Hide();
        }
    }
예제 #11
0
        } = 3000;                                                      // Milliseconds

        #endregion


        #region PUBLIC

        public static void AddNewPlugin(IPlugin newPlugin)
        {
            if (newPlugin != null &&
                LoadedPlugins.FindAll(elem => elem.Config.Name == newPlugin.Config.Name).Count <= 0)
            {
                LoadedPlugins.Add(newPlugin);
                LoadedPlugins.Sort((s1, s2) => s1.CompareTo(s2));
            }
        }
예제 #12
0
 public void InitializePlugins()
 {
     foreach (var pluginHost in LoadedPlugins.Where(lp => lp.Enabled))
     {
         foreach (var plugin in pluginHost.PluginHost.Plugins)
         {
             plugin.Initialize();
         }
     }
 }
예제 #13
0
        public void LoadPlugins()
        {
            Console.WriteLine("Loading plugins...");
            Console.WriteLine();
            var pluginFiles = Directory.GetFiles(PluginFolder);
            var pluginTypes = new List <Type>();

            for (int i = 0; i < pluginFiles.Length; i++)
            {
                try
                {
                    if (Path.GetExtension(pluginFiles[i]) != ".dll")
                    {
                        continue;
                    }

                    Console.WriteLine("Loading {0}...", pluginFiles[i]);
                    var assembly = Assembly.LoadFrom(pluginFiles[i]);
                    var types    = assembly.GetExportedTypes();
                    for (int j = 0; j < types.Length; j++)
                    {
                        if (m_PluginType.IsAssignableFrom(types[j]) && !types[j].IsAbstract)
                        {
                            var plugin = Activator.CreateInstance(types[j]) as Plugin;
                            Console.WriteLine("\tLoading {0}...", plugin.GetType().Name);
                            Console.WriteLine("\t\tName: {0}\n\t\tDescription: {1}\n\t\tAuthor: {2}", plugin.Name, plugin.Description, plugin.Author);

                            plugin.Client = m_Client;
                            LoadedPlugins.Add(plugin);
                        }
                    }
                    Console.WriteLine();
                    LoadedPluginAssemblies.Add(assembly);
                }
                catch (PluginException)
                {
                    //TODO: Add logs.
                    //TODO: Remove plugin if the plugin was loaded.
                    Console.WriteLine("Error in plugin {0} constructor", pluginFiles[i]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while loading {0}: \n\t{1}", pluginFiles[i], ex.Message);
                }
            }

            for (int i = 0; i < LoadedPlugins.Count; i++)
            {
                var pluginTasks = new PluginTasks(LoadedPlugins[i]);
                m_PluginTasks.Add(pluginTasks);
                pluginTasks.DoLoad();
            }
        }
 public bool ImportPlugin(string pluginPath)
 {
     if (LoadedPlugins.Any(p => p.FullName == pluginPath))
     {
         return(true);
     }
     else
     {
         var plugin = new FileInfo(pluginPath);
         LoadedPlugins.Add(plugin);
         return(PluginManager.AddPlugin(plugin));
     }
 }
예제 #15
0
 public Task <bool> ImportPlugin(string pluginPath)
 {
     if (LoadedPlugins.Any(p => p.FullName == pluginPath))
     {
         return(Task.FromResult(true));
     }
     else
     {
         var plugin = new FileInfo(pluginPath);
         LoadedPlugins.Add(plugin);
         return(Task.FromResult(PluginManager.AddPlugin(plugin)));
     }
 }
예제 #16
0
        protected void LoadPlugins()
        {
            var pl = LoadedPlugins.ToList();

            foreach (var item in Plugins)
            {
                foreach (var perm in item.Permissions)
                {
                    if (WorkingPermissions.Contains(perm))
                    {
                    }
                }
            }
        }
예제 #17
0
        /// <summary>
        /// Called when the plugin manager is unloading a plugin that was loaded by this plugin loader
        /// </summary>
        /// <param name="plugin_base"></param>
        public override void Unloading(Plugin plugin_base)
        {
            var plugin = plugin_base as CSharpPlugin;

            LoadedPlugins.Remove(plugin.Name);
            // Unload plugins which require this plugin first
            foreach (var compilable_plugin in plugins.Values)
            {
                if (compilable_plugin.Requires.Contains(plugin.Name))
                {
                    Interface.Oxide.UnloadPlugin(compilable_plugin.Name);
                }
            }
        }
예제 #18
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        public void LoadPlugins()
        {
            var log                = Factory.Singleton.Resolve <ILog>().Singleton;
            var manifestStorage    = Factory.Singleton.Resolve <IPluginManifestStorage>();
            var applicationVersion = Factory.Singleton.Resolve <IApplicationInformation>().Version;

            var rootFolder = Path.Combine(Provider.ApplicationStartupPath, "Plugins");

            if (Provider.DirectoryExists(rootFolder))
            {
                foreach (var subFolder in Provider.DirectoryGetDirectories(rootFolder))
                {
                    foreach (var dllFileName in Provider.DirectoryGetFiles(subFolder, "VirtualRadar.Plugin.*.dll"))
                    {
                        if (ManifestAllowsLoad(manifestStorage, applicationVersion, dllFileName))
                        {
                            try {
                                var pluginTypes = Provider.LoadTypes(dllFileName).Where(t => t.IsClass && typeof(IPlugin).IsAssignableFrom(t)).ToList();
                                if (pluginTypes.Count != 1)
                                {
                                    IgnoredPlugins.Add(dllFileName, Strings.PluginDoesNotHaveJustOneIPlugin);
                                    continue;
                                }

                                var pluginType = pluginTypes[0];
                                var plugin     = (IPlugin)Activator.CreateInstance(pluginType);
                                plugin.PluginFolder = subFolder;

                                var snapshot = Provider.ClassFactoryTakeSnapshot();
                                try {
                                    plugin.RegisterImplementations(Factory.Singleton);
                                    LoadedPlugins.Add(plugin);
                                } catch {
                                    Provider.ClassFactoryRestoreSnapshot(snapshot);
                                    throw;
                                }
                            } catch (Exception ex) {
                                var exceptionMessage = FormatException(ex);
                                Debug.WriteLine(String.Format("PluginManager.LoadPlugins caught exception: {0}", exceptionMessage));
                                log.WriteLine("Caught exception loading plugin {0}: {1}", dllFileName, exceptionMessage);

                                IgnoredPlugins.Add(dllFileName, String.Format(Strings.PluginCannotBeLoaded, ex.Message));
                            }
                        }
                    }
                }
            }
        }
예제 #19
0
        /// <inheritdoc />
        public override void OnDialogOpened(IDialogParameters parameters)
        {
            var title = parameters.GetValue <string>(LoadedPluginsDialogParameterNames.Title);

            if (title != null)
            {
                Title = title;
            }
            var loadedPlugins = parameters.GetValue <IEnumerable <PluginViewModel> >(LoadedPluginsDialogParameterNames.LoadedPlugins);

            if (loadedPlugins != null)
            {
                LoadedPlugins.Clear();
                LoadedPlugins.AddRange(loadedPlugins);
            }
        }
예제 #20
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        public void RegisterOwinMiddleware()
        {
            var log = Factory.ResolveSingleton <ILog>();

            foreach (var plugin in LoadedPlugins.ToArray())
            {
                if (plugin is IPlugin_V2 v2Plugin)
                {
                    try {
                        v2Plugin.RegisterOwinMiddleware();
                    } catch (Exception ex) {
                        log.WriteLine($"Caught exception registering web pipelines for plugin {v2Plugin.Name}: {FormatException(ex)}");
                    }
                }
            }
        }
예제 #21
0
        private void LoadPlugin(IPlugin plugin)
        {
            var savePlugin = $"{plugin.Name}_{plugin.Author}";

            if (LoadedPlugins.Contains(plugin))
            {
                LoadedPlugins.Remove(plugin);
                Options.Values.LoadedPlugins.Remove(savePlugin);
                Options.Values.Save();
                plugin.Unload();
                return;
            }
            LoadedPlugins.Add(plugin);
            Options.Values.LoadedPlugins.Add(savePlugin);
            Options.Values.Save();
            plugin.Load();
        }
예제 #22
0
        public void Load(CompilablePlugin plugin)
        {
            plugin.Compile(compiled =>
            {
                if (!compiled)
                {
                    PluginLoadingCompleted(plugin);
                    return;
                }

                var loadedLoadingRequirements = plugin.Requires.Where(r => LoadedPlugins.ContainsKey(r) && LoadingPlugins.Contains(r));
                foreach (var loadedPlugin in loadedLoadingRequirements)
                {
                    Interface.Oxide.UnloadPlugin(loadedPlugin);
                }

                var missingRequirements = plugin.Requires.Where(r => !LoadedPlugins.ContainsKey(r));
                if (missingRequirements.Any())
                {
                    var loadingRequirements = plugin.Requires.Where(r => LoadingPlugins.Contains(r));
                    if (loadingRequirements.Any())
                    {
                        Interface.Oxide.LogDebug($"{plugin.Name} plugin is waiting for requirements to be loaded: {loadingRequirements.ToSentence()}");
                    }
                    else
                    {
                        Interface.Oxide.LogError($"{plugin.Name} plugin requires missing dependencies: {missingRequirements.ToSentence()}");
                        PluginErrors[plugin.Name] = $"Missing dependencies: {missingRequirements.ToSentence()}";
                        PluginLoadingCompleted(plugin);
                    }
                }
                else
                {
                    Interface.Oxide.UnloadPlugin(plugin.Name);
                    plugin.LoadPlugin(pl =>
                    {
                        if (pl != null)
                        {
                            LoadedPlugins[pl.Name] = pl;
                        }
                        PluginLoadingCompleted(plugin);
                    });
                }
            });
        }
예제 #23
0
        public async Task SaveBoardPluginSetting(string boardKey, string pluginPath, JObject settings)
        {
            var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == pluginPath);

            if (plugin == null)
            {
                throw new InvalidOperationException("Not found plugin");
            }
            else if (!plugin.HasBoardSetting)
            {
                throw new InvalidOperationException("This plugin cannot has settings.");
            }
            var path     = GetPluginBoardSettingPath(boardKey, pluginPath);
            var saveTask = File.WriteAllTextAsync(path, settings.ToString());

            plugin.BoardSetting[boardKey] = settings.ToObject <object>();
            await saveTask;
        }
 private void ExportExistingVisits()
 {
     using (Client = CreateConnectedClient())
     {
         new Exporter
         {
             Context             = Context,
             Client              = Client,
             ReferencePointCache = ReferencePointCache,
             ParameterIdLookup   = ParameterIdLookup,
             MethodLookup        = MethodLookup,
             Plugins             = LoadedPlugins
                                   .Select(lp => lp.Plugin)
                                   .ToList(),
         }
         .Run();
     }
 }
예제 #25
0
        public void LoadPlugin(Assembly plugin, bool start = false)
        {
            if (plugin == null)
            {
                return;
            }
            var types = plugin.GetTypes();

            foreach (var pin in from type in types where !type.IsInterface && !type.IsAbstract where type.HasAbstract(typeof(Plugin)) select(Plugin) Activator.CreateInstance(type))
            {
                Logger.Info(string.Format("Loading Plugin - {0}(V -> {1})", pin.Name, pin.Version), "Plugin Engine");
                if (start)
                {
                    pin.Start();
                }
                LoadedPlugins.Add(pin);
                break;
            }
        }
예제 #26
0
        /// <summary>
        /// Called when the plugin manager is unloading a plugin that was loaded by this plugin loader
        /// </summary>
        /// <param name="pluginBase"></param>
        public override void Unloading(Plugin pluginBase)
        {
            CSharpPlugin plugin = pluginBase as CSharpPlugin;

            if (plugin == null)
            {
                return;
            }

            LoadedPlugins.Remove(plugin.Name);

            // Unload plugins which require this plugin first
            foreach (CompilablePlugin compilablePlugin in plugins.Values)
            {
                if (compilablePlugin.Requires.Contains(plugin.Name))
                {
                    Interface.Oxide.UnloadPlugin(compilablePlugin.Name);
                }
            }
        }
예제 #27
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        public void RegisterImplementations()
        {
            var log = Factory.ResolveSingleton <ILog>();

            foreach (var plugin in LoadedPlugins.ToArray())
            {
                var snapshot = Provider.ClassFactoryTakeSnapshot();
                try {
                    plugin.RegisterImplementations(Factory.Singleton);
                } catch (Exception ex) {
                    Provider.ClassFactoryRestoreSnapshot(snapshot);

                    var dllFileName = _PluginIDToFileNameMap[plugin.Id];
                    _PluginIDToFileNameMap.Remove(plugin.Id);
                    LoadedPlugins.Remove(plugin);
                    IgnoredPlugins.Add(dllFileName, String.Format(Strings.PluginCannotBeLoaded, ex.Message));
                    log.WriteLine("Caught exception loading plugin {0}: {1}", dllFileName, FormatException(ex));
                }
            }
        }
예제 #28
0
        public async void RunPlugins(PluginTypes types, Board board, Thread thread, Response response, Session session)
        {
            var targetPlugin = LoadedPlugins.Where(x => (x.PluginType & types) == types &&
                                                   x.IsEnabled &&
                                                   x.Valid &&
                                                   x.ActivatedBoards.Contains(board.BoardKey))
                               .OrderBy(x => x.Priority);

            foreach (var item in targetPlugin)
            {
                try
                {
                    await item.Script.RunAsync(new ZerochSharpPlugin(board, thread, response, types,
                                                                     item.BoardSetting?[board.BoardKey] as dynamic, session));
                }
                catch (CompilationErrorException ex)
                {
                    Console.WriteLine("Error in plugin running.");
                    Console.WriteLine(ex.Message);
                    var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == item.PluginPath);
                    if (plugin == null)
                    {
                        throw new InvalidOperationException();
                    }

                    plugin.Valid = false;
                    await SavePluginInfo();

                    Console.WriteLine($"Plugin {item.PluginName} is disabled.");
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("error in running plugin", e);
                }
            }
        }
예제 #29
0
        public bool LoadPlugins()
        {
            LoadedPlugins.Clear();
            foreach (string name in m_PluginNames)
            {
                IPlugin plugin = null;

                try
                {
                    plugin = (IPlugin)Activator.CreateInstance(Type.GetType(name));
                }
                catch (Exception)
                {
                    return(false);
                }

                if (plugin != null)
                {
                    LoadedPlugins.Add(plugin);
                }
            }

            return(true);
        }
예제 #30
0
 public static PluginModel Find(string key)
 {
     return(LoadedPlugins?.Find(p => p.Key == key));
 }