mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-23 00:24:41 +01:00
fix(sonar): no exact float compares, xrandr from its own path, its regexes timed
The quality gate of SonarCloud stopped on three exact compares of doubles (S1244), the regexes reading xrandr without a timeout (S6444) and xrandr run from whatever PATH finds (S4036). The compares meant to tell one number from another keep doing so with Equals; the scroll lane's margin is compared within a tenth of a pixel. xrandr is run from where distributions put it, or not at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -382,7 +382,7 @@ public sealed class SettingsStore
|
||||
if (string.Equals(a[i], b[i], StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
if (double.TryParse(a[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double x) &&
|
||||
double.TryParse(b[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double y) && x == y)
|
||||
double.TryParse(b[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double y) && x.Equals(y))
|
||||
continue;
|
||||
if (Bool(a[i]) is { } p && p == Bool(b[i]))
|
||||
continue;
|
||||
|
||||
@@ -138,15 +138,24 @@ public static class Monitors
|
||||
|
||||
// ── Linux: the connected RandR outputs, as x11_monitor.c of GLFW names them ──
|
||||
|
||||
// A line of xrandr is short; one that takes longer than this to match is no report of monitors.
|
||||
private static readonly TimeSpan MatchTimeout = TimeSpan.FromSeconds(1);
|
||||
|
||||
private static readonly Regex Output = new(
|
||||
@"^(\S+) connected (primary )?(\d+)x(\d+)\+(\d+)\+(\d+)", RegexOptions.CultureInvariant);
|
||||
@"^(\S+) connected (primary )?(\d+)x(\d+)\+(\d+)\+(\d+)", RegexOptions.CultureInvariant, MatchTimeout);
|
||||
|
||||
// A mode line under an output: the rate in use is the one marked with a star.
|
||||
private static readonly Regex CurrentRate = new(@"^\s+\S+.*?\s(\d+(?:\.\d+)?)\*", RegexOptions.CultureInvariant);
|
||||
private static readonly Regex CurrentRate = new(@"^\s+\S+.*?\s(\d+(?:\.\d+)?)\*", RegexOptions.CultureInvariant, MatchTimeout);
|
||||
|
||||
// Where distributions put xrandr: run from there, not from whatever PATH finds first.
|
||||
private static readonly string[] XrandrPlaces = { "/usr/bin/xrandr", "/usr/local/bin/xrandr", "/bin/xrandr" };
|
||||
|
||||
private static IReadOnlyList<DisplayMonitor> FromXrandr()
|
||||
{
|
||||
using var process = Process.Start(new ProcessStartInfo("xrandr", "--query")
|
||||
string? xrandr = Array.Find(XrandrPlaces, System.IO.File.Exists);
|
||||
if (xrandr is null)
|
||||
return Array.Empty<DisplayMonitor>();
|
||||
using var process = Process.Start(new ProcessStartInfo(xrandr, "--query")
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
|
||||
@@ -443,7 +443,7 @@ public sealed class SettingsSerializer
|
||||
return tokens.Length >= 2 &&
|
||||
TryParseMouseScale(tokens[0], out _) &&
|
||||
TryParseMouseScale(tokens[1], out double y) &&
|
||||
Math.Abs(y) == SimulatorSettings.MouseScaleY;
|
||||
Math.Abs(y).Equals(SimulatorSettings.MouseScaleY);
|
||||
}
|
||||
|
||||
private static bool TryParseMouseScale(string token, out double scale) =>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia;
|
||||
using Avalonia.Automation;
|
||||
@@ -84,7 +85,7 @@ internal static class TrainsetRow
|
||||
scroller.ScrollChanged += (_, _) =>
|
||||
{
|
||||
double below = scroller.Extent.Width > scroller.Viewport.Width + 0.5 ? ScrollBarLane : 0;
|
||||
if (strip.Margin.Bottom != below)
|
||||
if (Math.Abs(strip.Margin.Bottom - below) > 0.1)
|
||||
strip.Margin = new Thickness(0, 0, 0, below);
|
||||
};
|
||||
return scroller;
|
||||
|
||||
Reference in New Issue
Block a user