Ejemplo n.º 1
0
        public void Inject()
        {
            var context = _yukkuriContext;

            var ass = AppDomain.CurrentDomain.GetAssemblies()
                      .SingleOrDefault(assembly => assembly.GetName().Name == "ACT.TTSYukkuri.Core");

            if (context == null || context.YukkuriAssembly != ass)
            {
                context                  = new YukkuriContext(injector._plugin, ass);
                _yukkuriContext          = context;
                _originalYukkuriInstance = null;
            }

            lock (context.SpeechControllerLockObject)
            {
                var instance = context.SpeechControllerInstanceObject;
                if (instance == null || !(instance is IActLikeProxyInitialize))
                {
                    _originalYukkuriInstance = instance;
                    var myInterface = Impromptu.DynamicActLike(this, context.ISpeechControllerType);
                    _yukkuriContext.SpeechControllerInstanceObject = myInterface;
                    injector._plugin.Controller.NotifyLogMessageAppend(false, "TTSYukkuri injected!");
                }
            }
        }
Ejemplo n.º 2
0
        public void UnInject()
        {
            try
            {
                var c = _yukkuriContext;
                if (c != null)
                {
                    lock (c.SpeechControllerLockObject)
                    {
                        c.SpeechControllerInstanceObject = _originalYukkuriInstance;
                    }
                }
            }
            catch (Exception e)
            {
                injector._plugin.Controller.NotifyLogMessageAppend(false, e.ToString());
            }

            _yukkuriContext          = null;
            _originalYukkuriInstance = null;
        }
Ejemplo n.º 3
0
        public void UnInject()
        {
            try
            {
                var c = _yukkuriContext;
                if (c != null)
                {
                    lock (c.SpeechControllerLockObject)
                    {
                        c.SpeechControllerInstanceObject = _originalYukkuriInstance;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Failed to uninject YukkuriInjector", e);
            }

            _yukkuriContext          = null;
            _originalYukkuriInstance = null;
        }
Ejemplo n.º 4
0
        protected override void DoWork(FoxTTSPlugin context)
        {
            bool firstRun       = true;
            bool yukkuriEnabled = false;

            while (!WorkingThreadStopping)
            {
                bool longWait = true;
                try
                {
                    bool currentEnabled = false;
                    if (ActGlobals.oFormActMain.Visible)
                    {
                        foreach (var item in ActGlobals.oFormActMain.ActPlugins)
                        {
                            if (item.pluginFile.Name.ToUpper() == "ACT.TTSYukkuri.dll".ToUpper() &&
                                YUKKURI_INIT_SUCCESS.Contains(item.lblPluginStatus.Text.ToUpper()))
                            {
                                currentEnabled = true;
                                break;
                            }
                        }

                        if (currentEnabled)
                        {
                            var ass = AppDomain.CurrentDomain.GetAssemblies()
                                      .SingleOrDefault(assembly => assembly.GetName().Name == "ACT.TTSYukkuri.Core");
                            if (_yukkuriContext == null || _yukkuriContext.YukkuriAssembly != ass)
                            {
                                _yukkuriContext   = new YukkuriContext(ass);
                                _originalInstance = null;
                            }
                        }
                        else
                        {
                            UnInjectYukkuri();

                            longWait          = false;
                            _yukkuriContext   = null;
                            _originalInstance = null;
                        }

                        if (yukkuriEnabled != currentEnabled || firstRun)
                        {
                            yukkuriEnabled = currentEnabled;
                            firstRun       = false;

                            context.Controller.NotifyYukkuriEnabledChanged(false, yukkuriEnabled);
                            context.Controller.NotifyLogMessageAppend(false, $"yukkuriEnabled = {yukkuriEnabled}");
                        }

                        if (yukkuriEnabled)
                        {
                            InjectYukkuri();
                        }
                    }
                }
                catch (Exception e)
                {
                    context.Controller.NotifyLogMessageAppend(false, e.ToString());
                }

                SafeSleep(longWait ? 1000 : 100);
            }
        }