Пример #1
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Sign, KPRes.CreateMasterKey,
                                         m_ioInfo.GetDisplayName());
            this.Icon = AppIcons.Default;
            this.Text = KPRes.CreateMasterKey;

            FontUtil.SetDefaultFont(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            Bitmap bmpBig = SystemIcons.Warning.ToBitmap();

            m_imgAccWarning = GfxUtil.ScaleImage(bmpBig, DpiUtil.ScaleIntX(16),
                                                 DpiUtil.ScaleIntY(16), ScaleTransformFlags.UIIcon);
            bmpBig.Dispose();
            m_picAccWarning.Image = m_imgAccWarning;

            UIUtil.ConfigureToolTip(m_ttRect);
            // m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks);
            m_ttRect.SetToolTip(m_btnSaveKeyFile, KPRes.KeyFileCreate);
            m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileUseExisting);
            m_ttRect.SetToolTip(m_tbRepeatPassword, KPRes.PasswordRepeatHint);

            Debug.Assert(!m_lblIntro.AutoSize);             // For RTL support
            if (!m_bCreatingNew)
            {
                m_lblIntro.Text = KPRes.ChangeMasterKeyIntroShort;
            }

            m_icgPassword.Attach(m_tbPassword, m_cbHidePassword, m_lblRepeatPassword,
                                 m_tbRepeatPassword, m_lblEstimatedQuality, m_pbPasswordQuality,
                                 m_lblQualityInfo, m_ttRect, this, true, false);

            m_cmbKeyFile.Items.Add(KPRes.NoKeyFileSpecifiedMeta);
            foreach (KeyProvider prov in Program.KeyProviderPool)
            {
                m_cmbKeyFile.Items.Add(prov.Name);
            }

            m_cmbKeyFile.SelectedIndex = 0;

            m_cbPassword.Checked = true;
            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyCreationFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if (WinUtil.IsWindows9x || NativeLib.IsUnix())
            {
                UIUtil.SetChecked(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_lblWindowsAccDesc, false);
                UIUtil.SetEnabled(m_lblWindowsAccDesc2, false);
            }

            CustomizeForScreenReader();
            EnableUserControls();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Пример #2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_pwGroup == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }
            if (m_pwDatabase == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            string strTitle = (m_bCreatingNew ? KPRes.AddGroup : KPRes.EditGroup);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Folder_Txt, strTitle,
                                         (m_bCreatingNew ? KPRes.AddGroupDesc : KPRes.EditGroupDesc));
            this.Icon = AppIcons.Default;
            this.Text = strTitle;

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnIcon, KPRes.SelectIcon, true);
            UIUtil.SetToolTip(m_ttRect, m_btnAutoTypeEdit, KPRes.ConfigureKeystrokeSeq, true);

            UIUtil.AccSetName(m_dtExpires, m_cbExpires);
            UIUtil.AccSetName(m_tbDefaultAutoTypeSeq, m_rbAutoTypeOverride);

            m_tbName.Text = m_pwGroup.Name;

            m_pwIconIndex    = m_pwGroup.IconId;
            m_pwCustomIconID = m_pwGroup.CustomIconUuid;

            if (!m_pwCustomIconID.Equals(PwUuid.Zero))
            {
                UIUtil.SetButtonImage(m_btnIcon, DpiUtil.GetIcon(
                                          m_pwDatabase, m_pwCustomIconID), true);
            }
            else
            {
                UIUtil.SetButtonImage(m_btnIcon, m_ilClientIcons.Images[
                                          (int)m_pwIconIndex], true);
            }

            UIUtil.SetMultilineText(m_tbNotes, m_pwGroup.Notes);

            if (m_pwGroup.Expires)
            {
                m_dtExpires.Value   = TimeUtil.ToLocal(m_pwGroup.ExpiryTime, true);
                m_cbExpires.Checked = true;
            }
            else             // Does not expire
            {
                m_dtExpires.Value   = DateTime.Now.Date;
                m_cbExpires.Checked = false;
            }
            m_cgExpiry.Attach(m_cbExpires, m_dtExpires);

            TagUtil.MakeInheritedTagsLink(m_linkTagsInh, m_pwGroup.ParentGroup, this);
            m_tbTags.Text = StrUtil.TagsToString(m_pwGroup.Tags, true);
            TagUtil.MakeTagsButton(m_btnTags, m_tbTags, m_ttRect, m_pwGroup.ParentGroup,
                                   ((m_pwDatabase != null) ? m_pwDatabase.RootGroup : null));

            m_tbUuid.Text = m_pwGroup.Uuid.ToHexString() + ", " +
                            Convert.ToBase64String(m_pwGroup.Uuid.UuidBytes);

            PwGroup pgParent = m_pwGroup.ParentGroup;

            bool bParentSearching = ((pgParent != null) ?
                                     pgParent.GetSearchingEnabledInherited() :
                                     PwGroup.DefaultSearchingEnabled);

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableSearching,
                                               m_pwGroup.EnableSearching, bParentSearching);

            bool bParentAutoType = ((pgParent != null) ?
                                    pgParent.GetAutoTypeEnabledInherited() :
                                    PwGroup.DefaultAutoTypeEnabled);

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableAutoType,
                                               m_pwGroup.EnableAutoType, bParentAutoType);

            m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

            if (m_pwGroup.DefaultAutoTypeSequence.Length == 0)
            {
                m_rbAutoTypeInherit.Checked = true;
            }
            else
            {
                m_rbAutoTypeOverride.Checked = true;
            }

            UIUtil.SetButtonImage(m_btnAutoTypeEdit,
                                  Properties.Resources.B16x16_Wizard, true);

            m_sdCustomData = m_pwGroup.CustomData.CloneDeep();
            UIUtil.StrDictListInit(m_lvCustomData);
            UIUtil.StrDictListUpdate(m_lvCustomData, m_sdCustomData, false);

            EnableControlsEx();

            ThreadPool.QueueUserWorkItem(delegate(object state)
            {
                try
                {
                    string[] vSeq = m_pwDatabase.RootGroup.GetAutoTypeSequences(true);
                    // Do not append, because long suggestions hide the start
                    UIUtil.EnableAutoCompletion(m_tbDefaultAutoTypeSeq,
                                                false, vSeq); // Invokes
                }
                catch (Exception) { Debug.Assert(false); }
            });

            UIUtil.SetFocus(m_tbName, this);

            switch (m_gftInit)
            {
            case GroupFormTab.Properties:
                m_tabMain.SelectedTab = m_tabProperties; break;

            case GroupFormTab.AutoType:
                m_tabMain.SelectedTab = m_tabAutoType; break;

            case GroupFormTab.CustomData:
                m_tabMain.SelectedTab = m_tabCustomData; break;

            default: break;
            }
        }
Пример #3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = WinUtil.CompactPath(m_ioInfo.Path, 45);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            FontUtil.SetDefaultFont(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            // m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks);
            m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileSelect);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strNameEx = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strNameEx))
            {
                this.Text = strStart + " - " + strNameEx;
            }
            else
            {
                this.Text = strStart;
            }

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.ProcessTextChangedPassword;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileSuggPriv(KPRes.NoKeyFileSpecifiedMeta, true);

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if ((strCmdLineFile != null) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if ((strCmdLineFile != null) && strCmdLineFile.Equals(m_ioInfo.Path,
                                                                  StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }
            }

            m_cbHidePassword.Checked = true;
            OnCheckedHidePassword(sender, e);

            Debug.Assert(m_cmbKeyFile.Text.Length != 0);

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            ulong uKpf = Program.Config.UI.KeyPromptFlags;

            UIUtil.ApplyKeyUIFlags(uKpf, m_cbPassword, m_cbKeyFile,
                                   m_cbUserAccount, m_cbHidePassword);

            if ((uKpf & (ulong)AceKeyUIFlags.DisableKeyFile) != 0)
            {
                UIUtil.SetEnabled(m_cmbKeyFile, m_cbKeyFile.Checked);
                UIUtil.SetEnabled(m_btnOpenKeyFile, m_cbKeyFile.Checked);
            }

            if (((uKpf & (ulong)AceKeyUIFlags.CheckPassword) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckPassword) != 0))
            {
                m_bPwStatePreset = true;
            }
            if (((uKpf & (ulong)AceKeyUIFlags.CheckUserAccount) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckUserAccount) != 0))
            {
                m_bUaStatePreset = true;
            }

            CustomizeForScreenReader();
            EnableUserControls();

            m_bInitializing = false;

            // E.g. command line options have higher priority
            m_bCanModKeyFile = (m_cmbKeyFile.SelectedIndex == 0);

            m_aKeyAssoc = Program.Config.Defaults.GetKeySources(m_ioInfo);
            if (m_aKeyAssoc != null)
            {
                if (m_aKeyAssoc.Password && !m_bPwStatePreset)
                {
                    m_cbPassword.Checked = true;
                }

                if (m_aKeyAssoc.KeyFilePath.Length > 0)
                {
                    AddKeyFileSuggPriv(m_aKeyAssoc.KeyFilePath, null);
                }

                if (m_aKeyAssoc.UserAccount && !m_bUaStatePreset)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider prov in Program.KeyProviderPool)
            {
                AddKeyFileSuggPriv(prov.Name, null);
            }

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.AsyncFormLoad));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.AsyncFormLoad));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Пример #4
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pwDatabase != null); if (m_pwDatabase == null)
            {
                throw new InvalidOperationException();
            }

            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);

            IOConnectionInfo ioc     = m_pwDatabase.IOConnectionInfo;
            string           strDisp = ioc.GetDisplayName();

            string strDesc = KPRes.DatabaseSettingsDesc;

            if (!string.IsNullOrEmpty(strDisp))
            {
                strDesc = strDisp;
            }

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Ark, KPRes.DatabaseSettings, strDesc);
            this.Icon = AppIcons.Default;

            FontUtil.AssignDefaultItalic(m_lblHeaderCpAlgo);
            FontUtil.AssignDefaultItalic(m_lblHeaderCp);
            FontUtil.AssignDefaultItalic(m_lblHeaderPerf);

            FontUtil.AssignDefaultBold(m_rbNone);
            FontUtil.AssignDefaultBold(m_rbGZip);

            UIUtil.ConfigureToolTip(m_ttRect);
            m_ttRect.SetToolTip(m_btnKdf1Sec, KPRes.KdfParams1Sec);

            m_tbDbName.PromptText = KPRes.DatabaseNamePrompt;
            m_tbDbDesc.PromptText = KPRes.DatabaseDescPrompt;

            if (m_bCreatingNew)
            {
                this.Text = KPRes.ConfigureOnNewDatabase2;
            }
            else
            {
                this.Text = KPRes.DatabaseSettings;
            }

            m_tbDbName.Text = m_pwDatabase.Name;
            UIUtil.SetMultilineText(m_tbDbDesc, m_pwDatabase.Description);
            m_tbDefaultUser.Text = m_pwDatabase.DefaultUserName;

            m_clr = m_pwDatabase.Color;
            if (m_clr != Color.Empty)
            {
                m_clr = AppIcons.RoundColor(m_clr);
                UIUtil.OverwriteButtonImage(m_btnColor, ref m_imgColor,
                                            UIUtil.CreateColorBitmap24(m_btnColor, m_clr));
            }
            m_cbColor.Checked = (m_clr != Color.Empty);

            for (int inx = 0; inx < CipherPool.GlobalPool.EngineCount; ++inx)
            {
                m_cmbEncAlgo.Items.Add(CipherPool.GlobalPool[inx].DisplayName);
            }

            if (m_cmbEncAlgo.Items.Count > 0)
            {
                int nIndex = CipherPool.GlobalPool.GetCipherIndex(m_pwDatabase.DataCipherUuid);
                m_cmbEncAlgo.SelectedIndex = ((nIndex >= 0) ? nIndex : 0);
            }

            Debug.Assert(m_cmbKdf.Items.Count == 0);
            foreach (KdfEngine kdf in KdfPool.Engines)
            {
                m_cmbKdf.Items.Add(kdf.Name);
            }

            m_numKdfIt.Minimum = ulong.MinValue;
            m_numKdfIt.Maximum = ulong.MaxValue;

            m_numKdfMem.Minimum = ulong.MinValue;
            m_numKdfMem.Maximum = ulong.MaxValue;

            Debug.Assert(m_cmbKdfMem.Items.Count == 0);
            Debug.Assert(!m_cmbKdfMem.Sorted);
            m_cmbKdfMem.Items.Add("B");
            m_cmbKdfMem.Items.Add("KB");
            m_cmbKdfMem.Items.Add("MB");
            m_cmbKdfMem.Items.Add("GB");

            m_numKdfPar.Minimum = uint.MinValue;
            m_numKdfPar.Maximum = uint.MaxValue;

            SetKdfParameters(m_pwDatabase.KdfParameters);

            // m_lbMemProt.Items.Add(KPRes.Title, m_pwDatabase.MemoryProtection.ProtectTitle);
            // m_lbMemProt.Items.Add(KPRes.UserName, m_pwDatabase.MemoryProtection.ProtectUserName);
            // m_lbMemProt.Items.Add(KPRes.Password, m_pwDatabase.MemoryProtection.ProtectPassword);
            // m_lbMemProt.Items.Add(KPRes.Url, m_pwDatabase.MemoryProtection.ProtectUrl);
            // m_lbMemProt.Items.Add(KPRes.Notes, m_pwDatabase.MemoryProtection.ProtectNotes);

            // m_cbAutoEnableHiding.Checked = m_pwDatabase.MemoryProtection.AutoEnableVisualHiding;
            // m_cbAutoEnableHiding.Checked = false;

            if (m_pwDatabase.Compression == PwCompressionAlgorithm.None)
            {
                m_rbNone.Checked = true;
            }
            else if (m_pwDatabase.Compression == PwCompressionAlgorithm.GZip)
            {
                m_rbGZip.Checked = true;
            }
            else
            {
                Debug.Assert(false);
            }

            InitRecycleBinTab();
            InitAdvancedTab();

            m_bInitializing = false;
            EnableControlsEx();
            UIUtil.SetFocus(m_tbDbName, this);
        }
Пример #5
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_tbPassword.TabIndex >= 2) && !m_tbPassword.Focused);

            GlobalWindowManager.AddWindow(this);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Sign, KPRes.CreateMasterKey,
                                         m_ioInfo.GetDisplayName());
            this.Icon = AppIcons.Default;
            this.Text = KPRes.CreateMasterKey;

            FontUtil.SetDefaultFont(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            m_imgKeyFileWarning = UIUtil.IconToBitmap(SystemIcons.Warning,
                                                      DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16));
            m_imgAccWarning           = (Image)m_imgKeyFileWarning.Clone();
            m_picKeyFileWarning.Image = m_imgKeyFileWarning;
            m_picAccWarning.Image     = m_imgAccWarning;

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_tbRepeatPassword, KPRes.PasswordRepeatHint, false);
            UIUtil.SetToolTip(m_ttRect, m_btnSaveKeyFile, KPRes.KeyFileCreate, false);
            UIUtil.SetToolTip(m_ttRect, m_btnOpenKeyFile, KPRes.KeyFileUseExisting, false);

            UIUtil.AccSetName(m_tbPassword, m_cbPassword);
            UIUtil.AccSetName(m_cmbKeyFile, m_cbKeyFile);
            UIUtil.AccSetName(m_picKeyFileWarning, KPRes.Warning);
            UIUtil.AccSetName(m_picAccWarning, KPRes.Warning);

            Debug.Assert(!m_lblIntro.AutoSize);             // For RTL support
            if (!m_bCreatingNew)
            {
                m_lblIntro.Text = KPRes.ChangeMasterKeyIntroShort;
            }

            m_icgPassword.Attach(m_tbPassword, m_cbHidePassword, m_lblRepeatPassword,
                                 m_tbRepeatPassword, m_lblEstimatedQuality, m_pbPasswordQuality,
                                 m_lblQualityInfo, m_ttRect, this, true, false);

            m_cmbKeyFile.Items.Add(KPRes.NoKeyFileSpecifiedMeta);
            foreach (KeyProvider prov in Program.KeyProviderPool)
            {
                m_cmbKeyFile.Items.Add(prov.Name);
            }

            m_cmbKeyFile.SelectedIndex = 0;

            m_cbPassword.Checked = true;
            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyCreationFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if (WinUtil.IsWindows9x || NativeLib.IsUnix())
            {
                UIUtil.SetChecked(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_lblWindowsAccDesc, false);
                UIUtil.SetEnabled(m_lblWindowsAccDesc2, false);
            }

            EnableUserControls();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Пример #6
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_pgRoot == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            string strTitle = KPRes.SearchTitle;
            string strDesc  = KPRes.SearchDesc2;

            if ((m_pgRoot.ParentGroup != null) && !string.IsNullOrEmpty(m_pgRoot.Name))
            {
                strTitle += " (" + KPRes.SelectedGroup + ")";
                strDesc   = KPRes.Group + ": '" + m_pgRoot.Name + "'.";
            }

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_XMag, strTitle, strDesc);
            this.Icon = AppIcons.Default;
            this.Text = KPRes.SearchTitle;

            UIUtil.SetButtonImage(m_btnProfileAdd,
                                  Properties.Resources.B16x16_FileSaveAs, false);
            UIUtil.SetButtonImage(m_btnProfileDelete,
                                  Properties.Resources.B16x16_EditDelete, true);

            UIUtil.SetText(m_cbDerefData, m_cbDerefData.Text + " (" + KPRes.Slow + ")");

            UIUtil.ConfigureToolTip(m_ttMain);
            UIUtil.SetToolTip(m_ttMain, m_btnProfileAdd, KPRes.ProfileSaveDesc, false);
            UIUtil.SetToolTip(m_ttMain, m_btnProfileDelete, KPRes.ProfileDeleteDesc, false);

            UIUtil.AccSetName(m_btnProfileAdd, KPRes.ProfileSave);
            UIUtil.AccSetName(m_btnProfileDelete, KPRes.ProfileDelete);

            SearchParameters sp = (!string.IsNullOrEmpty(m_strInitProfile) ?
                                   Program.Config.Search.FindProfile(m_strInitProfile) : null);

            Debug.Assert(string.IsNullOrEmpty(m_strInitProfile) || (sp != null));
            UpdateProfilesList((sp != null) ? sp.Name : ProfileCustom);
            SetSearchParameters(sp ?? Program.Config.Search.LastUsedProfile);

            m_tbSearch.TextChanged         += this.OnProfilePropertyChanged;
            m_rbModeSimple.CheckedChanged  += this.OnProfilePropertyChanged;
            m_rbModeRegular.CheckedChanged += this.OnProfilePropertyChanged;
            m_rbModeXPath.CheckedChanged   += this.OnProfilePropertyChanged;

            CheckBox[] v = new CheckBox[] {
                m_cbTitle, m_cbUserName, m_cbPassword, m_cbUrl, m_cbNotes,
                m_cbStringsOther, m_cbStringName, m_cbTags, m_cbUuid,
                m_cbGroupPath, m_cbGroupName, m_cbHistory,
                m_cbCaseSensitive, m_cbExcludeExpired, m_cbIgnoreGroupSettings,
                m_cbDerefData
            };
            foreach (CheckBox cb in v)
            {
                cb.CheckedChanged += this.OnProfilePropertyChanged;
            }

            UpdateUIState();
            m_tbSearch.SelectAll();
        }
Пример #7
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            // Can be invoked by tray command; don't use CenterParent
            Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen);

            ++m_uBlockUIUpdate;

            GlobalWindowManager.AddWindow(this);

            m_strAdvControlText = m_tabAdvanced.Text;

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Gen, KPRes.PasswordOptions,
                                         KPRes.PasswordOptionsDesc);
            this.Icon = AppIcons.Default;

            UIUtil.SetButtonImage(m_btnProfileAdd,
                                  Properties.Resources.B16x16_FileSaveAs, false);
            UIUtil.SetButtonImage(m_btnProfileRemove,
                                  Properties.Resources.B16x16_EditDelete, true);

            FontUtil.AssignDefaultBold(m_rbStandardCharSet);
            FontUtil.AssignDefaultBold(m_rbPattern);
            FontUtil.AssignDefaultBold(m_rbCustom);
            FontUtil.AssignDefaultMono(m_tbPreview, true);

            UIUtil.ConfigureToolTip(m_ttMain);
            UIUtil.SetToolTip(m_ttMain, m_btnProfileAdd, KPRes.ProfileSaveDesc, false);
            UIUtil.SetToolTip(m_ttMain, m_btnProfileRemove, KPRes.ProfileDeleteDesc, false);
            UIUtil.SetToolTip(m_ttMain, m_btnCustomOpt, KPRes.Options, true);

            UIUtil.AccSetName(m_btnProfileAdd, KPRes.ProfileSave);
            UIUtil.AccSetName(m_btnProfileRemove, KPRes.ProfileDelete);

            using (RtlAwareResizeScope r = new RtlAwareResizeScope(
                       m_cbUpperCase, m_cbLowerCase, m_cbDigits, m_cbMinus,
                       m_cbUnderline, m_cbSpace, m_cbSpecial, m_cbBrackets,
                       m_cbLatin1S, m_cbNoRepeat, m_cbExcludeLookAlike,
                       m_lblExcludeChars, m_lblSecRedInfo))
            {
                m_cbUpperCase.Text        += " (A, B, C, ...)";
                m_cbLowerCase.Text        += " (a, b, c, ...)";
                m_cbDigits.Text           += " (0, 1, 2, ...)";
                m_cbMinus.Text            += " (-)";
                m_cbUnderline.Text        += " (_)";
                m_cbSpace.Text            += " ( )";
                m_cbSpecial.Text          += @" (!, $, %, &&, ...)";
                m_cbBrackets.Text         += @" ([, ], {, }, (, ), <, >)";
                m_cbLatin1S.Text          += " (\u00C4, \u00B5, \u00B6, ...)";
                m_cbNoRepeat.Text         += " *";
                m_cbExcludeLookAlike.Text += " (l|1I, O0) *";
                m_lblExcludeChars.Text    += " *";
                m_lblSecRedInfo.Text       = "* " + m_lblSecRedInfo.Text;
            }

            SetCharSetTT(m_cbUpperCase, PwCharSet.UpperCase, 2);
            SetCharSetTT(m_cbLowerCase, PwCharSet.LowerCase, 2);
            SetCharSetTT(m_cbDigits, PwCharSet.Digits, 2);
            SetCharSetTT(m_cbSpecial, PwCharSet.Special, 2);
            SetCharSetTT(m_cbLatin1S, PwCharSet.Latin1S, 4);

            m_cmbCustomAlgo.Items.Add(NoCustomAlgo);
            foreach (CustomPwGenerator pwg in Program.PwGeneratorPool)
            {
                m_cmbCustomAlgo.Items.Add(pwg.Name);
            }
            SelectCustomGenerator((m_optInitial != null) ?
                                  m_optInitial.CustomAlgorithmUuid : null, null);
            if (m_optInitial != null)
            {
                CustomPwGenerator pwg = GetPwGenerator();
                if (pwg != null)
                {
                    m_dictCustomOptions[pwg] = m_optInitial.CustomAlgorithmOptions;
                }
            }

            m_cmbProfiles.Items.Add(CustomMeta);

            if (m_optInitial != null)
            {
                m_cmbProfiles.Items.Add(DeriveFromPrevious);
                SetGenerationOptions(m_optInitial);
            }

            m_rbStandardCharSet.CheckedChanged   += this.UpdateUIProc;
            m_rbPattern.CheckedChanged           += this.UpdateUIProc;
            m_rbCustom.CheckedChanged            += this.UpdateUIProc;
            m_numGenChars.ValueChanged           += this.UpdateUIProc;
            m_cbUpperCase.CheckedChanged         += this.UpdateUIProc;
            m_cbLowerCase.CheckedChanged         += this.UpdateUIProc;
            m_cbDigits.CheckedChanged            += this.UpdateUIProc;
            m_cbMinus.CheckedChanged             += this.UpdateUIProc;
            m_cbUnderline.CheckedChanged         += this.UpdateUIProc;
            m_cbSpace.CheckedChanged             += this.UpdateUIProc;
            m_cbSpecial.CheckedChanged           += this.UpdateUIProc;
            m_cbBrackets.CheckedChanged          += this.UpdateUIProc;
            m_cbLatin1S.CheckedChanged           += this.UpdateUIProc;
            m_tbCustomChars.TextChanged          += this.UpdateUIProc;
            m_tbPattern.TextChanged              += this.UpdateUIProc;
            m_cbPatternPermute.CheckedChanged    += this.UpdateUIProc;
            m_cbNoRepeat.CheckedChanged          += this.UpdateUIProc;
            m_cbExcludeLookAlike.CheckedChanged  += this.UpdateUIProc;
            m_tbExcludeChars.TextChanged         += this.UpdateUIProc;
            m_cmbCustomAlgo.SelectedIndexChanged += this.UpdateUIProc;

            m_cmbProfiles.Items.Add(AutoGeneratedMeta);

            m_cmbProfiles.SelectedIndex = ((m_optInitial == null) ? 0 : 1);

            foreach (PwProfile ppw in PwGeneratorUtil.GetAllProfiles(true))
            {
                m_cmbProfiles.Items.Add(ppw.Name);

                if ((ppw.GeneratorType == PasswordGeneratorType.Custom) &&
                    !string.IsNullOrEmpty(ppw.CustomAlgorithmUuid))
                {
                    CustomPwGenerator pwg = Program.PwGeneratorPool.Find(new
                                                                         PwUuid(Convert.FromBase64String(ppw.CustomAlgorithmUuid)));
                    if (pwg != null)
                    {
                        m_dictCustomOptions[pwg] = ppw.CustomAlgorithmOptions;
                    }
                }
            }

            if (m_optInitial == null)
            {
                // int nIndex = m_cmbProfiles.FindString(Program.Config.PasswordGenerator.LastUsedProfile.Name);
                // if(nIndex >= 0) m_cmbProfiles.SelectedIndex = nIndex;
                SetGenerationOptions(Program.Config.PasswordGenerator.LastUsedProfile);
            }

            if (!m_bCanAccept)
            {
                m_btnOK.Visible  = false;
                m_btnCancel.Text = KPRes.Close;

                m_tabPreview.Text    = KPRes.Generate;
                m_lblPreview.Visible = false;
                UIUtil.SetChecked(m_cbEntropy, false);
                m_cbEntropy.Enabled = false;
            }

            // Debug.Assert(this.ShowInTaskbar == false);
            // if(m_bForceInTaskbar) this.ShowInTaskbar = true;

            --m_uBlockUIUpdate;
            EnableControlsEx(false);
        }
Пример #8
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if ((m_pd == null) && (m_pg == null))
            {
                Debug.Assert(false);
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            string strTitle = (m_bExport ? KPRes.ExportFileTitle : KPRes.ImportFileTitle);
            string strDesc  = (m_bExport ? KPRes.ExportFileDesc : KPRes.ImportFileDesc);
            Image  img      = (m_bExport ? Properties.Resources.B48x48_Folder_Txt :
                               Properties.Resources.B48x48_Folder_Download);

            BannerFactory.CreateBannerEx(this, m_bannerImage, img, strTitle, strDesc);

            this.Icon = AppIcons.Default;
            this.Text = strTitle;

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnSelFile, StrUtil.TrimDots(
                                  KPRes.SelectFile, true), true);

            m_lvFormats.ShowGroups = true;

            int w = m_lvFormats.ClientSize.Width - UIUtil.GetVScrollBarWidth();

            m_lvFormats.Columns.Add(string.Empty, w - 1);

            List <Image> lImages = new List <Image>();
            Dictionary <string, FormatGroupEx> dictGroups =
                new Dictionary <string, FormatGroupEx>();

            foreach (FileFormatProvider f in Program.FileFormatPool)
            {
                if (m_bExport && !f.SupportsExport)
                {
                    continue;
                }
                if (!m_bExport && !f.SupportsImport)
                {
                    continue;
                }

                string strDisplayName = f.DisplayName;
                if (string.IsNullOrEmpty(strDisplayName))
                {
                    Debug.Assert(false); continue;
                }

                string strAppGroup = f.ApplicationGroup;
                if (string.IsNullOrEmpty(strAppGroup))
                {
                    strAppGroup = KPRes.General;
                }

                FormatGroupEx grp;
                if (!dictGroups.TryGetValue(strAppGroup, out grp))
                {
                    grp = new FormatGroupEx(strAppGroup);
                    dictGroups[strAppGroup] = grp;
                }

                ListViewItem lvi = new ListViewItem(strDisplayName);
                lvi.Group = grp.Group;
                lvi.Tag   = f;

                Image imgSmallIcon = f.SmallIcon;
                if (imgSmallIcon == null)
                {
                    imgSmallIcon = Properties.Resources.B16x16_Folder_Inbox;
                }

                lvi.ImageIndex = lImages.Count;
                lImages.Add(imgSmallIcon);

                grp.Items.Add(lvi);
            }

            foreach (FormatGroupEx formatGroup in dictGroups.Values)
            {
                m_lvFormats.Groups.Add(formatGroup.Group);
                foreach (ListViewItem lvi in formatGroup.Items)
                {
                    m_lvFormats.Items.Add(lvi);
                }
            }

            m_ilFormats = UIUtil.BuildImageListUnscaled(lImages,
                                                        DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16));
            m_lvFormats.SmallImageList = m_ilFormats;

            if (m_bExport)
            {
                m_grpFiles.Text = KPRes.Destination;
                UIUtil.SetText(m_lblFiles, KPRes.File + ":");
                UIUtil.SetButtonImage(m_btnSelFile,
                                      Properties.Resources.B16x16_FileSaveAs, false);

                m_lnkFileFormats.Enabled = false;
                m_lnkFileFormats.Visible = false;
            }
            else             // Import
            {
                m_grpFiles.Text = KPRes.Source;
                UIUtil.SetButtonImage(m_btnSelFile,
                                      Properties.Resources.B16x16_Folder_Yellow_Open, false);

                m_grpExport.Enabled     = false;
                m_grpExportPost.Enabled = false;
            }

            m_cbExportMasterKeySpec.Checked = Program.Config.Defaults.ExportMasterKeySpec;
            m_cbExportParentGroups.Checked  = Program.Config.Defaults.ExportParentGroups;
            m_cbExportPostOpen.Checked      = Program.Config.Defaults.ExportPostOpen;
            m_cbExportPostShow.Checked      = Program.Config.Defaults.ExportPostShow;

            UpdateUIState();
        }
Пример #9
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            ++m_uUIAutoBlocked;

            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_tbPassword.TabIndex >= 2) && !m_tbPassword.Focused);

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = m_ioInfo.GetDisplayName();             // Compacted by banner

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strName = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strName))
            {
                this.Text = strStart + " - " + strName;
            }
            else
            {
                this.Text = strStart;
            }

            FontUtil.SetDefaultFont(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbKeyFile);
            // FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnOpenKeyFile, KPRes.KeyFileSelect, true);

            UIUtil.AccSetName(m_tbPassword, m_cbPassword);
            UIUtil.AccSetName(m_cmbKeyFile, m_cbKeyFile);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            // Enable protection before possibly setting a text
            m_cbHidePassword.Checked = true;
            OnHidePasswordCheckedChanged(null, EventArgs.Empty);

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.OnPasswordTextChanged;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileItem(KPRes.NoKeyFileSpecifiedMeta, true);

            Debug.Assert(!AnyComponentOn());

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if (!string.IsNullOrEmpty(strCmdLineFile) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if (!string.IsNullOrEmpty(strCmdLineFile) && strCmdLineFile.Equals(
                    m_ioInfo.Path, StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.UserAccount];
                if (str != null)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            AceKeyAssoc a = Program.Config.Defaults.GetKeySources(m_ioInfo);

            if ((a != null) && !AnyComponentOn())
            {
                if (a.Password)
                {
                    m_cbPassword.Checked = true;
                }

                if (!string.IsNullOrEmpty(a.KeyFilePath))
                {
                    AddKeyFileItem(a.KeyFilePath, true);
                }
                if (!string.IsNullOrEmpty(a.KeyProvider))
                {
                    AddKeyFileItem(a.KeyProvider, true);
                }

                if (a.UserAccount)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider kp in Program.KeyProviderPool)
            {
                AddKeyFileItem(kp.Name, false);
            }

            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyPromptFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if (!m_cbPassword.Enabled && !m_cbPassword.Checked)
            {
                m_tbPassword.Text = string.Empty;
                UIUtil.SetEnabledFast(false, m_tbPassword, m_cbHidePassword);
            }

            if (!m_cbKeyFile.Enabled && !m_cbKeyFile.Checked)
            {
                UIUtil.SetEnabledFast(false, m_cmbKeyFile, m_btnOpenKeyFile);
            }

            if (WinUtil.IsWindows9x || NativeLib.IsUnix())
            {
                UIUtil.SetChecked(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_cbUserAccount, false);
            }

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            --m_uUIAutoBlocked;
            UpdateUIState();

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.OnFormLoadAsync));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.OnFormLoadAsync));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Пример #10
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_dStrings == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            string strTitle, strDesc;

            if (m_strInitName == null)
            {
                strTitle = KPRes.AddStringField;
                strDesc  = KPRes.AddStringFieldDesc;
            }
            else
            {
                strTitle = KPRes.EditStringField;
                strDesc  = KPRes.EditStringFieldDesc;
            }

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Font, strTitle, strDesc);
            this.Icon = AppIcons.Default;

            UIUtil.ConfigureToolTip(m_ttRect);

            UIUtil.EnableAutoCompletion(m_cmbName, true);

            UIUtil.PrepareStandardMultilineControl(m_rtbValue, true, true);
            m_ctxValue.Attach(m_rtbValue, this);

            GFunc <PwEntry> fGetContextEntry = delegate()
            {
                return(PwEntry.CreateVirtual(((m_pdContext != null) ? m_pdContext.RootGroup :
                                              null) ?? new PwGroup(true, true), m_dStrings));
            };

            m_pgm = new PwGeneratorMenu(m_btnGenPw, m_ttRect, m_rtbValue,
                                        fGetContextEntry, m_pdContext, (m_mvec != null));

            if (m_strInitName != null)
            {
                m_cmbName.Text = m_strInitName;
            }
            if (m_psInitValue != null)
            {
                m_rtbValue.Text = StrUtil.NormalizeNewLines(
                    m_psInitValue.ReadString(), true);
                UIUtil.SetChecked(m_cbProtect, m_psInitValue.IsProtected);
            }

            ValidateStringNameUI();
            PopulateNamesComboBox();

            if (m_mvec != null)
            {
                m_cmbName.Enabled = false;
                MultipleValuesEx.ConfigureText(m_rtbValue, true);

                bool bMultiProt;
                m_mvec.MultiStringProt.TryGetValue(m_cmbName.Text, out bMultiProt);
                if (bMultiProt)
                {
                    MultipleValuesEx.ConfigureState(m_cbProtect, true);
                }
            }

            if (m_bReadOnly)
            {
                m_cmbName.Enabled   = false;
                m_rtbValue.ReadOnly = true;
                m_cbProtect.Enabled = false;
                m_btnGenPw.Enabled  = false;
                // m_btnOK.Enabled = false; // See ValidateStringNameUI
            }

            // UIUtil.SetFocus(..., this); // See PopulateNamesComboBox
        }