.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.
This commit is contained in:
gokcekantarci
2023-12-28 13:37:13 +03:00
committed by GitHub
parent cd57659ef6
commit a94b3eec39
112 changed files with 429 additions and 291 deletions

View File

@@ -45,6 +45,10 @@ namespace MouseWithoutBorders
private static string lastDragDropFile;
private static long clipboardCopiedTime;
internal static readonly char[] Comma = new char[] { ',' };
internal static readonly char[] Star = new char[] { '*' };
internal static readonly char[] NullSeparator = new char[] { '\0' };
internal static ID LastIDWithClipboardData { get; set; }
internal static string LastDragDropFile
@@ -406,7 +410,7 @@ namespace MouseWithoutBorders
try
{
remoteMachine = postAct.Contains("mspaint,") ? postAct.Split(new char[] { ',' })[1] : Common.LastMachineWithClipboardData;
remoteMachine = postAct.Contains("mspaint,") ? postAct.Split(Comma)[1] : Common.LastMachineWithClipboardData;
remoteMachine = remoteMachine.Trim();
@@ -518,7 +522,7 @@ namespace MouseWithoutBorders
fileName = Common.GetStringU(header).Replace("\0", string.Empty);
Common.LogDebug("Header: " + fileName);
string[] headers = fileName.Split(new char[] { '*' });
string[] headers = fileName.Split(Star);
if (headers.Length < 2 || !long.TryParse(headers[0], out long dataSize))
{
@@ -973,7 +977,7 @@ namespace MouseWithoutBorders
foreach (string txt in texts)
{
if (string.IsNullOrEmpty(txt.Trim(new char[] { '\0' })))
if (string.IsNullOrEmpty(txt.Trim(NullSeparator)))
{
continue;
}

View File

@@ -22,7 +22,9 @@ namespace MouseWithoutBorders
{
internal partial class Common
{
private static SymmetricAlgorithm symAl;
#pragma warning disable SYSLIB0021
private static AesCryptoServiceProvider symAl;
#pragma warning restore SYSLIB0021
private static string myKey;
private static uint magicNumber;
private static Random ran = new(); // Used for non encryption related functionality.

View File

@@ -313,7 +313,8 @@ namespace MouseWithoutBorders
HasSwitchedMachineSinceLastCopy = true;
// Common.CreateLowIntegrityProcess("\"" + Path.GetDirectoryName(Application.ExecutablePath) + "\\MouseWithoutBordersHelper.exe\"", string.Empty, 0, false, 0);
if (Process.GetProcessesByName(HelperProcessName)?.Any() != true)
var processes = Process.GetProcessesByName(HelperProcessName);
if (processes?.Length == 0)
{
Log("Unable to start helper process.");
Common.ShowToolTip("Error starting Mouse Without Borders Helper, clipboard sharing will not work!", 5000, ToolTipIcon.Error);
@@ -325,7 +326,8 @@ namespace MouseWithoutBorders
}
else
{
if (Process.GetProcessesByName(HelperProcessName)?.Any() == true)
var processes = Process.GetProcessesByName(HelperProcessName);
if (processes?.Length > 0)
{
Log("Helper process found running.");
}
@@ -432,7 +434,7 @@ namespace MouseWithoutBorders
{
if (string.IsNullOrEmpty(Setting.Values.Username) && !Common.RunOnLogonDesktop)
{
if (Program.User.ToLower(CultureInfo.CurrentCulture).Contains("system"))
if (Program.User.Contains("system", StringComparison.CurrentCultureIgnoreCase))
{
_ = Common.ImpersonateLoggedOnUserAndDoSomething(() =>
{

View File

@@ -84,12 +84,11 @@ namespace MouseWithoutBorders
}
}
[SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower", Justification = "Dotnet port with style preservation")]
internal static int CreateProcessInInputDesktopSession(string commandLine, string arg, string desktop, short wShowWindow, bool lowIntegrity = false)
// As user who runs explorer.exe
{
if (!Program.User.ToLower(CultureInfo.InvariantCulture).Contains("system"))
if (!Program.User.Contains("system", StringComparison.InvariantCultureIgnoreCase))
{
ProcessStartInfo s = new(commandLine, arg);
s.WindowStyle = wShowWindow != 0 ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden;

View File

@@ -45,7 +45,7 @@ namespace MouseWithoutBorders
{
Process[] ps = Process.GetProcessesByName("MouseWithoutBordersSvc");
if (ps.Any())
if (ps.Length != 0)
{
if (DateTime.UtcNow - lastStartServiceTime < TimeSpan.FromSeconds(5))
{

View File

@@ -353,6 +353,7 @@ namespace MouseWithoutBorders.Class
private static bool ctrlDown;
private static bool altDown;
private static bool shiftDown;
internal static readonly string[] Args = new string[] { "CAD" };
private static void ResetModifiersState(HotkeySettings matchingHotkey)
{
@@ -456,7 +457,7 @@ namespace MouseWithoutBorders.Class
if (ctrlDown && altDown)
{
ctrlDown = altDown = false;
new ServiceController("MouseWithoutBordersSvc").Start(new string[] { "CAD" });
new ServiceController("MouseWithoutBordersSvc").Start(Args);
}
break;

View File

@@ -156,7 +156,7 @@ namespace MouseWithoutBorders.Class
}
else if (list.Count >= 4)
{
throw new ArgumentException("machineNames.Length > Common.MAX_MACHINE");
throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {Common.MAX_MACHINE}. Actual count: {list.Count}.");
}
_ = LearnMachine(name);
@@ -178,7 +178,7 @@ namespace MouseWithoutBorders.Class
}
else if (list.Count >= 4)
{
throw new ArgumentException("infos.Length > Common.MAX_MACHINE");
throw new ArgumentException($"The number of machines exceeded the maximum allowed limit of {Common.MAX_MACHINE}. Actual count: {list.Count}.");
}
_ = LearnMachine(inf.Name);

View File

@@ -8,6 +8,9 @@ namespace MouseWithoutBorders.Class
{
internal static class MachinePoolHelpers
{
internal static readonly char[] Comma = new char[] { ',' };
internal static readonly char[] Colon = new char[] { ':' };
internal static MachineInf[] LoadMachineInfoFromMachinePoolStringSetting(string s)
{
if (s == null)
@@ -15,7 +18,7 @@ namespace MouseWithoutBorders.Class
throw new ArgumentNullException(s);
}
string[] st = s.Split(new char[] { ',' });
string[] st = s.Split(Comma);
if (st.Length < Common.MAX_MACHINE)
{
@@ -25,7 +28,7 @@ namespace MouseWithoutBorders.Class
MachineInf[] rv = new MachineInf[Common.MAX_MACHINE];
for (int i = 0; i < Common.MAX_MACHINE; i++)
{
string[] mc = st[i].Split(new char[] { ':' });
string[] mc = st[i].Split(Colon);
if (mc.Length == 2)
{
rv[i].Name = mc[0];

View File

@@ -38,7 +38,7 @@ namespace MouseWithoutBorders.Class
{
internal bool Changed;
private readonly ISettingsUtils _settingsUtils;
private readonly SettingsUtils _settingsUtils;
private readonly object _loadingSettingsLock = new object();
private readonly IFileSystemWatcher _watcher;

View File

@@ -887,14 +887,14 @@ namespace MouseWithoutBorders.Class
if (!string.IsNullOrEmpty(Setting.Values.Name2IP))
{
string[] name2ip = Setting.Values.Name2IP.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] name2ip = Setting.Values.Name2IP.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
string[] nameNip;
if (name2ip != null)
{
foreach (string st in name2ip)
{
nameNip = st.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
nameNip = st.Split(BlankSeparator, StringSplitOptions.RemoveEmptyEntries);
if (nameNip != null && nameNip.Length >= 2 && nameNip[0].Trim().Equals(machineName, StringComparison.OrdinalIgnoreCase)
&& IPAddress.TryParse(nameNip[1].Trim(), out IPAddress ip) && !validAddressesSt.Contains("[" + ip.ToString() + "]")
@@ -1063,7 +1063,7 @@ namespace MouseWithoutBorders.Class
List<IPAddress> localIPv4Addresses = GetMyIPv4Addresses().ToList();
if (!localIPv4Addresses.Any())
if (localIPv4Addresses.Count == 0)
{
Common.Log($"No IPv4 resolved from the local machine: {Common.MachineName}");
return true;
@@ -1234,6 +1234,8 @@ namespace MouseWithoutBorders.Class
}
private long lastRemoteMachineID;
internal static readonly string[] Separator = new string[] { "\r\n" };
internal static readonly char[] BlankSeparator = new char[] { ' ' };
private void MainTCPRoutine(TcpSk tcp, string machineName, bool isClient)
{

View File

@@ -104,6 +104,7 @@ namespace MouseWithoutBorders.Class
}
private static bool logged;
internal static readonly string[] Separator = new[] { " " };
private void LogError(string log)
{
@@ -146,7 +147,7 @@ namespace MouseWithoutBorders.Class
try
{
// Assuming the format of netstat's output is fixed.
pid = int.Parse(portLogLine.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Last(), CultureInfo.CurrentCulture);
pid = int.Parse(portLogLine.Split(Separator, StringSplitOptions.RemoveEmptyEntries).Last(), CultureInfo.CurrentCulture);
process = Process.GetProcessById(pid);
}
catch (Exception)