Ejemplo n.º 1
0
        /// <summary>
        /// Prepare for saving the configuration to disk. None of the
        /// modifications in this method need to be rolled back
        /// (for rollback, use <c>OnSavePre</c> / <c>OnSavePost</c>).
        /// </summary>
        private void PrepareSave()
        {
            AceMeta        aceMeta = this.Meta;        // m_meta might be null
            AceApplication aceApp  = this.Application; // m_aceApp might be null
            AceDefaults    aceDef  = this.Defaults;    // m_def might be null

            aceMeta.OmitItemsWithDefaultValues = true;
            aceMeta.DpiFactorX = DpiUtil.FactorX;             // For new (not loaded) cfgs.
            aceMeta.DpiFactorY = DpiUtil.FactorY;

            aceApp.LastUsedFile.ClearCredentials(true);

            foreach (IOConnectionInfo iocMru in aceApp.MostRecentlyUsed.Items)
            {
                iocMru.ClearCredentials(true);
            }

            if (aceDef.RememberKeySources == false)
            {
                aceDef.KeySources.Clear();
            }

            aceApp.TriggerSystem = Program.TriggerSystem;

            SearchUtil.PrepareForSerialize(aceDef.SearchParameters);

            const int     m = 64;         // Maximum number of compatibility items
            List <string> l = aceApp.PluginCompatibility;

            if (l.Count > m)
            {
                l.RemoveRange(m, l.Count - m);                         // See reg.
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepare for saving the configuration to disk. None of the
        /// modifications in this method need to be rolled back
        /// (for rollback, use <c>OnSavePre</c> / <c>OnSavePost</c>).
        /// </summary>
        private void PrepareSave()
        {
            AceMeta        aceMeta = this.Meta;        // m_meta might be null
            AceApplication aceApp  = this.Application; // m_aceApp might be null
            AceDefaults    aceDef  = this.Defaults;    // m_def might be null

            aceMeta.OmitItemsWithDefaultValues = true;
            aceMeta.DpiFactorX = DpiUtil.FactorX;             // For new (not loaded) cfgs.
            aceMeta.DpiFactorY = DpiUtil.FactorY;

            aceApp.LastUsedFile.ClearCredentials(true);

            foreach (IOConnectionInfo iocMru in aceApp.MostRecentlyUsed.Items)
            {
                iocMru.ClearCredentials(true);
            }

            if (aceDef.RememberKeySources == false)
            {
                aceDef.KeySources.Clear();
            }

            aceApp.TriggerSystem = Program.TriggerSystem;

            SearchUtil.PrepareForSerialize(aceDef.SearchParameters);
        }
Ejemplo n.º 3
0
        private void DpiScale()
        {
            AceMeta aceMeta = this.Meta;             // m_meta might be null
            double  dCfgX = aceMeta.DpiFactorX, dCfgY = aceMeta.DpiFactorY;
            double  dScrX = DpiUtil.FactorX, dScrY = DpiUtil.FactorY;

            if ((dScrX == dCfgX) && (dScrY == dCfgY))
            {
                return;
            }

            // When this method returns, all positions and sizes are in pixels
            // for the current screen DPI
            aceMeta.DpiFactorX = dScrX;
            aceMeta.DpiFactorY = dScrY;

            // Backward compatibility; configuration files created by KeePass
            // 2.37 and earlier do not contain DpiFactor* values, they default
            // to 0.0 and all positions and sizes are in pixels for the current
            // screen DPI; so, do not perform any DPI scaling in this case
            if ((dCfgX == 0.0) || (dCfgY == 0.0))
            {
                return;
            }

            double           sX = dScrX / dCfgX, sY = dScrY / dCfgY;
            GFunc <int, int> fX = delegate(int x)
            {
                return((int)Math.Round((double)x * sX));
            };
            GFunc <int, int> fY = delegate(int y)
            {
                return((int)Math.Round((double)y * sY));
            };
            GFunc <string, string> fWsr = delegate(string strRect)
            {
                return(UIUtil.ScaleWindowScreenRect(strRect, sX, sY));
            };
            GFunc <string, string> fVX = delegate(string strArray)
            {
                if (string.IsNullOrEmpty(strArray))
                {
                    return(strArray);
                }

                try
                {
                    int[] v = StrUtil.DeserializeIntArray(strArray);
                    if (v == null)
                    {
                        Debug.Assert(false); return(strArray);
                    }

                    for (int i = 0; i < v.Length; ++i)
                    {
                        v[i] = (int)Math.Round((double)v[i] * sX);
                    }

                    return(StrUtil.SerializeIntArray(v));
                }
                catch (Exception) { Debug.Assert(false); }

                return(strArray);
            };
            Action <AceFont> fFont = delegate(AceFont f)
            {
                if (f == null)
                {
                    Debug.Assert(false); return;
                }

                if (f.GraphicsUnit == GraphicsUnit.Pixel)
                {
                    f.Size = (float)(f.Size * sY);
                }
            };

            AceMainWindow mw = this.MainWindow;
            AceUI         ui = this.UI;

            if (mw.X != AppDefs.InvalidWindowValue)
            {
                mw.X = fX(mw.X);
            }
            if (mw.Y != AppDefs.InvalidWindowValue)
            {
                mw.Y = fY(mw.Y);
            }
            if (mw.Width != AppDefs.InvalidWindowValue)
            {
                mw.Width = fX(mw.Width);
            }
            if (mw.Height != AppDefs.InvalidWindowValue)
            {
                mw.Height = fY(mw.Height);
            }

            foreach (AceColumn c in mw.EntryListColumns)
            {
                if (c.Width >= 0)
                {
                    c.Width = fX(c.Width);
                }
            }

            ui.DataViewerRect          = fWsr(ui.DataViewerRect);
            ui.DataEditorRect          = fWsr(ui.DataEditorRect);
            ui.CharPickerRect          = fWsr(ui.CharPickerRect);
            ui.AutoTypeCtxRect         = fWsr(ui.AutoTypeCtxRect);
            ui.AutoTypeCtxColumnWidths = fVX(ui.AutoTypeCtxColumnWidths);

            fFont(ui.StandardFont);
            fFont(ui.PasswordFont);
            fFont(ui.DataEditorFont);
        }