コード例 #1
0
ファイル: OxideMod.cs プロジェクト: kpoIIIkaeHo7/Oxide-2
        /// <summary>
        /// Scans for all available plugins and attempts to load them
        /// </summary>
        public void LoadAllPlugins()
        {
            // Get all plugin loaders, scan the plugin directory and load all reported plugins
            HashSet <Plugin> plugins = new HashSet <Plugin>();

            foreach (PluginLoader loader in extensionmanager.GetPluginLoaders())
            {
                foreach (string name in loader.ScanDirectory(plugindir))
                {
                    // Check if the plugin is already loaded
                    if (pluginmanager.GetPlugin(name) == null)
                    {
                        // Load it and watch for errors
                        try
                        {
                            Plugin plugin = loader.Load(plugindir, name);
                            plugin.OnError += plugin_OnError;
                            rootlogger.Write(LogType.Info, "Loaded plugin {0} (v{1}) by {2}", plugin.Title, plugin.Version, plugin.Author);
                            plugins.Add(plugin);
                        }
                        catch (Exception ex)
                        {
                            //rootlogger.Write(LogType.Error, "Failed to load plugin {0} ({1})", name, ex.Message);
                            //rootlogger.Write(LogType.Debug, ex.StackTrace);
                            rootlogger.WriteException(string.Format("Failed to load plugin {0}", name), ex);
                        }
                    }
                }
            }

            // Init all successfully loaded plugins
            foreach (Plugin plugin in plugins)
            {
                try
                {
                    pluginmanager.AddPlugin(plugin);
                }
                catch (Exception ex)
                {
                    //rootlogger.Write(LogType.Error, "Failed to initialise plugin {0} ({1})", plugin.Name, ex.Message);
                    //rootlogger.Write(LogType.Debug, ex.StackTrace);
                    rootlogger.WriteException(string.Format("Failed to initialise plugin {0}", plugin.Name), ex);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Logs a formatted message to the root logger
 /// </summary>
 /// <param name="format"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public void LogInfo(string format, params object[] args)
 {
     rootlogger.Write(LogType.Info, format, args);
 }
コード例 #3
0
        /// <summary>
        /// Initialises a new instance of the OxideMod class
        /// </summary>
        public void Load()
        {
            // Create the commandline
            commandline = new CommandLine(Environment.CommandLine);

            // Load the config
            if (!File.Exists("oxide.root.json"))
            {
                throw new FileNotFoundException("Could not load Oxide root configuration", "oxide.root.json");
            }
            rootconfig = ConfigFile.Load <OxideConfig>("oxide.root.json");

            // Work out the instance directory
            for (int i = 0; i < rootconfig.InstanceCommandLines.Length; i++)
            {
                string varname, format;
                rootconfig.GetInstanceCommandLineArg(i, out varname, out format);
                if (string.IsNullOrEmpty(varname) || commandline.HasVariable(varname))
                {
                    InstanceDirectory = Path.Combine(Environment.CurrentDirectory, string.Format(format, commandline.GetVariable(varname)));
                    break;
                }
            }
            if (InstanceDirectory == null)
            {
                throw new Exception("Could not identify instance directory");
            }
            ExtensionDirectory = Path.Combine(Environment.CurrentDirectory, rootconfig.ExtensionDirectory);
            PluginDirectory    = Path.Combine(InstanceDirectory, rootconfig.PluginDirectory);
            DataDirectory      = Path.Combine(InstanceDirectory, rootconfig.DataDirectory);
            LogDirectory       = Path.Combine(InstanceDirectory, rootconfig.LogDirectory);
            ConfigDirectory    = Path.Combine(InstanceDirectory, rootconfig.ConfigDirectory);
            TempDirectory      = Path.Combine(InstanceDirectory, rootconfig.TempDirectory);
            if (!Directory.Exists(ExtensionDirectory))
            {
                throw new Exception("Could not identify extension directory");
            }
            if (!Directory.Exists(InstanceDirectory))
            {
                Directory.CreateDirectory(InstanceDirectory);
            }
            if (!Directory.Exists(PluginDirectory))
            {
                Directory.CreateDirectory(PluginDirectory);
            }
            if (!Directory.Exists(DataDirectory))
            {
                Directory.CreateDirectory(DataDirectory);
            }
            if (!Directory.Exists(LogDirectory))
            {
                Directory.CreateDirectory(LogDirectory);
            }
            if (!Directory.Exists(ConfigDirectory))
            {
                Directory.CreateDirectory(ConfigDirectory);
            }
            if (!Directory.Exists(TempDirectory))
            {
                Directory.CreateDirectory(TempDirectory);
            }

            // Create the loggers
            filelogger           = new RotatingFileLogger();
            filelogger.Directory = LogDirectory;
            rootlogger           = new CompoundLogger();
            rootlogger.AddLogger(filelogger);

            // Log Oxide core loading
            rootlogger.Write(LogType.Info, "Loading Oxide core v{0}...", Version);

            // Create the managers
            pluginmanager = new PluginManager(rootlogger)
            {
                ConfigPath = ConfigDirectory
            };
            extensionmanager = new ExtensionManager(rootlogger);

            // Register core libraries
            libglobal = new Global();
            extensionmanager.RegisterLibrary("Global", libglobal);
            libtimer = new Timer();
            extensionmanager.RegisterLibrary("Timer", libtimer);
            libtime = new Time();
            extensionmanager.RegisterLibrary("Time", libtime);
            libplugins = new Libraries.Plugins(pluginmanager);
            extensionmanager.RegisterLibrary("Plugins", libplugins);
            libwebrequests = new WebRequests();
            extensionmanager.RegisterLibrary("WebRequests", libwebrequests);

            // Initialise other things
            DataFileSystem = new DataFileSystem(DataDirectory);

            // Load all extensions
            rootlogger.Write(LogType.Info, "Loading extensions...");
            extensionmanager.LoadAllExtensions(ExtensionDirectory);

            // Load all watchers
            foreach (Extension ext in extensionmanager.GetAllExtensions())
            {
                ext.LoadPluginWatchers(PluginDirectory);
            }

            // Load all plugins
            rootlogger.Write(LogType.Info, "Loading plugins...");
            LoadAllPlugins();

            // Hook all watchers
            foreach (PluginChangeWatcher watcher in extensionmanager.GetPluginChangeWatchers())
            {
                watcher.OnPluginSourceChanged += watcher_OnPluginSourceChanged;
                watcher.OnPluginAdded         += watcher_OnPluginAdded;
                watcher.OnPluginRemoved       += watcher_OnPluginRemoved;
            }
        }
コード例 #4
0
 public static void Info(string msg)
 {
     logger.Write(LogType.Info, msg);
 }