Skip to content

Commit a94b3ee

Browse files
.NET 8 Upgrade Silenced Errors Fix (#30469)
* [Dev][Build] .NET 8 Upgrade Silenced errors first fix. * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1859 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1854. * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1860 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1861 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1862 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1863 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1864 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA1865 * [Dev][Build] .NET 8 Upgrade Silenced errors. CA2208 * [Dev][Build] .NET 8 Upgrade Silenced errors. CS9191 * [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check * [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check * [Dev][Build] .NET 8 Upgrade Silenced errors. - CompositeFormat variables used more than once in the same file were assigned to a single variable. - GetProcessesByName logic fix. - String comparion fix. - ArgumentOutOfRangeException message change. * [Dev][Build] .NET 8 Upgrade Silenced errors. - Null check added. - static readonly CompositeFormat added for all fields.
1 parent cd57659 commit a94b3ee

File tree

112 files changed

+429
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+429
-291
lines changed

src/.editorconfig

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -96,49 +96,4 @@ end_of_line = crlf
9696
dotnet_diagnostic.IDE0065.severity = none
9797

9898
# IDE0009: Add this or Me qualification
99-
dotnet_diagnostic.IDE0009.severity = none
100-
101-
# CA1859: Change type for improved performance
102-
dotnet_diagnostic.CA1859.severity = none
103-
104-
# CA1716: Identifiers should not match keywords
105-
dotnet_diagnostic.CA1716.severity = none
106-
107-
# SYSLIB1096: Convert to 'GeneratedComInterface'
108-
dotnet_diagnostic.SYSLIB1096.severity = silent
109-
110-
# CA1309: Use ordinal StringComparison
111-
dotnet_diagnostic.CA1309.severity = suggestion
112-
113-
# CS1615: Argument may not be passed with the ref keyword
114-
dotnet_diagnostic.CS1615.severity = none
115-
116-
# CA1854: Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup
117-
dotnet_diagnostic.CA1854.severity = suggestion
118-
119-
# CA1860: Avoid using 'Enumerable.Any()' extension method
120-
dotnet_diagnostic.CA1860.severity = suggestion
121-
122-
# CA1861: Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array
123-
dotnet_diagnostic.CA1861.severity = suggestion
124-
125-
# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
126-
dotnet_diagnostic.CA1862.severity = suggestion
127-
128-
# CA1863: Cache a CompositeFormat for repeated use in this formatting operation
129-
dotnet_diagnostic.CA1863.severity = none
130-
131-
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
132-
dotnet_diagnostic.CA1864.severity = suggestion
133-
134-
# CA1865: Use 'string.Method(char)' instead of 'string.Method(string)' for string with single char
135-
dotnet_diagnostic.CA1865.severity = suggestion
136-
137-
# CA1869: Cache and reuse 'JsonSerializerOptions' instances
138-
dotnet_diagnostic.CA1869.severity = none
139-
140-
# CA2208: Instantiate argument exceptions correctly
141-
dotnet_diagnostic.CA2208.severity = none
142-
143-
# CS9191: The 'ref' modifier for argument corresponding to 'in' is equivalent to 'in'. Consider using 'in' instead.
144-
dotnet_diagnostic.CS9191.severity = none
99+
dotnet_diagnostic.IDE0009.severity = none

src/common/AllExperiments/Experiments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private async Task VariantAssignmentProvider_Initialize()
145145

146146
private string? AssignmentUnit { get; set; }
147147

148-
private IVariantAssignmentRequest GetVariantAssignmentRequest()
148+
private VariantAssignmentRequest GetVariantAssignmentRequest()
149149
{
150150
var jsonFilePath = CreateFilePath();
151151
try

src/common/FilePreviewCommon/Formatters/JsonFormatter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ public class JsonFormatter : IFormatter
1212
/// <inheritdoc/>
1313
public string LangSet => "json";
1414

15+
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
16+
{
17+
WriteIndented = true,
18+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
19+
};
20+
1521
/// <inheritdoc/>
1622
public string Format(string value)
1723
{
@@ -22,11 +28,7 @@ public string Format(string value)
2228

2329
using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
2430
{
25-
return JsonSerializer.Serialize(jDocument, new JsonSerializerOptions
26-
{
27-
WriteIndented = true,
28-
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
29-
});
31+
return JsonSerializer.Serialize(jDocument, _serializerOptions);
3032
}
3133
}
3234
}

src/modules/Hosts/Hosts/Settings/UserSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class UserSettings : IUserSettings
1717
private const string HostsModuleName = "Hosts";
1818
private const int MaxNumberOfRetry = 5;
1919

20-
private readonly ISettingsUtils _settingsUtils;
20+
private readonly SettingsUtils _settingsUtils;
2121
private readonly IFileSystemWatcher _watcher;
2222
private readonly object _loadingSettingsLock = new object();
2323

src/modules/MouseWithoutBorders/App/Class/Common.Clipboard.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ internal partial class Common
4545
private static string lastDragDropFile;
4646
private static long clipboardCopiedTime;
4747

48+
internal static readonly char[] Comma = new char[] { ',' };
49+
internal static readonly char[] Star = new char[] { '*' };
50+
internal static readonly char[] NullSeparator = new char[] { '\0' };
51+
4852
internal static ID LastIDWithClipboardData { get; set; }
4953

5054
internal static string LastDragDropFile
@@ -406,7 +410,7 @@ private static void ConnectAndGetData(object postAction)
406410

407411
try
408412
{
409-
remoteMachine = postAct.Contains("mspaint,") ? postAct.Split(new char[] { ',' })[1] : Common.LastMachineWithClipboardData;
413+
remoteMachine = postAct.Contains("mspaint,") ? postAct.Split(Comma)[1] : Common.LastMachineWithClipboardData;
410414

411415
remoteMachine = remoteMachine.Trim();
412416

@@ -518,7 +522,7 @@ internal static void ReceiveAndProcessClipboardData(string remoteMachine, Socket
518522

519523
fileName = Common.GetStringU(header).Replace("\0", string.Empty);
520524
Common.LogDebug("Header: " + fileName);
521-
string[] headers = fileName.Split(new char[] { '*' });
525+
string[] headers = fileName.Split(Star);
522526

523527
if (headers.Length < 2 || !long.TryParse(headers[0], out long dataSize))
524528
{
@@ -973,7 +977,7 @@ internal static void SetClipboardData(byte[] data)
973977

974978
foreach (string txt in texts)
975979
{
976-
if (string.IsNullOrEmpty(txt.Trim(new char[] { '\0' })))
980+
if (string.IsNullOrEmpty(txt.Trim(NullSeparator)))
977981
{
978982
continue;
979983
}

src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace MouseWithoutBorders
2222
{
2323
internal partial class Common
2424
{
25-
private static SymmetricAlgorithm symAl;
25+
#pragma warning disable SYSLIB0021
26+
private static AesCryptoServiceProvider symAl;
27+
#pragma warning restore SYSLIB0021
2628
private static string myKey;
2729
private static uint magicNumber;
2830
private static Random ran = new(); // Used for non encryption related functionality.

src/modules/MouseWithoutBorders/App/Class/Common.Helper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ internal static void RunDDHelper(bool cleanUp = false)
313313
HasSwitchedMachineSinceLastCopy = true;
314314

315315
// Common.CreateLowIntegrityProcess("\"" + Path.GetDirectoryName(Application.ExecutablePath) + "\\MouseWithoutBordersHelper.exe\"", string.Empty, 0, false, 0);
316-
if (Process.GetProcessesByName(HelperProcessName)?.Any() != true)
316+
var processes = Process.GetProcessesByName(HelperProcessName);
317+
if (processes?.Length == 0)
317318
{
318319
Log("Unable to start helper process.");
319320
Common.ShowToolTip("Error starting Mouse Without Borders Helper, clipboard sharing will not work!", 5000, ToolTipIcon.Error);
@@ -325,7 +326,8 @@ internal static void RunDDHelper(bool cleanUp = false)
325326
}
326327
else
327328
{
328-
if (Process.GetProcessesByName(HelperProcessName)?.Any() == true)
329+
var processes = Process.GetProcessesByName(HelperProcessName);
330+
if (processes?.Length > 0)
329331
{
330332
Log("Helper process found running.");
331333
}
@@ -432,7 +434,7 @@ internal static bool GetUserName()
432434
{
433435
if (string.IsNullOrEmpty(Setting.Values.Username) && !Common.RunOnLogonDesktop)
434436
{
435-
if (Program.User.ToLower(CultureInfo.CurrentCulture).Contains("system"))
437+
if (Program.User.Contains("system", StringComparison.CurrentCultureIgnoreCase))
436438
{
437439
_ = Common.ImpersonateLoggedOnUserAndDoSomething(() =>
438440
{

src/modules/MouseWithoutBorders/App/Class/Common.Launch.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ internal static bool ImpersonateLoggedOnUserAndDoSomething(Action targetFunc)
8484
}
8585
}
8686

87-
[SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower", Justification = "Dotnet port with style preservation")]
8887
internal static int CreateProcessInInputDesktopSession(string commandLine, string arg, string desktop, short wShowWindow, bool lowIntegrity = false)
8988

9089
// As user who runs explorer.exe
9190
{
92-
if (!Program.User.ToLower(CultureInfo.InvariantCulture).Contains("system"))
91+
if (!Program.User.Contains("system", StringComparison.InvariantCultureIgnoreCase))
9392
{
9493
ProcessStartInfo s = new(commandLine, arg);
9594
s.WindowStyle = wShowWindow != 0 ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden;

src/modules/MouseWithoutBorders/App/Class/Common.Service.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal static void StartMouseWithoutBordersService(string desktopToRunMouseWit
4545
{
4646
Process[] ps = Process.GetProcessesByName("MouseWithoutBordersSvc");
4747

48-
if (ps.Any())
48+
if (ps.Length != 0)
4949
{
5050
if (DateTime.UtcNow - lastStartServiceTime < TimeSpan.FromSeconds(5))
5151
{

src/modules/MouseWithoutBorders/App/Class/InputSimulation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ internal static void MouseClickDotForm(int x, int y)
353353
private static bool ctrlDown;
354354
private static bool altDown;
355355
private static bool shiftDown;
356+
internal static readonly string[] Args = new string[] { "CAD" };
356357

357358
private static void ResetModifiersState(HotkeySettings matchingHotkey)
358359
{
@@ -456,7 +457,7 @@ private static void InputProcessKeyEx(int vkCode, int flags, out bool eatKey)
456457
if (ctrlDown && altDown)
457458
{
458459
ctrlDown = altDown = false;
459-
new ServiceController("MouseWithoutBordersSvc").Start(new string[] { "CAD" });
460+
new ServiceController("MouseWithoutBordersSvc").Start(Args);
460461
}
461462

462463
break;

0 commit comments

Comments
 (0)