コード例 #1
0
        /// <summary>Loads the external tool's entry form.</summary>
        public IExternalToolForm LoadExternalToolForm(string toolPath, string customFormTypeName, bool focus = true)
        {
            var existingTool = _tools.OfType <IExternalToolForm>().FirstOrDefault(t => t.GetType().Assembly.Location == toolPath);

            if (existingTool != null)
            {
                if (!existingTool.IsDisposed)
                {
                    if (focus)
                    {
                        existingTool.Show();
                        existingTool.Focus();
                    }
                    return(existingTool);
                }
                _tools.Remove(existingTool);
            }

            var newTool = (IExternalToolForm)CreateInstance(typeof(IExternalToolForm), toolPath, customFormTypeName);

            if (newTool == null)
            {
                return(null);
            }
            if (newTool is Form form)
            {
                form.Owner = _owner;
            }
            ApiInjector.UpdateApis(_apiProvider, newTool);
            ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
            SetBaseProperties(newTool);
            // auto settings
            if (newTool is IToolFormAutoConfig autoConfigTool)
            {
                AttachSettingHooks(
                    autoConfigTool,
                    _config.CommonToolSettings.TryGetValue(customFormTypeName, out var settings)
                                                ? settings
                                                : (_config.CommonToolSettings[customFormTypeName] = new ToolDialogSettings())
                    );
            }
            // custom settings
            if (HasCustomConfig(newTool))
            {
                InstallCustomConfig(
                    newTool,
                    _config.CustomToolSettings.TryGetValue(customFormTypeName, out var settings)
                                                ? settings
                                                : (_config.CustomToolSettings[customFormTypeName] = new Dictionary <string, object>())
                    );
            }

            newTool.Restart();
            newTool.Show();
            return(newTool);
        }
コード例 #2
0
ファイル: ToolManager.cs プロジェクト: magicono43/BizHawk
        public void Restart()
        {
            // If Cheat tool is loaded, restarting will restart the list too anyway
            if (!GlobalWin.Tools.Has <Cheats>())
            {
                Global.CheatList.NewList(GenerateDefaultCheatFilename(), autosave: true);
            }

            var unavailable = new List <IToolForm>();

            foreach (var tool in _tools)
            {
                if (ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool.GetType()))
                {
                    ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, tool);

                    if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch)                     // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
                    {
                        if (tool is IExternalToolForm)
                        {
                            ApiInjector.UpdateApis(GlobalWin.ApiProvider, tool);
                        }
                        tool.Restart();
                    }
                }
                else
                {
                    unavailable.Add(tool);
                    ServiceInjector.ClearServices(tool);                     // the services of the old emulator core are no longer valid on the tool
                }
            }

            foreach (var tool in unavailable)
            {
                tool.Close();
                _tools.Remove(tool);
            }
        }
コード例 #3
0
ファイル: ToolManager.cs プロジェクト: magicono43/BizHawk
        /// <summary>
        /// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
        /// </summary>
        /// <typeparam name="T">Type of tool you want to load</typeparam>
        /// <param name="toolPath">Path to the .dll of the external tool</param>
        /// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
        /// <returns>An instantiated <see cref="IToolForm"/></returns>
        public T Load <T>(string toolPath, bool focus = true)
            where T : class, IToolForm
        {
            bool isExternal = typeof(T) == typeof(IExternalToolForm);

            if (!IsAvailable <T>() && !isExternal)
            {
                return(null);
            }

            T existingTool;

            if (isExternal)
            {
                existingTool = (T)_tools.FirstOrDefault(t => t is T && t.GetType().Assembly.Location == toolPath);
            }
            else
            {
                existingTool = (T)_tools.FirstOrDefault(t => t is T);
            }

            if (existingTool != null)
            {
                if (existingTool.IsDisposed)
                {
                    _tools.Remove(existingTool);
                }
                else
                {
                    if (focus)
                    {
                        existingTool.Show();
                        existingTool.Focus();
                    }

                    return(existingTool);
                }
            }

            IToolForm newTool = CreateInstance <T>(toolPath);

            if (newTool == null)
            {
                return(null);
            }

            if (newTool is Form)
            {
                (newTool as Form).Owner = GlobalWin.MainForm;
            }

            if (isExternal)
            {
                ApiInjector.UpdateApis(GlobalWin.ApiProvider, newTool);
            }

            ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool);
            string toolType = typeof(T).ToString();

            // auto settings
            if (newTool is IToolFormAutoConfig)
            {
                ToolDialogSettings settings;
                if (!Global.Config.CommonToolSettings.TryGetValue(toolType, out settings))
                {
                    settings = new ToolDialogSettings();
                    Global.Config.CommonToolSettings[toolType] = settings;
                }

                AttachSettingHooks(newTool as IToolFormAutoConfig, settings);
            }

            // custom settings
            if (HasCustomConfig(newTool))
            {
                if (!Global.Config.CustomToolSettings.TryGetValue(toolType, out var settings))
                {
                    settings = new Dictionary <string, object>();
                    Global.Config.CustomToolSettings[toolType] = settings;
                }

                InstallCustomConfig(newTool, settings);
            }

            newTool.Restart();
            if (!OSTailoredCode.IsWindows() && newTool is RamSearch)
            {
                // the mono winforms implementation is buggy, skip to the return statement and call Show in MainForm instead
            }
            else
            {
                newTool.Show();
            }
            return((T)newTool);
        }