示例#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);
        }
示例#2
0
        private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
        {
            if (e.form.DialogResult != DialogResult.OK)
            {
                return;
            }
            bool    shown;
            Options options = (Options)Tools.GetPluginFromOptions(this, out shown);

            if (!shown)
            {
                return;
            }

            Dictionary <PwDatabase, Options.DBSettings> dDB = options.OTPDBSettings;

            foreach (KeyValuePair <PwDatabase, Options.DBSettings> kvp in dDB)
            {
                kvp.Key.UseDBForOTPSeeds(kvp.Value.UseOTPDB);
                kvp.Key.PreloadOTPDB(kvp.Value.Preload);
            }

            Config.CheckTFA = options.cgbCheckTFA.Checked;
            Config.Hotkey   = options.hkcKPOTP.HotKey;
            string sOldPlaceholder = Config.Placeholder;

            Config.KPOTPAutoSubmit = options.cbAutoSubmit.Checked;
            Config.Placeholder     = options.tbPlaceholder.Text;
            if ((sOldPlaceholder != Config.Placeholder) &&
                (Tools.AskYesNo(string.Format(PluginTranslate.MigratePlaceholder, sOldPlaceholder, Config.Placeholder)) == DialogResult.Yes))
            {
                MigratePlacholderInOpenDatabases(sOldPlaceholder, Config.Placeholder);
            }
            if (m_ContextMenuAutotype != null)
            {
                m_ContextMenuAutotype.Text = Config.Placeholder;
            }
            if (m_MainMenuAutotype != null)
            {
                m_MainMenuAutotype.Text = Config.Placeholder;
            }
            TFASites.Init(false);
        }