Example #1
0
        public override bool Initialize(IPluginHost host)
        {
            Terminate();
            if (host == null)
            {
                return(false);
            }
            m_host = host;

            PluginTranslate.Init(this, Program.Translation.Properties.Iso6391Code);
            Tools.DefaultCaption = PluginTranslate.PluginName;
            Tools.PluginURL      = "https://github.com/rookiestyle/keepassotp/";

            var t = typeof(Program).Assembly.GetType("KeePass.Native.NativeMethods");

            try { m_miSetForegroundWindowEx = t.GetMethod("SetForegroundWindowEx", BindingFlags.Static | BindingFlags.NonPublic); } catch { }
            if (m_miSetForegroundWindowEx == null)
            {
                PluginDebug.AddError("Could not locate method 'SetForegroundEx'", 0);
            }

            try { m_miGetForegroundWindowHandle = t.GetMethod("GetForegroundWindowHandle", BindingFlags.Static | BindingFlags.NonPublic); } catch { }
            if (m_miGetForegroundWindowHandle == null)
            {
                PluginDebug.AddError("Could not locate method 'GetForegroundWindowHandle'", 0);
            }

            m_miAutoType = m_host.MainWindow.GetType().GetMethod("ExecuteGlobalAutoType", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null);
            if (m_miSetForegroundWindowEx == null)
            {
                PluginDebug.AddError("Could not locate method 'ExecuteGlobalAutoType'", 0);
            }

            CreateMenu();
            AddTray();

            Config.Init();

            m_columnOTP = new KeePassOTPColumnProvider();
            m_host.ColumnProviderPool.Add(m_columnOTP);
            m_columnOTP.StartTimer();

            SprEngine.FilterCompile += SprEngine_FilterCompile;
            SprEngine.FilterPlaceholderHints.Add(Config.Placeholder);

            TFASites.Init(false);
            OTPDAO.Init();
            PTHotKeyManager.HotKeyPressed += PTHotKeyManager_HotKeyPressed;
            m_host.MainWindow.FileOpened  += MainWindow_FileOpened;

            GlobalWindowManager.WindowAdded += GlobalWindowManager_WindowAdded;

            return(true);
        }