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); } }
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); } }
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); } }
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; }
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; } }
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("\"", "\"\"\"")); }
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); }
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); } } }
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); } }
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; } }
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("\"", "\"\"\"")); }
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); }
// 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()); }
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); }
internal void CloseEx() { Close(); if (MonoWorkarounds.IsRequired(1710)) { OnFormClosed(this, new FormClosedEventArgs(CloseReason.UserClosing)); } }
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)); }
private void MonoRedrawOnScroll() { if (!m_bForceRedrawOnScroll.HasValue) { m_bForceRedrawOnScroll = MonoWorkarounds.IsRequired(1366); } if (m_bForceRedrawOnScroll.Value) { Invalidate(); } }
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; } }
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); }
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 }
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; }
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; } }
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); }
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); }
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); }
public ListViewDecorator(ListView listView, ITheme theme) { _listView = listView; _theme = theme; if (!MonoWorkarounds.IsRequired()) { _headerPainter = new ListViewHeaderPainter(_listView); _headerPainter.Paint += HandleHeaderPaint; _groupsPainter = new ListViewGroupsPainter(_listView); _groupsPainter.Paint += HandleGroupsPaint; } _listView.Controls.Add(this); }
private static bool GCryptInitLib() { Debug.Assert(Marshal.SizeOf(typeof(int)) == 4); // Also on 64-bit systems Debug.Assert(Marshal.SizeOf(typeof(uint)) == 4); 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); }
private static IOWebClient CreateWebClient(IOConnectionInfo ioc) { PrepareWebAccess(ioc); IOWebClient wc = new IOWebClient(ioc); if ((ioc.UserName.Length > 0) || (ioc.Password.Length > 0)) { wc.Credentials = new NetworkCredential(ioc.UserName, ioc.Password); } else if (MonoWorkarounds.IsRequired(688007)) { wc.Credentials = new NetworkCredential("anonymous", string.Empty); } ConfigureWebClient(wc); return(wc); }
private static WebRequest CreateWebRequest(IOConnectionInfo ioc) { PrepareWebAccess(ioc); WebRequest req = WebRequest.Create(ioc.Path); if ((ioc.UserName.Length > 0) || (ioc.Password.Length > 0)) { req.Credentials = new NetworkCredential(ioc.UserName, ioc.Password); } else if (MonoWorkarounds.IsRequired(688007)) { req.Credentials = new NetworkCredential("anonymous", string.Empty); } ConfigureWebRequest(req, ioc); return(req); }
private static bool GCryptInitLib() { if (!NativeLib.IsUnix()) { return(false); // Independent of workaround state } if (!MonoWorkarounds.IsRequired(1468)) { return(false); // Can be turned off } #if (!KeePassLibSD && !KeePassUAP && !NETSTANDARD2_0) // gcry_check_version initializes the library; // throws when LibGCrypt is not available NativeMethods.gcry_check_version(IntPtr.Zero); return(true); #else return(false); #endif }