Пример #1
0
        internal void OnLoad()
        {
            AceMainWindow aceMW  = this.MainWindow;         // m_uiMainWindow might be null
            AceDefaults   aceDef = this.Defaults;           // m_def might be null

            // aceInt.UrlSchemeOverrides.SetDefaultsIfEmpty();

            ObfuscateCred(false);
            ChangePathsRelAbs(true);

            // Remove invalid columns
            List <AceColumn> vColumns = aceMW.EntryListColumns;
            int i = 0;

            while (i < vColumns.Count)
            {
                if (((int)vColumns[i].Type < 0) || ((int)vColumns[i].Type >=
                                                    (int)AceColumnType.Count))
                {
                    vColumns.RemoveAt(i);
                }
                else
                {
                    ++i;
                }
            }

            SearchUtil.FinishDeserialize(aceDef.SearchParameters);
            DpiScale();

            if (aceMW.EscMinimizesToTray)            // For backward compatibility
            {
                aceMW.EscMinimizesToTray = false;    // Default value
                aceMW.EscAction          = AceEscAction.MinimizeToTray;
            }

            if (NativeLib.IsUnix())
            {
                this.Security.MasterKeyOnSecureDesktop = false;

                AceIntegration aceInt = this.Integration;
                aceInt.HotKeyGlobalAutoType   = (ulong)Keys.None;
                aceInt.HotKeySelectedAutoType = (ulong)Keys.None;
                aceInt.HotKeyShowWindow       = (ulong)Keys.None;
            }

            if (MonoWorkarounds.IsRequired(1378))
            {
                AceWorkspaceLocking aceWL = this.Security.WorkspaceLocking;
                aceWL.LockOnSessionSwitch       = false;
                aceWL.LockOnSuspend             = false;
                aceWL.LockOnRemoteControlChange = false;
            }

            if (MonoWorkarounds.IsRequired(1418))
            {
                aceMW.MinimizeAfterOpeningDatabase        = false;
                this.Application.Start.MinimizedAndLocked = false;
            }
        }
Пример #2
0
        internal static string EncodeForCommandLine(string strRaw)
        {
            if (strRaw == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            if (MonoWorkarounds.IsRequired(3471228285U) && NativeLib.IsUnix())
            {
                string str = strRaw;

                str = str.Replace("\\", "\\\\");
                str = str.Replace("\"", "\\\"");
                str = str.Replace("\'", "\\\'");
                str = str.Replace("\u0060", "\\\u0060");                 // Grave accent
                str = str.Replace("$", "\\$");
                str = str.Replace("&", "\\&");
                str = str.Replace("<", "\\<");
                str = str.Replace(">", "\\>");
                str = str.Replace("|", "\\|");
                str = str.Replace(";", "\\;");
                str = str.Replace("(", "\\(");
                str = str.Replace(")", "\\)");

                return(str);
            }

            // See SHELLEXECUTEINFO structure documentation
            return(strRaw.Replace("\"", "\"\"\""));
        }
Пример #3
0
        public static void CommonTerminate()
        {
#if DEBUG
            Debug.Assert(ShutdownBlocker.Instance == null);
            Debug.Assert(!SendInputEx.IsSending);
            // GC.Collect(); // Force invocation of destructors
#endif

            AppLogEx.Close();

            if (m_tempFilesPool != null)
            {
                m_tempFilesPool.Clear(TempClearFlags.All);
                m_tempFilesPool.WaitForThreads();
            }

            EnableThemingInScope.StaticDispose();
            MonoWorkarounds.Terminate();

#if KP_DEVSNAP
            if (m_bAsmResReg)
            {
                AppDomain.CurrentDomain.AssemblyResolve -= Program.AssemblyResolve;
                m_bAsmResReg = false;
            }
            else
            {
                Debug.Assert(false);
            }
#endif
        }
Пример #4
0
        public static void RemoveWindow(Form form)
        {
            Debug.Assert(form != null);
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            lock (g_oSyncRoot)
            {
                for (int i = 0; i < g_vWindows.Count; ++i)
                {
                    if (g_vWindows[i].Key == form)
                    {
                        if (GlobalWindowManager.WindowRemoved != null)
                        {
                            GlobalWindowManager.WindowRemoved(null, new GwmWindowEventArgs(
                                                                  form, g_vWindows[i].Value));
                        }

                        MonoWorkarounds.Release(form);

#if DEBUG
                        DebugClose(form);
#endif

                        g_vWindows.RemoveAt(i);
                        return;
                    }
                }
            }

            Debug.Assert(false);             // Window not found
        }
Пример #5
0
        private void Apply(Control control)
        {
            var listView = (ListView)control;

            if (!listView.OwnerDraw && listView.View == View.Details)
            {
                listView.OwnerDraw = true;

                listView.Resize                += HandleListViewResize;
                listView.DrawColumnHeader      += HandleListViewDrawColumnHeader;
                listView.DrawItem              += HandleListViewDrawItem;
                listView.DrawSubItem           += HandleListViewDrawSubItem;
                listView.Parent.EnabledChanged += ListViewParentEnabledChanged;
            }

            // Setting borders style throws exception on Mono
            if (!MonoWorkarounds.IsRequired())
            {
                listView.BorderStyle = _theme.ListView.BorderStyle;
            }

            listView.BackColor = _theme.ListView.BackColor;

            if (_theme.ListViewBackgroundTiled)
            {
                listView.BackgroundImage      = _theme.ListViewBackground;
                listView.BackgroundImageTiled = _theme.ListViewBackgroundTiled;
            }
        }
Пример #6
0
        public static void AddWindow(Form form, IGwmWindow wnd)
        {
            Debug.Assert(form != null);
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            KeyValuePair <Form, IGwmWindow> kvp = new KeyValuePair <Form, IGwmWindow>(
                form, wnd);

            Debug.Assert(m_vWindows.IndexOf(kvp) < 0);
            m_vWindows.Add(kvp);

            form.TopMost = Program.Config.MainWindow.AlwaysOnTop;
            // Form formParent = form.ParentForm;
            // if(formParent != null) form.TopMost = formParent.TopMost;
            // else { Debug.Assert(false); }

            // form.Font = new System.Drawing.Font(System.Drawing.SystemFonts.MessageBoxFont.Name, 12.0f);

            CustomizeControl(form);

            MonoWorkarounds.ApplyTo(form);

            if (GlobalWindowManager.WindowAdded != null)
            {
                GlobalWindowManager.WindowAdded(null, new GwmWindowEventArgs(
                                                    form, wnd));
            }
        }
Пример #7
0
        public NotifyIconEx(IContainer container)
        {
            try
            {
                bool bNtf = true;
                if (NativeLib.GetPlatformID() == PlatformID.MacOSX)
                {
                    bNtf = !MonoWorkarounds.IsRequired(1574);
                }
                else
                {
                    DesktopType t = NativeLib.GetDesktopType();
                    if ((t == DesktopType.Unity) || (t == DesktopType.Pantheon))
                    {
                        bNtf = !MonoWorkarounds.IsRequired(1354);
                    }
                }

                if (bNtf)
                {
                    m_ntf = new NotifyIcon(container);
                }
            }
            catch (Exception) { Debug.Assert(false); }
        }
Пример #8
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false;             // Again, for the ones not calling Main

            m_rndGlobal = CryptoRandom.NewWeakRandom();

            InitEnvSecurity();
            MonoWorkarounds.Initialize();

            // try { NativeMethods.SetProcessDPIAware(); }
            // catch(Exception) { }

            // Do not run as AppX, because of compatibility problems
            // (unless we're a special compatibility build)
            if (WinUtil.IsAppX && !IsBuildType(
                    "CDE75CF0D4CA04D577A5A2E6BF5D19BFD5DDBBCF89D340FBBB0E4592C04496F1"))
            {
                return(false);
            }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            if (m_appConfig.Security.ProtectProcessWithDacl)
            {
                KeePassLib.Native.NativeMethods.ProtectProcessWithDacl();
            }

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

            return(true);
        }
Пример #9
0
        internal static string EncodeDataToArgs(string strData)
        {
            if (strData == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            // Cf. EncodePath and DecodeArgsToPath
            if (MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
            {
                string str = strData;

                str = str.Replace("\\", "\\\\");
                str = str.Replace("\"", "\\\"");

                // Whether '\'' needs to be encoded depends on the context
                // (e.g. surrounding quotes); as we do not know what the
                // caller does with the returned string, we assume that
                // it will be used in a context where '\'' must not be
                // encoded; this behavior is documented
                // str = str.Replace("\'", "\\\'");

                return(str);
            }

            // See SHELLEXECUTEINFO structure documentation
            return(strData.Replace("\"", "\"\"\""));
        }
Пример #10
0
        private static void EnsureInitializedStatic()
        {
            if (m_vTags != null)
            {
                return;
            }

            // When running under Mono, replace bold and italic text
            // by underlined text, which is rendered correctly (in
            // contrast to bold and italic text)
            string strOvrS = null, strOvrE = null;

            if (MonoWorkarounds.IsRequired(1632))
            {
                strOvrS = "\\ul ";
                strOvrE = "\\ul0 ";
            }

            List <RtfbTag> l = new List <RtfbTag>();

            l.Add(new RtfbTag(null, (strOvrS ?? "\\b "), true, FontStyle.Bold));
            l.Add(new RtfbTag(null, (strOvrE ?? "\\b0 "), false, FontStyle.Bold));
            l.Add(new RtfbTag(null, (strOvrS ?? "\\i "), true, FontStyle.Italic));
            l.Add(new RtfbTag(null, (strOvrE ?? "\\i0 "), false, FontStyle.Italic));
            l.Add(new RtfbTag(null, "\\ul ", true, FontStyle.Underline));
            l.Add(new RtfbTag(null, "\\ul0 ", false, FontStyle.Underline));
            l.Add(new RtfbTag(null, "\\strike ", true, FontStyle.Strikeout));
            l.Add(new RtfbTag(null, "\\strike0 ", false, FontStyle.Strikeout));
            m_vTags = l;
        }
Пример #11
0
		private static void EnsureNoBom(StreamWriter sw)
		{
			if(sw == null) { Debug.Assert(false); return; }
			if(!MonoWorkarounds.IsRequired(1219)) return;

			try
			{
				Encoding enc = sw.Encoding;
				if(enc == null) { Debug.Assert(false); return; }
				byte[] pbBom = enc.GetPreamble();
				if((pbBom == null) || (pbBom.Length == 0)) return;

				// For Mono >= 4.0 (using Microsoft's reference source)
				try
				{
					FieldInfo fi = typeof(StreamWriter).GetField("haveWrittenPreamble",
						BindingFlags.Instance | BindingFlags.NonPublic);
					if(fi != null)
					{
						fi.SetValue(sw, true);
						return;
					}
				}
				catch(Exception) { Debug.Assert(false); }

				// For Mono < 4.0
				FieldInfo fiPD = typeof(StreamWriter).GetField("preamble_done",
					BindingFlags.Instance | BindingFlags.NonPublic);
				if(fiPD != null) fiPD.SetValue(sw, true);
				else { Debug.Assert(false); }
			}
			catch(Exception) { Debug.Assert(false); }
		}
Пример #12
0
        public override void Close()
        {
            base.Close();
#endif
            if (MonoWorkarounds.IsRequired(10163) && m_bWrite)
            {
                try
                {
                    Stream s = this.BaseStream;
                    Type   t = s.GetType();
                    if (t.Name == "WebConnectionStream")
                    {
                        PropertyInfo pi = t.GetProperty("Request",
                                                        BindingFlags.Instance | BindingFlags.NonPublic);
                        if (pi != null)
                        {
                            WebRequest wr = (pi.GetValue(s, null) as WebRequest);
                            if (wr != null)
                            {
                                IOConnection.DisposeResponse(wr.GetResponse(), false);
                            }
                            else
                            {
                                Debug.Assert(false);
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                }
                catch (Exception) { Debug.Assert(false); }
            }
        }
Пример #13
0
        public static void Apply(ITheme theme, bool enabled)
        {
            var colorTableFieldName = MonoWorkarounds.IsRequired() ? "s_colorTable" : "colorTable";
            var colorTableField     = typeof(Color).Assembly.GetType("System.Drawing.KnownColorTable")
                                      .GetField(colorTableFieldName, BindingFlags.Static | BindingFlags.NonPublic);

            if (colorTableField == null)
            {
                return;
            }

            var colorTable = (int[])colorTableField.GetValue(null);

            if (_originalColorTable == null)
            {
                _originalColorTable = new int[colorTable.Length];
                Array.Copy(colorTable, _originalColorTable, colorTable.Length);
            }

            if (enabled)
            {
                colorTable[(int)KnownColor.ControlText] = theme.Control.ForeColor.ToArgb();
                colorTable[(int)KnownColor.Control]     = theme.Control.BackColor.ToArgb();
            }
            else
            {
                Array.Copy(_originalColorTable, colorTable, colorTable.Length);
            }
        }
Пример #14
0
        public void EnableProtection(bool bEnable)
        {
            if (m_tbPassword == null)
            {
                Debug.Assert(false); return;
            }

            if (!MonoWorkarounds.IsRequired(5795))
            {
                if (bEnable)
                {
                    FontUtil.AssignDefault(m_tbPassword);
                }
                else
                {
                    FontUtil.SetDefaultFont(m_tbPassword);
                    FontUtil.AssignDefaultMono(m_tbPassword, true);
                }
            }

            if (m_tbPassword.UseSystemPasswordChar == bEnable)
            {
                return;
            }
            m_tbPassword.UseSystemPasswordChar = bEnable;

            ShowCurrentPassword(-1, -1);
        }
Пример #15
0
        private static void CheckCompatibilityPriv(Plugin p)
        {
            // When trying to resolve a non-existing token, Mono
            // terminates the whole process with a SIGABRT instead
            // of just throwing an ArgumentOutOfRangeException
            if (MonoWorkarounds.IsRequired(9604))
            {
                return;
            }

            Assembly asm = p.GetType().Assembly;

            if (asm == typeof(PluginManager).Assembly)
            {
                Debug.Assert(false); return;
            }

            foreach (Module m in asm.GetModules())
            {
                // MetadataTokenType.TypeRef = 0x01000000
                CheckRefs(m, 0x01000000, CheckTypeRef);

                // MetadataTokenType.MemberRef = 0x0A000000
                CheckRefs(m, 0x0A000000, CheckMemberRef);
            }
        }
Пример #16
0
        protected override void OnLinkClicked(LinkClickedEventArgs e)
        {
            try
            {
                string str = e.LinkText;
                if (string.IsNullOrEmpty(str))
                {
                    Debug.Assert(false); return;
                }

                // Open the URL if no handler has been associated with
                // the LinkClicked event;
                // if(this.LinkClicked == null) WinUtil.OpenUrl(str, null);
                string strEv = (MonoWorkarounds.IsRequired() ? "LinkClickedEvent" :
                                "EVENT_LINKACTIVATE");
                FieldInfo fi = typeof(RichTextBox).GetField(strEv,
                                                            BindingFlags.NonPublic | BindingFlags.Static);
                object oEv = ((fi != null) ? fi.GetValue(null) : null);
                if (oEv != null)
                {
                    if (this.Events[oEv] == null)                    // No event handler associated
                    {
                        WinUtil.OpenUrl(str, null);
                        return;
                    }
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            catch (Exception) { Debug.Assert(false); }

            base.OnLinkClicked(e);
        }
Пример #17
0
        // Cf. EncodeDataToArgs
        internal static string DecodeArgsToData(string strArgs)
        {
            if (strArgs == null)
            {
                Debug.Assert(false); return(string.Empty);
            }

            Debug.Assert(StrUtil.Count(strArgs, "\"") == StrUtil.Count(strArgs, "\\\""));

            if (MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
            {
                string str = strArgs;

                str = str.Replace("\\\"", "\"");
                str = str.Replace("\\\\", "\\");

                return(str);
            }

            StringBuilder sb = new StringBuilder();
            int           i  = 0;

            while (i < strArgs.Length)
            {
                char ch = strArgs[i++];

                if (ch == '\\')
                {
                    int cBackslashes = 1;
                    while ((i < strArgs.Length) && (strArgs[i] == '\\'))
                    {
                        ++cBackslashes;
                        ++i;
                    }

                    if (i == strArgs.Length)
                    {
                        sb.Append('\\', cBackslashes);                         // Assume no quote follows
                    }
                    else if (strArgs[i] == '\"')
                    {
                        Debug.Assert((cBackslashes & 1) == 1);
                        sb.Append('\\', (cBackslashes - 1) / 2);
                        sb.Append('\"');
                        ++i;
                    }
                    else
                    {
                        sb.Append('\\', cBackslashes);
                    }
                }
                else
                {
                    sb.Append(ch);
                }
            }

            return(sb.ToString());
        }
Пример #18
0
        internal static Process StartProcessEx(ProcessStartInfo psi)
        {
            if (psi == null)
            {
                Debug.Assert(false); return(null);
            }

            string strFileOrg = psi.FileName;

            if (string.IsNullOrEmpty(strFileOrg))
            {
                Debug.Assert(false); return(null);
            }

            Process p;

            try
            {
                string strFile = strFileOrg;

                string[] vUrlEncSchemes = new string[] {
                    "file:", "ftp:", "ftps:", "http:", "https:",
                    "mailto:", "scp:", "sftp:"
                };
                foreach (string strPfx in vUrlEncSchemes)
                {
                    if (strFile.StartsWith(strPfx, StrUtil.CaseIgnoreCmp))
                    {
                        Debug.Assert(string.IsNullOrEmpty(psi.Arguments));

                        strFile = strFile.Replace("\"", "%22");
                        strFile = strFile.Replace("\'", "%27");
                        strFile = strFile.Replace("\\", "%5C");
                        break;
                    }
                }

                if (IsUnix())
                {
                    // Mono's Process.Start method replaces '\\' by '/',
                    // which may cause a different file to be executed;
                    // therefore, we refuse to start such files
                    if (strFile.Contains("\\") && MonoWorkarounds.IsRequired(190417))
                    {
                        throw new ArgumentException(KLRes.PathBackslash);
                    }

                    strFile = strFile.Replace("\\", "\\\\");                     // If WA not required
                    strFile = strFile.Replace("\"", "\\\"");
                }

                psi.FileName = strFile;
                p            = Process.Start(psi);
            }
            finally { psi.FileName = strFileOrg; }

            return(p);
        }
Пример #19
0
        internal void CloseEx()
        {
            Close();

            if (MonoWorkarounds.IsRequired(1710))
            {
                OnFormClosed(this, new FormClosedEventArgs(CloseReason.UserClosing));
            }
        }
Пример #20
0
        protected override bool ProcessCmdKey(ref Message m, Keys keyData)
        {
            try
            {
                if (!m_bSimpleTextOnly && this.ShortcutsEnabled &&
                    this.RichTextShortcutsEnabled && !this.ReadOnly)
                {
                    bool bHandled = true;

                    switch (keyData)
                    {
                    case (Keys.Control | Keys.B):
                        UIUtil.RtfToggleSelectionFormat(this, FontStyle.Bold);
                        break;

                    case (Keys.Control | Keys.I):
                        UIUtil.RtfToggleSelectionFormat(this, FontStyle.Italic);
                        break;

                    case (Keys.Control | Keys.U):
                        UIUtil.RtfToggleSelectionFormat(this, FontStyle.Underline);
                        break;

                    // The following keyboard shortcuts are implemented
                    // by the rich text box on Windows, but not by Mono;
                    // https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.textboxbase.shortcutsenabled
                    case (Keys.Control | Keys.L):
                        this.SelectionAlignment = HorizontalAlignment.Left;
                        break;

                    case (Keys.Control | Keys.E):
                        this.SelectionAlignment = HorizontalAlignment.Center;
                        break;

                    case (Keys.Control | Keys.R):
                        this.SelectionAlignment = HorizontalAlignment.Right;
                        break;

                    default: bHandled = false; break;
                    }

                    if (bHandled)
                    {
                        if (MonoWorkarounds.IsRequired(100002))
                        {
                            OnTextChanged(EventArgs.Empty);
                        }
                        return(true);
                    }
                }
            }
            catch (Exception) { Debug.Assert(false); }

            return(base.ProcessCmdKey(ref m, keyData));
        }
Пример #21
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false;             // Again, for the ones not calling Main

            int nRandomSeed = (int)DateTime.UtcNow.Ticks;

            // Prevent overflow (see Random class constructor)
            if (nRandomSeed == int.MinValue)
            {
                nRandomSeed = 17;
            }
            m_rndGlobal = new Random(nRandomSeed);

            InitEnvSecurity();
            MonoWorkarounds.Initialize();

            // try { NativeMethods.SetProcessDPIAware(); }
            // catch(Exception) { }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

            return(true);
        }
Пример #22
0
        private void MonoRedrawOnScroll()
        {
            if (!m_bForceRedrawOnScroll.HasValue)
            {
                m_bForceRedrawOnScroll = MonoWorkarounds.IsRequired(1366);
            }

            if (m_bForceRedrawOnScroll.Value)
            {
                Invalidate();
            }
        }
Пример #23
0
        private void Apply(TreeView treeView)
        {
            treeView.BorderStyle = _theme.TreeView.BorderStyle;
            treeView.BackColor   = _theme.TreeView.BackColor;

            if (!MonoWorkarounds.IsRequired())
            {
                treeView.DrawMode  = _theme.TreeViewDrawMode;
                treeView.DrawNode -= HandleTreeViewDrawNode;
                treeView.DrawNode += HandleTreeViewDrawNode;
            }
        }
Пример #24
0
        public override bool IsSupported()
        {
            // bool bVisualStyles = true;
            // try { bVisualStyles = VisualStyleRenderer.IsSupported; }
            // catch(Exception) { Debug.Assert(false); bVisualStyles = false; }

            // Various drawing bugs under Mono (gradients too light, incorrect
            // painting of popup menus, paint method not invoked for disabled
            // items, ...)
            bool bMono = MonoWorkarounds.IsRequired();

            return(!UIUtil.IsHighContrast && !bMono);
        }
Пример #25
0
        internal static void ConfigureHideButton(CheckBox cb, ToolTip tt)
        {
            if (cb == null)
            {
                Debug.Assert(false); return;
            }

            Debug.Assert(!cb.AutoSize);
            Debug.Assert(cb.Appearance == Appearance.Button);
            Debug.Assert(cb.Image == null);
            Debug.Assert(cb.Text == "***");
            Debug.Assert(cb.TextAlign == ContentAlignment.MiddleCenter);
            Debug.Assert(cb.TextImageRelation == TextImageRelation.Overlay);
            Debug.Assert(cb.UseVisualStyleBackColor);
            Debug.Assert((cb.Width == 32) || DpiUtil.ScalingRequired ||
                         MonoWorkarounds.IsRequired(100001));
            Debug.Assert((cb.Height == 23) || DpiUtil.ScalingRequired ||
                         MonoWorkarounds.IsRequired(100001));

            // Too much spacing between the dots when using the default font
            // cb.Text = new string(SecureTextBoxEx.PasswordCharEx, 3);
            cb.Text = string.Empty;

            Image img = Properties.Resources.B19x07_3BlackDots;

            if (UIUtil.IsDarkTheme)
            {
                if (g_bmpLightDots == null)
                {
                    g_bmpLightDots = UIUtil.InvertImage(img);
                }

                if (g_bmpLightDots != null)
                {
                    img = g_bmpLightDots;
                }
            }
            else
            {
                Debug.Assert(g_bmpLightDots == null);
            }                                                          // Always or never

            cb.Image = img;
            Debug.Assert(cb.ImageAlign == ContentAlignment.MiddleCenter);

            if (tt != null)
            {
                UIUtil.SetToolTip(tt, cb, KPRes.TogglePasswordAsterisks, false);
            }
            UIUtil.AccSetName(cb, KPRes.TogglePasswordAsterisks);             // Even if tt is null
        }
Пример #26
0
        private static void CustomizeProcessStartInfo(ProcessStartInfo psi)
        {
            string strFile = psi.FileName, strArgs = psi.Arguments;

            string[] vUrlEncSchemes = new string[] {
                "file:", "ftp:", "ftps:", "http:", "https:",
                "mailto:", "scp:", "sftp:"
            };
            foreach (string strPfx in vUrlEncSchemes)
            {
                if (strFile.StartsWith(strPfx, StrUtil.CaseIgnoreCmp))
                {
                    Debug.Assert(string.IsNullOrEmpty(strArgs));

                    strFile = strFile.Replace("\"", "%22");
                    strFile = strFile.Replace("\'", "%27");
                    strFile = strFile.Replace("\\", "%5C");
                    break;
                }
            }

            if (IsUnix())
            {
                if (MonoWorkarounds.IsRequired(19836) && string.IsNullOrEmpty(strArgs))
                {
                    if (Regex.IsMatch(strFile, "^[a-zA-Z][a-zA-Z0-9\\+\\-\\.]*:",
                                      RegexOptions.Singleline) ||
                        strFile.EndsWith(".html", StrUtil.CaseIgnoreCmp))
                    {
                        bool bMacOSX = (GetPlatformID() == PlatformID.MacOSX);

                        strArgs = "\"" + EncodeDataToArgs(strFile) + "\"";
                        strFile = (bMacOSX ? "open" : "xdg-open");
                    }
                }

                // Mono's Process.Start method replaces '\\' by '/',
                // which may cause a different file to be executed;
                // therefore, we refuse to start such files
                if (strFile.Contains("\\") && MonoWorkarounds.IsRequired(190417))
                {
                    throw new ArgumentException(KLRes.PathBackslash);
                }

                strFile = strFile.Replace("\\", "\\\\");                 // If WA not required
                strFile = strFile.Replace("\"", "\\\"");
            }

            psi.FileName  = strFile;
            psi.Arguments = strArgs;
        }
Пример #27
0
        public static Stream WrapIfRequired(Stream s)
        {
            if (s == null)
            {
                Debug.Assert(false); return(null);
            }

            if (MonoWorkarounds.IsRequired(10163) && s.CanWrite)
            {
                return(new IocStream(s));
            }

            return(s);
        }
Пример #28
0
        private void Apply(TreeView treeView)
        {
            treeView.BorderStyle = _theme.TreeView.BorderStyle;
            treeView.BackColor   = _theme.TreeView.BackColor;

            TrySetWindowTheme(treeView.Handle, _enabled);

            if (!MonoWorkarounds.IsRequired())
            {
                treeView.DrawMode  = _theme.TreeViewDrawMode;
                treeView.DrawNode -= HandleTreeViewDrawNode;
                treeView.DrawNode += HandleTreeViewDrawNode;
            }
        }
Пример #29
0
 private static bool GCryptInit()
 {
     if (!NativeLib.IsUnix())
     {
         return(false);                                // Independent of workaround state
     }
     if (!MonoWorkarounds.IsRequired(1468))
     {
         return(false);                                              // Can be turned off
     }
     // gcry_check_version initializes the library;
     // throws when LibGCrypt is not available
     NativeMethods.gcry_check_version(IntPtr.Zero);
     return(true);
 }
Пример #30
0
        private bool SkipGroupHeaderIfRequired(KeyEventArgs e)
        {
            if (!UIUtil.GetGroupsEnabled(this))
            {
                return(false);
            }
            if (this.MultiSelect)
            {
                return(false);
            }

            if (MonoWorkarounds.IsRequired(836428016))
            {
                return(false);
            }

            ListViewItem lvi = this.FocusedItem;

            if (lvi != null)
            {
                ListViewGroup g           = lvi.Group;
                ListViewItem  lviChangeTo = null;

                if ((e.KeyCode == Keys.Up) && IsFirstLastItemInGroup(g, lvi, true))
                {
                    lviChangeTo = (GetNextLvi(g, true) ?? lvi);                     // '??' for top item
                }
                else if ((e.KeyCode == Keys.Down) && IsFirstLastItemInGroup(g, lvi, false))
                {
                    lviChangeTo = (GetNextLvi(g, false) ?? lvi);                     // '??' for bottom item
                }
                if (lviChangeTo != null)
                {
                    foreach (ListViewItem lviEnum in this.Items)
                    {
                        lviEnum.Selected = false;
                    }

                    EnsureVisible(lviChangeTo.Index);
                    UIUtil.SetFocusedItem(this, lviChangeTo, true);

                    UIUtil.SetHandled(e, true);
                    return(true);
                }
            }

            return(false);
        }