/// <summary> /// DO NOT USE INSIDE <see cref="IPlugin3.OnStop"/> or <see cref="IPlugin3.OnStart"/> METHODS! /// </summary> /// <param name="name"></param> public static void RemovePluginFromRunning(string name) { var plugin = PluginManagerEx.RunningPlugins.FirstOrDefault(l => l.Name == name); if (plugin != null) { PluginManagerEx.RemovePluginFromRunning(plugin); } }
/// <summary> /// Stops WoW plugin /// </summary> internal static void Unhook(int processID) { // cast 'PluginManagerEx.RunningPlugins' to array because we will get 'collection changed' exception otherwise foreach (var plugin in PluginManagerEx.RunningPlugins.Where(l => !l.DontCloseOnWowShutdown).ToArray()) { if (PluginManagerEx.PluginWoW[plugin.Name] == processID) { PluginManagerEx.RemovePluginFromRunning(plugin); } } }
/// <summary> /// DO NOT USE INSIDE <see cref="IPlugin3.OnStop"/> or <see cref="IPlugin3.OnStart"/> METHODS! /// </summary> /// <param name="callerPlugin"></param> /// <param name="name"></param> public static void AddPluginToRunning(this IPlugin3 callerPlugin, string name) { var plugin = PluginManagerEx.LoadedPlugins.FirstOrDefault(l => l.Name == name); if (plugin != null) { var activePlugin = PluginManagerEx.RunningPlugins.FirstOrDefault(l => l.Name == name); if (activePlugin == null && WoWProcessManager.Processes.TryGetValue(PluginManagerEx.PluginWoW[callerPlugin.Name], out WowProcess wow)) { PluginManagerEx.AddPluginToRunning(plugin, wow); } } }
private static void Main(string[] args) { UIThread = Thread.CurrentThread.ManagedThreadId; if (args.Length == 0) { if (Process.GetProcessesByName(nameof(AxTools)).Length > 1) { log.Info("Waiting for parent AxTools process (1000 ms)"); Thread.Sleep(1000); } using (new Mutex(true, "AxToolsMainExecutable", out bool newInstance)) { if (newInstance) { if (Environment.OSVersion.Version >= new Version(6, 1)) { using (WindowsIdentity p = WindowsIdentity.GetCurrent()) { var pricipal = new WindowsPrincipal(p); if (!pricipal.IsInRole(WindowsBuiltInRole.Administrator)) { TaskDialog.Show("This program requires administrator privileges", nameof(AxTools), "Make sure you have administrator privileges", TaskDialogButton.OK, TaskDialogIcon.SecurityError); return; } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WebRequest.DefaultWebProxy = null; DeleteTempFolder(); Legacy(); InstallRootCertificate(); log.Info("Adjusting process priorities..."); Utils.SetProcessPrioritiesToNormal(Process.GetCurrentProcess().Id); // in case we'are starting from Task Scheduler priorities can be lower than normal log.Info($"{typeof(WoWAntiKick)} is subscribing for {typeof(WoWProcessManager)}'s events"); WoWAntiKick.StartWaitForWoWProcesses(); log.Info($"Registered for: {Settings2.Instance.UserID}"); log.Info("Starting to load plugins..."); PluginManagerEx.LoadPluginsAsync(); log.Info("Starting WoW process manager..."); StartWoWProcessManagerTask = Task.Run((Action)WoWProcessManager.StartWatcher); log.Info("Looking for WoW client..."); WoWPathSearchTask = Task.Run((Action)CheckWoWDirectoryIsValid); log.Info("Starting add-ons backup service..."); Task.Run((Action)AddonsBackup.StartService); log.Info("Starting pinger..."); Task.Run(delegate { Pinger.Enabled = Settings2.Instance.PingerServerID != 0; }); log.Info("Starting updater service..."); Task.Run((Action)UpdaterService.Start); log.Info($"Constructing MainWindow, app version: {Globals.AppVersion}"); Application.Run(new MainWindow()); log.Info("MainWindow is closed, waiting for ShutdownLock..."); ShutdownLock.WaitForLocks(); log.Info($"Invoking 'Exit' handlers ({Exit?.GetInvocationList().Length})..."); Exit?.Invoke(); log.Info("Application is closed"); SendLogToDeveloper(); } else { MessageBox.Show("This program works only on Windows 7 or higher", nameof(AxTools), MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TaskDialog.Show("This program is already running", nameof(AxTools), "", TaskDialogButton.OK, TaskDialogIcon.Warning); } } } else { ProcessArgs(); } }