From 7365ba14d0cee8146a10f0522d6553d5060edfe3 Mon Sep 17 00:00:00 2001 From: CleanCodeDeveloper <16760760+CleanCodeDeveloper@users.noreply.github.com> Date: Mon, 14 Mar 2022 16:42:32 +0100 Subject: [PATCH] [PreviewPane] Enable analyzer and fix warnings (#16995) --- .../WebBrowserExtUnitTests.cs | 1 + .../common/PreviewHandlerCommon.csproj | 2 + .../common/Utilities/ReadonlyStream.cs | 2 +- .../WebBrowserDownloadControlFlags.cs | 165 +++++++++--------- .../common/controls/WebBrowserExt.cs | 3 +- 5 files changed, 90 insertions(+), 83 deletions(-) diff --git a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/WebBrowserExtUnitTests.cs b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/WebBrowserExtUnitTests.cs index 0e4489b597..8c03a2a989 100644 --- a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/WebBrowserExtUnitTests.cs +++ b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/WebBrowserExtUnitTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Reflection; +using Common; using Microsoft.PowerToys.STATestExtension; using Microsoft.VisualStudio.TestTools.UnitTesting; using PreviewHandlerCommon; diff --git a/src/modules/previewpane/common/PreviewHandlerCommon.csproj b/src/modules/previewpane/common/PreviewHandlerCommon.csproj index 05cd4d70b8..2895ceee31 100644 --- a/src/modules/previewpane/common/PreviewHandlerCommon.csproj +++ b/src/modules/previewpane/common/PreviewHandlerCommon.csproj @@ -18,6 +18,8 @@ false false true + true + Recommended diff --git a/src/modules/previewpane/common/Utilities/ReadonlyStream.cs b/src/modules/previewpane/common/Utilities/ReadonlyStream.cs index eb8d4a897a..6baca663b9 100644 --- a/src/modules/previewpane/common/Utilities/ReadonlyStream.cs +++ b/src/modules/previewpane/common/Utilities/ReadonlyStream.cs @@ -107,7 +107,7 @@ namespace Common.Utilities if (buffer == null) { - throw new NullReferenceException("buffer is null"); + throw new ArgumentNullException(nameof(buffer), "buffer is null"); } if (offset < 0 || count < 0 || (offset + count) > buffer.Length) diff --git a/src/modules/previewpane/common/controls/WebBrowserDownloadControlFlags.cs b/src/modules/previewpane/common/controls/WebBrowserDownloadControlFlags.cs index bf4743a0e9..0ea884eacc 100644 --- a/src/modules/previewpane/common/controls/WebBrowserDownloadControlFlags.cs +++ b/src/modules/previewpane/common/controls/WebBrowserDownloadControlFlags.cs @@ -4,106 +4,109 @@ using System; -/// -/// Flags to control download and execution in Web Browser Control. -/// Values of flags are defined in mshtmdid.h in distributed Windows Sdk. -/// -[Flags] -[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop, keeping stuff in sync")] -public enum WebBrowserDownloadControlFlags : int +namespace Common { /// - /// Images will be downloaded from the server if this flag is set. + /// Flags to control download and execution in Web Browser Control. + /// Values of flags are defined in mshtmdid.h in distributed Windows Sdk. /// - DLIMAGES = 0x00000010, + [Flags] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Interop, keeping stuff in sync")] + public enum WebBrowserDownloadControlFlags : int + { + /// + /// Images will be downloaded from the server if this flag is set. + /// + DLIMAGES = 0x00000010, - /// - /// Videos will be downloaded from the server if this flag is set. - /// - VIDEOS = 0x00000020, + /// + /// Videos will be downloaded from the server if this flag is set. + /// + VIDEOS = 0x00000020, - /// - /// Background sounds will be downloaded from the server if this flag is set. - /// - BGSOUNDS = 0x00000040, + /// + /// Background sounds will be downloaded from the server if this flag is set. + /// + BGSOUNDS = 0x00000040, - /// - /// Scripts will not be executed. - /// - NO_SCRIPTS = 0x00000080, + /// + /// Scripts will not be executed. + /// + NO_SCRIPTS = 0x00000080, - /// - /// Java applets will not be executed. - /// - NO_JAVA = 0x00000100, + /// + /// Java applets will not be executed. + /// + NO_JAVA = 0x00000100, - /// - /// ActiveX controls will not be executed. - /// - NO_RUNACTIVEXCTLS = 0x00000200, + /// + /// ActiveX controls will not be executed. + /// + NO_RUNACTIVEXCTLS = 0x00000200, - /// - /// ActiveX controls will not be downloaded. - /// - NO_DLACTIVEXCTLS = 0x00000400, + /// + /// ActiveX controls will not be downloaded. + /// + NO_DLACTIVEXCTLS = 0x00000400, - /// - /// The page will only be downloaded, not displayed. - /// - DOWNLOADONLY = 0x00000800, + /// + /// The page will only be downloaded, not displayed. + /// + DOWNLOADONLY = 0x00000800, - /// - /// WebBrowser Control will download and parse a frameSet, but not the individual frame objects within the frameSet. - /// - NO_FRAMEDOWNLOAD = 0x00001000, + /// + /// WebBrowser Control will download and parse a frameSet, but not the individual frame objects within the frameSet. + /// + NO_FRAMEDOWNLOAD = 0x00001000, - /// - /// The server will be asked for update status. Cached files will be used if the server indicates that the cached information is up-to-date. - /// - RESYNCHRONIZE = 0x00002000, + /// + /// The server will be asked for update status. Cached files will be used if the server indicates that the cached information is up-to-date. + /// + RESYNCHRONIZE = 0x00002000, - /// - /// Files will be re-downloaded from the server regardless of the update status of the files. - /// - PRAGMA_NO_CACHE = 0x00004000, + /// + /// Files will be re-downloaded from the server regardless of the update status of the files. + /// + PRAGMA_NO_CACHE = 0x00004000, - /// - /// Behaviors are not downloaded and are disabled in the document. - /// - NO_BEHAVIORS = 0x00008000, + /// + /// Behaviors are not downloaded and are disabled in the document. + /// + NO_BEHAVIORS = 0x00008000, - /// - /// Character sets specified in meta elements are suppressed. - /// - NO_METACHARSET = 0x00010000, + /// + /// Character sets specified in meta elements are suppressed. + /// + NO_METACHARSET = 0x00010000, - /// - /// The browsing component will disable UTF-8 encoding. - /// - URL_ENCODING_DISABLE_UTF8 = 0x00020000, + /// + /// The browsing component will disable UTF-8 encoding. + /// + URL_ENCODING_DISABLE_UTF8 = 0x00020000, - /// - /// The browsing component will enable UTF-8 encoding. - /// - URL_ENCODING_ENABLE_UTF8 = 0x00040000, + /// + /// The browsing component will enable UTF-8 encoding. + /// + URL_ENCODING_ENABLE_UTF8 = 0x00040000, - /// - /// No Documentation Available. - /// - NOFRAMES = 0x00080000, + /// + /// No Documentation Available. + /// + NOFRAMES = 0x00080000, - /// - /// WebBrowser Control always operates in offline mode. - /// - FORCEOFFLINE = 0x10000000, + /// + /// WebBrowser Control always operates in offline mode. + /// + FORCEOFFLINE = 0x10000000, - /// - /// No client pull operations will be performed. - /// - NO_CLIENTPULL = 0x20000000, + /// + /// No client pull operations will be performed. + /// + NO_CLIENTPULL = 0x20000000, - /// - /// No user interface will be displayed during downloads. - /// - SILENT = 0x40000000, + /// + /// No user interface will be displayed during downloads. + /// + SILENT = 0x40000000, + } } diff --git a/src/modules/previewpane/common/controls/WebBrowserExt.cs b/src/modules/previewpane/common/controls/WebBrowserExt.cs index 05a3a3bff4..1904faf0b0 100644 --- a/src/modules/previewpane/common/controls/WebBrowserExt.cs +++ b/src/modules/previewpane/common/controls/WebBrowserExt.cs @@ -6,6 +6,7 @@ using System; using System.Globalization; using System.Reflection; using System.Windows.Forms; +using Common; namespace PreviewHandlerCommon { @@ -52,7 +53,7 @@ namespace PreviewHandlerCommon { object result; - if (name != null && name.Equals(DISPIDAMBIENTDLCONTROL, StringComparison.CurrentCulture)) + if (name != null && name.Equals(DISPIDAMBIENTDLCONTROL, StringComparison.Ordinal)) { // Using InvariantCulture since this is used for web browser configurations result = Convert.ToInt32(