/// <summary> /// Initializes a new instance of the OxideMod class /// </summary> public void Load() { RootDirectory = Environment.CurrentDirectory; if (RootDirectory.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))) { RootDirectory = AppDomain.CurrentDomain.BaseDirectory; } Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Culture = CultureInfo.InvariantCulture }; // Create the commandline CommandLine = new CommandLine(Environment.GetCommandLineArgs()); // Load the config var oxideConfig = Path.Combine(RootDirectory, "oxide.config.json"); if (!File.Exists(oxideConfig)) { throw new FileNotFoundException("Could not load the Oxide configuration file", oxideConfig); } Config = ConfigFile.Load <OxideConfig>(oxideConfig); Config.Save(); // Work out the instance directory for (var i = 0; i < Config.InstanceCommandLines.Length; i++) { string varname, format; Config.GetInstanceCommandLineArg(i, out varname, out format); if (string.IsNullOrEmpty(varname) || CommandLine.HasVariable(varname)) { InstanceDirectory = Path.Combine(RootDirectory, Utility.CleanPath(string.Format(format, CommandLine.GetVariable(varname)))); break; } } if (InstanceDirectory == null) { throw new Exception("Could not identify instance directory"); } // Clean and set directory paths ExtensionDirectory = Path.Combine(RootDirectory, Utility.CleanPath(Config.ExtensionDirectory)); PluginDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("plugins")); DataDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("data")); LangDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("lang")); LogDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("logs")); ConfigDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath(Config.ConfigDirectory)); // Create directories if needed 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(LangDirectory)) { Directory.CreateDirectory(LangDirectory); } if (!Directory.Exists(LogDirectory)) { Directory.CreateDirectory(LogDirectory); } if (!Directory.Exists(ConfigDirectory)) { Directory.CreateDirectory(ConfigDirectory); } // Register the library path RegisterLibrarySearchPath(Path.Combine(ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")); // Set the default group DefaultGroup = Config.DefaultGroup; // Create the loggers RootLogger = new CompoundLogger(); RootLogger.AddLogger(new RotatingFileLogger { Directory = LogDirectory }); if (debugCallback != null) { RootLogger.AddLogger(new CallbackLogger(debugCallback)); } // Log Oxide core loading LogInfo("Loading Oxide Core v{0}...", Version); // Create the managers RootPluginManager = new PluginManager(RootLogger) { ConfigPath = ConfigDirectory }; extensionManager = new ExtensionManager(RootLogger); // Initialize other things DataFileSystem = new DataFileSystem(DataDirectory); // Register core libraries extensionManager.RegisterLibrary("Covalence", covalence = new Covalence()); extensionManager.RegisterLibrary("Global", new Global()); extensionManager.RegisterLibrary("Lang", new Lang()); extensionManager.RegisterLibrary("Permission", new Permission()); extensionManager.RegisterLibrary("Plugins", new Libraries.Plugins(RootPluginManager)); extensionManager.RegisterLibrary("Time", new Time()); extensionManager.RegisterLibrary("Timer", libtimer = new Timer()); extensionManager.RegisterLibrary("WebRequests", new WebRequests()); // Load all extensions LogInfo("Loading extensions..."); extensionManager.LoadAllExtensions(ExtensionDirectory); // Initialize covalence library after extensions (as it depends on things from within an ext) covalence.Initialize(); // Remove old files Cleanup.Add(Path.Combine(Interface.Oxide.RootDirectory, "oxide.root.json")); Cleanup.Run(); // If no clock has been defined, make our own unreliable clock if (getTimeSinceStartup == null) { timer = new Stopwatch(); timer.Start(); getTimeSinceStartup = () => (float)timer.Elapsed.TotalSeconds; LogWarning("A reliable clock is not available, falling back to a clock which may be unreliable on certain hardware"); } // Load all watchers foreach (var ext in extensionManager.GetAllExtensions()) { ext.LoadPluginWatchers(PluginDirectory); } // Load all plugins LogInfo("Loading plugins..."); LoadAllPlugins(true); // Hook all watchers foreach (var watcher in extensionManager.GetPluginChangeWatchers()) { watcher.OnPluginSourceChanged += watcher_OnPluginSourceChanged; watcher.OnPluginAdded += watcher_OnPluginAdded; watcher.OnPluginRemoved += watcher_OnPluginRemoved; } // Check for 'load' variable and warn if (CommandLine.HasVariable("load")) { LogWarning("The 'load' variable is unused and can be removed"); } // Check for 'nolog' variable and warn if (CommandLine.HasVariable("nolog")) { LogWarning("Usage of the 'nolog' variable will prevent logging"); } }
/// <summary> /// Initializes a new instance of the OxideMod class /// </summary> public void Load() { RootDirectory = Environment.CurrentDirectory; if (RootDirectory.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))) { RootDirectory = AppDomain.CurrentDomain.BaseDirectory; } if (RootDirectory == null) { throw new Exception("RootDirectory is null"); } InstanceDirectory = Path.Combine(RootDirectory, "oxide"); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Culture = CultureInfo.InvariantCulture }; CommandLine = new CommandLine(Environment.GetCommandLineArgs()); if (CommandLine.HasVariable("oxide.directory")) { CommandLine.GetArgument("oxide.directory", out string var, out string format); if (string.IsNullOrEmpty(var) || CommandLine.HasVariable(var)) { InstanceDirectory = Path.Combine(RootDirectory, Utility.CleanPath(string.Format(format, CommandLine.GetVariable(var)))); } } ExtensionDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (ExtensionDirectory == null || !Directory.Exists(ExtensionDirectory)) { throw new Exception("Could not identify extension directory"); } if (!Directory.Exists(InstanceDirectory)) { Directory.CreateDirectory(InstanceDirectory); } ConfigDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("config")); if (!Directory.Exists(ConfigDirectory)) { Directory.CreateDirectory(ConfigDirectory); } DataDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("data")); if (!Directory.Exists(DataDirectory)) { Directory.CreateDirectory(DataDirectory); } LangDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("lang")); if (!Directory.Exists(LangDirectory)) { Directory.CreateDirectory(LangDirectory); } LogDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("logs")); if (!Directory.Exists(LogDirectory)) { Directory.CreateDirectory(LogDirectory); } PluginDirectory = Path.Combine(InstanceDirectory, Utility.CleanPath("plugins")); if (!Directory.Exists(PluginDirectory)) { Directory.CreateDirectory(PluginDirectory); } RegisterLibrarySearchPath(Path.Combine(ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")); string config = Path.Combine(InstanceDirectory, "oxide.config.json"); if (File.Exists(config)) { Config = ConfigFile.Load <OxideConfig>(config); } else { Config = new OxideConfig(config); Config.Save(); } if (CommandLine.HasVariable("web.ip")) { Config.Options.WebRequestIP = CommandLine.GetVariable("web.ip"); } if (CommandLine.HasVariable("rcon.port")) { Config.Rcon.Port = Utility.GetNumbers(CommandLine.GetVariable("rcon.port")); } if (CommandLine.HasVariable("rcon.password")) { Config.Rcon.Password = CommandLine.GetVariable("rcon.password"); } RootLogger = new CompoundLogger(); RootLogger.AddLogger(new RotatingFileLogger { Directory = LogDirectory }); if (debugCallback != null) { RootLogger.AddLogger(new CallbackLogger(debugCallback)); } if (CommandLine.HasVariable("nolog")) { LogWarning("Usage of the 'nolog' variable will prevent logging"); } LogInfo("Loading Oxide Core v{0}...", Version); RootPluginManager = new PluginManager(RootLogger) { ConfigPath = ConfigDirectory }; extensionManager = new ExtensionManager(RootLogger); DataFileSystem = new DataFileSystem(DataDirectory); extensionManager.RegisterLibrary("Covalence", covalence = new Covalence()); extensionManager.RegisterLibrary("Global", new Global()); extensionManager.RegisterLibrary("Lang", new Lang()); extensionManager.RegisterLibrary("Permission", libperm = new Permission()); extensionManager.RegisterLibrary("Plugins", new Libraries.Plugins(RootPluginManager)); extensionManager.RegisterLibrary("Time", new Time()); extensionManager.RegisterLibrary("Timer", libtimer = new Timer()); extensionManager.RegisterLibrary("WebRequests", new WebRequests()); LogInfo("Loading extensions..."); extensionManager.LoadAllExtensions(ExtensionDirectory); Cleanup.Run(); covalence.Initialize(); RemoteConsole = new RemoteConsole.RemoteConsole(); RemoteConsole?.Initalize(); if (getTimeSinceStartup == null) { timer = new Stopwatch(); timer.Start(); getTimeSinceStartup = () => (float)timer.Elapsed.TotalSeconds; LogWarning("A reliable clock is not available, falling back to a clock which may be unreliable on certain hardware"); } foreach (Extension ext in extensionManager.GetAllExtensions()) { ext.LoadPluginWatchers(PluginDirectory); } LogInfo("Loading plugins..."); LoadAllPlugins(true); foreach (PluginChangeWatcher watcher in extensionManager.GetPluginChangeWatchers()) { watcher.OnPluginSourceChanged += watcher_OnPluginSourceChanged; watcher.OnPluginAdded += watcher_OnPluginAdded; watcher.OnPluginRemoved += watcher_OnPluginRemoved; } }
/// <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; } }
/// <summary> /// Initializes a new instance of the OxideMod class /// </summary> public void Load() { RootDirectory = Environment.CurrentDirectory; if (RootDirectory.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))) { RootDirectory = AppDomain.CurrentDomain.BaseDirectory; } // Create the commandline commandline = new CommandLine(Environment.GetCommandLineArgs()); // Load the config var oxideConfig = Path.Combine(RootDirectory, "oxide.root.json"); if (!File.Exists(oxideConfig)) { throw new FileNotFoundException("Could not load Oxide root configuration", oxideConfig); } rootconfig = ConfigFile.Load <OxideConfig>(oxideConfig); // 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(RootDirectory, CleanPath(string.Format(format, commandline.GetVariable(varname)))); break; } } if (InstanceDirectory == null) { throw new Exception("Could not identify instance directory"); } ExtensionDirectory = Path.Combine(RootDirectory, CleanPath(rootconfig.ExtensionDirectory)); PluginDirectory = Path.Combine(InstanceDirectory, CleanPath(rootconfig.PluginDirectory)); DataDirectory = Path.Combine(InstanceDirectory, CleanPath(rootconfig.DataDirectory)); LangDirectory = Path.Combine(InstanceDirectory, CleanPath(rootconfig.LangDirectory)); LogDirectory = Path.Combine(InstanceDirectory, CleanPath(rootconfig.LogDirectory)); ConfigDirectory = Path.Combine(InstanceDirectory, CleanPath(rootconfig.ConfigDirectory)); 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(LangDirectory)) { Directory.CreateDirectory(LangDirectory); } if (!Directory.Exists(LogDirectory)) { Directory.CreateDirectory(LogDirectory); } if (!Directory.Exists(ConfigDirectory)) { Directory.CreateDirectory(ConfigDirectory); } RegisterLibrarySearchPath(Path.Combine(ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")); // Create the loggers RootLogger = new CompoundLogger(); RootLogger.AddLogger(new RotatingFileLogger { Directory = LogDirectory }); if (debugCallback != null) { RootLogger.AddLogger(new CallbackLogger(debugCallback)); } // Log Oxide core loading LogInfo("Loading Oxide Core v{0}...", Version); // Create the managers RootPluginManager = new PluginManager(RootLogger) { ConfigPath = ConfigDirectory }; extensionmanager = new ExtensionManager(RootLogger); // Initialize other things DataFileSystem = new DataFileSystem(DataDirectory); // Register core libraries extensionmanager.RegisterLibrary("Global", new Global()); extensionmanager.RegisterLibrary("Time", new Time()); extensionmanager.RegisterLibrary("Timer", libtimer = new Timer()); extensionmanager.RegisterLibrary("Permission", new Permission()); extensionmanager.RegisterLibrary("Plugins", new Libraries.Plugins(RootPluginManager)); extensionmanager.RegisterLibrary("WebRequests", new WebRequests()); extensionmanager.RegisterLibrary("Lang", new Lang()); extensionmanager.RegisterLibrary("Covalence", covalence = new Covalence()); // Load all extensions LogInfo("Loading extensions..."); extensionmanager.LoadAllExtensions(ExtensionDirectory); // Remove old files Cleanup.Run(); // Initialize covalence library after extensions (as it depends on things from within an ext) covalence.Initialize(); // If no clock has been defined, make our own if (getTimeSinceStartup == null) { timer = new Stopwatch(); timer.Start(); getTimeSinceStartup = () => (float)timer.Elapsed.TotalSeconds; } // Load all watchers foreach (var ext in extensionmanager.GetAllExtensions()) { ext.LoadPluginWatchers(PluginDirectory); } // Load all plugins LogInfo("Loading plugins..."); LoadAllPlugins(); // Hook all watchers foreach (var watcher in extensionmanager.GetPluginChangeWatchers()) { watcher.OnPluginSourceChanged += watcher_OnPluginSourceChanged; watcher.OnPluginAdded += watcher_OnPluginAdded; watcher.OnPluginRemoved += watcher_OnPluginRemoved; } }