示例#1
0
 public void EnableAutoSync(AutoSyncMode mode, bool enabled)
 {
     AutoSync &= ~mode;
     if (enabled)
     {
         AutoSync |= mode;
     }
 }
        public ConfigurationForm(PwObjectList <PwEntry> accounts, int idx, AutoSyncMode autoSync)
        {
            InitializeComponent();

            m_accounts = accounts;
            m_accidx   = idx >= 0 ? idx : -1;
            m_autoSync = autoSync;

            Visible = false;
        }
示例#3
0
 PluginConfig()
 {
     m_autoSync            = AutoSyncMode.DISABLED;
     m_enabledCmds         = SyncCommands.All;
     m_defaultFolder       = null;
     m_defaultFolderColor  = null;
     m_defaultDriveScope   = null;
     m_defaultClientId     = string.Empty;
     m_defaultClientSecret = GdsDefs.PsEmptyEx;
     m_isDirty             = false;
 }
示例#4
0
 PluginConfig()
 {
     m_autoSync            = AutoSyncMode.DISABLED;
     m_enabledCmds         = SyncCommands.All;
     m_defaultFolder       = null;
     m_defaultFolderColor  = null;
     m_defaultDriveScope   = null;
     m_defaultClientId     = string.Empty;
     m_defaultClientSecret = GdsDefs.PsEmptyEx;
     m_useLegacyCreds      = false;
     m_dontSaveAuthToken   = false;
     m_warnSavedAuthToken  = false;
     m_isDirty             = true;
     m_ver = null;
 }
示例#5
0
 PluginConfig(PluginConfig c)
 {
     m_autoSync            = c.m_autoSync;
     m_enabledCmds         = c.m_enabledCmds;
     m_defaultFolder       = c.m_defaultFolder;
     m_defaultFolderColor  = c.m_defaultFolderColor;
     m_defaultDriveScope   = c.m_defaultDriveScope;
     m_defaultClientId     = c.m_defaultClientId;
     m_defaultClientSecret = c.m_defaultClientSecret;
     m_useLegacyCreds      = c.m_useLegacyCreds;
     m_dontSaveAuthToken   = c.m_dontSaveAuthToken;
     m_warnSavedAuthToken  = c.m_warnSavedAuthToken;
     m_isDirty             = c.m_isDirty;
     m_ver            = c.m_ver;
     m_autoResumeSave = c.m_autoResumeSave;
 }
        private void btnOk_Click(object sender, EventArgs e)
        {
            string strUuid = txtUuid.Text.Trim().ToUpper();

            if (String.IsNullOrEmpty(strUuid))
            {
                DialogResult dlgr = MessageBox.Show("从 KeePass 配置中删除 Google 账户关联?", Defs.ProductName(), MessageBoxButtons.YesNoCancel);
                if (DialogResult.Yes != dlgr)
                {
                    DialogResult = DialogResult.None;
                }
                return;
            }

            if (!Regex.IsMatch(strUuid, "^[0-9A-F]{32}$"))
            {
                MessageBox.Show("输入的 UUID 无效!", Defs.ProductName());
                DialogResult = DialogResult.None;
                return;
            }

            if (chkOAuth.Checked && (String.IsNullOrEmpty(txtClientId.Text.Trim()) || String.IsNullOrEmpty(txtClientSecret.Text.Trim())))
            {
                MessageBox.Show("请为 " + Defs.ProductName() + " 输入有效的 Google OAuth 2.0 客户端ID和客户端密匙,或使用默认设置", Defs.ProductName());
                DialogResult = DialogResult.None;
                return;
            }

            m_uuid = strUuid;
            if (chkOAuth.Checked)
            {
                m_clientId     = txtClientId.Text.Trim();
                m_clientSecret = txtClientSecret.Text.Trim();
            }
            m_autoSync = (AutoSyncMode)cbAutoSync.SelectedIndex;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            string strUuid = txtUuid.Text.Trim().ToUpper();

            if (String.IsNullOrEmpty(strUuid))
            {
                DialogResult dlgr = MessageBox.Show("Remove Google Account association from KeePass config?", Defs.ProductName(), MessageBoxButtons.YesNoCancel);
                if (DialogResult.Yes != dlgr)
                {
                    DialogResult = DialogResult.None;
                }
                return;
            }

            if (!Regex.IsMatch(strUuid, "^[0-9A-F]{32}$"))
            {
                MessageBox.Show("The entered UUID is not valid.", Defs.ProductName());
                DialogResult = DialogResult.None;
                return;
            }

            if (chkOAuth.Checked && (String.IsNullOrEmpty(txtClientId.Text.Trim()) || String.IsNullOrEmpty(txtClientSecret.Text.Trim())))
            {
                MessageBox.Show("Please enter a valid custom Google OAuth 2.0 Client ID and Client Secrect for " + Defs.ProductName() + " or use default values.", Defs.ProductName());
                DialogResult = DialogResult.None;
                return;
            }

            m_uuid = strUuid;
            if (chkOAuth.Checked)
            {
                m_clientId     = txtClientId.Text.Trim();
                m_clientSecret = txtClientSecret.Text.Trim();
            }
            m_autoSync = (AutoSyncMode)cbAutoSync.SelectedIndex;
        }
示例#8
0
 public bool IsAutoSync(AutoSyncMode mode)
 {
     return(IsCmdEnabled(SyncCommands.SYNC) &&
            (AutoSync & mode) == mode);
 }
示例#9
0
        /// <summary>
        /// Show the configuration form
        /// </summary>
        private bool AskForConfiguration()
        {
            if (!m_host.Database.IsOpen)
            {
                return(false);
            }

            // find google accounts
            SearchParameters sp = new SearchParameters();

            sp.SearchString   = Defs.AccountSearchString;
            sp.ComparisonMode = StringComparison.OrdinalIgnoreCase;
            sp.RespectEntrySearchingDisabled = false;
            sp.SearchInGroupNames            = false;
            sp.SearchInNotes     = false;
            sp.SearchInOther     = false;
            sp.SearchInPasswords = false;
            sp.SearchInTags      = false;
            sp.SearchInTitles    = true;
            sp.SearchInUrls      = true;
            sp.SearchInUserNames = false;
            sp.SearchInUuids     = false;
            PwObjectList <PwEntry> accounts = new PwObjectList <PwEntry>();

            m_host.Database.RootGroup.SearchEntries(sp, accounts);

            // find the active account
            string  strUuid = null;
            PwEntry entry   = null;
            PwObjectList <PwEntry> activeAccounts = FindActiveAccounts();

            if (activeAccounts != null && activeAccounts.UCount == 1)
            {
                entry = activeAccounts.GetAt(0);
            }
            else
            {
                // alternatively try to find the active account in the config file (old configuration) (may be removed in later versions)
                strUuid = m_host.CustomConfig.GetString(Defs.ConfigUUID);
                try
                {
                    entry = m_host.Database.RootGroup.FindEntry(new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(strUuid)), true);
                }
                catch (ArgumentException) { }
            }

            // find configured entry in account list
            int idx = -1;

            if (entry != null)
            {
                idx = accounts.IndexOf(entry);
                // add configured entry to account list if not already present
                if (idx < 0)
                {
                    accounts.Insert(0, entry);
                    idx = 0;
                }
            }

            ConfigurationForm form1 = new ConfigurationForm(accounts, idx, m_autoSync);

            if (DialogResult.OK != UIUtil.ShowDialogAndDestroy(form1))
            {
                return(false);
            }

            entry   = null;
            strUuid = form1.Uuid;
            try
            {
                // will throw ArgumentException when Uuid is empty and association shall be removed
                entry = m_host.Database.RootGroup.FindEntry(new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(strUuid)), true);
            }
            catch (ArgumentException) { }

            if (entry == null && !String.IsNullOrEmpty(strUuid))
            {
                ShowMessage("没有找到 UUID:'" + strUuid + "' 关联密码");
                return(false);
            }

            m_entry        = entry;
            m_clientId     = form1.ClientId;
            m_clientSecret = new ProtectedString(true, form1.ClientSecrect);
            m_refreshToken = (m_entry != null) ? m_entry.Strings.Get(Defs.ConfigRefreshToken) : null;
            m_autoSync     = form1.AutoSync;

            return(true);
        }
示例#10
0
        /// <summary>
        /// The <c>Initialize</c> function is called by KeePass when
        /// you should initialize your plugin (create menu items, etc.).
        /// </summary>
        /// <param name="host">Plugin host interface. By using this
        /// interface, you can access the KeePass main window and the
        /// currently opened database.</param>
        /// <returns>You must return <c>true</c> in order to signal
        /// successful initialization. If you return <c>false</c>,
        /// KeePass unloads your plugin (without calling the
        /// <c>Terminate</c> function of your plugin).</returns>
        public override bool Initialize(IPluginHost host)
        {
            if (host == null)
            {
                return(false);
            }
            m_host = host;

            try
            {
                m_autoSync = (AutoSyncMode)Enum.Parse(typeof(AutoSyncMode), m_host.CustomConfig.GetString(Defs.ConfigAutoSync, AutoSyncMode.DISABLED.ToString()), true);
            }
            catch (Exception)
            {
                // support old boolean value (Sync on Save) (may be removed in later versions)
                if (m_host.CustomConfig.GetBool(Defs.ConfigAutoSync, false))
                {
                    m_autoSync = AutoSyncMode.SAVE;
                }
            }

            // Get a reference to the 'Tools' menu item container
            ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;

            // Add a separator at the bottom
            m_tsSeparator = new ToolStripSeparator();
            tsMenu.Add(m_tsSeparator);

            // Add the popup menu item
            m_tsmiPopup      = new ToolStripMenuItem();
            m_tsmiPopup.Text = Defs.ProductName();
            tsMenu.Add(m_tsmiPopup);

            m_tsmiSync        = new ToolStripMenuItem();
            m_tsmiSync.Name   = SyncCommand.SYNC.ToString();
            m_tsmiSync.Text   = "同步";
            m_tsmiSync.Click += OnSyncWithGoogle;
            m_tsmiPopup.DropDownItems.Add(m_tsmiSync);

            m_tsmiUpload        = new ToolStripMenuItem();
            m_tsmiUpload.Name   = SyncCommand.UPLOAD.ToString();
            m_tsmiUpload.Text   = "上传";
            m_tsmiUpload.Click += OnSyncWithGoogle;
            m_tsmiPopup.DropDownItems.Add(m_tsmiUpload);

            m_tsmiDownload        = new ToolStripMenuItem();
            m_tsmiDownload.Name   = SyncCommand.DOWNLOAD.ToString();
            m_tsmiDownload.Text   = "下载";
            m_tsmiDownload.Click += OnSyncWithGoogle;
            m_tsmiPopup.DropDownItems.Add(m_tsmiDownload);

            m_tsmiConfigure        = new ToolStripMenuItem();
            m_tsmiConfigure.Name   = "CONFIG";
            m_tsmiConfigure.Text   = "配置...";
            m_tsmiConfigure.Click += OnConfigure;
            m_tsmiPopup.DropDownItems.Add(m_tsmiConfigure);

            // We want a notification when the user tried to save the
            // current database or opened a new one.
            m_host.MainWindow.FileSaved  += OnFileSaved;
            m_host.MainWindow.FileOpened += OnFileOpened;

            return(true);            // Initialization successful
        }