Fix CA1305 and bump to error

This commit is contained in:
Morilli 2023-06-08 19:08:26 +02:00 committed by Moritz Bender
parent 8e557b0b9d
commit 6e20a3091c
17 changed files with 54 additions and 41 deletions

View File

@ -13,5 +13,7 @@ csharp_indent_case_contents = true
csharp_indent_labels = one_less_than_current
# Globalization rules
dotnet_diagnostic.CA1305.severity = silent
dotnet_code_quality.CA1305.excluded_symbol_names = T:System.Byte|T:System.SByte|T:System.Int16|T:System.UInt16|T:System.Int32|T:System.UInt32|T:System.Int64|T:System.UInt64|T:System.String|T:System.Text.StringBuilder|T:System.Convert
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA2101.severity = suggestion

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Text.RegularExpressions;
@ -234,7 +235,7 @@ namespace BizHawk.Client.Common.Filters
private static float FetchFloat(IDictionary<string, string> dict, string key, float @default)
{
return dict.TryGetValue(key, out var str) ? float.Parse(str) : @default;
return dict.TryGetValue(key, out var str) ? float.Parse(str, NumberFormatInfo.InvariantInfo) : @default;
}
private static bool FetchBool(IDictionary<string, string> dict, string key, bool @default)

View File

@ -1,4 +1,5 @@
using System.IO;
using System.Globalization;
using System.IO;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Sony.PSX;
@ -350,10 +351,10 @@ namespace BizHawk.Client.Common
string rightXRaw = player1Str.Substring(24, 4);
string rightYRaw = player1Str.Substring(28, 4);
var leftX = ("P1 LStick X", (int) float.Parse(leftXRaw));
var leftY = ("P1 LStick Y", (int) float.Parse(leftYRaw));
var rightX = ("P1 RStick X", (int) float.Parse(rightXRaw));
var rightY = ("P1 RStick Y", (int) float.Parse(rightYRaw));
var leftX = ("P1 LStick X", (int) float.Parse(leftXRaw, NumberFormatInfo.InvariantInfo));
var leftY = ("P1 LStick Y", (int) float.Parse(leftYRaw, NumberFormatInfo.InvariantInfo));
var rightX = ("P1 RStick X", (int) float.Parse(rightXRaw, NumberFormatInfo.InvariantInfo));
var rightY = ("P1 RStick Y", (int) float.Parse(rightYRaw, NumberFormatInfo.InvariantInfo));
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
}
@ -385,10 +386,10 @@ namespace BizHawk.Client.Common
string rightXRaw = player2Str.Substring(24, 4);
string rightYRaw = player2Str.Substring(28, 4);
var leftX = ("P2 LStick X", (int) float.Parse(leftXRaw));
var leftY = ("P2 LStick Y", (int) float.Parse(leftYRaw));
var rightX = ("P2 RStick X", (int) float.Parse(rightXRaw));
var rightY = ("P2 RStick Y", (int) float.Parse(rightYRaw));
var leftX = ("P2 LStick X", (int) float.Parse(leftXRaw, NumberFormatInfo.InvariantInfo));
var leftY = ("P2 LStick Y", (int) float.Parse(leftYRaw, NumberFormatInfo.InvariantInfo));
var rightX = ("P2 RStick X", (int) float.Parse(rightXRaw, NumberFormatInfo.InvariantInfo));
var rightY = ("P2 RStick Y", (int) float.Parse(rightYRaw, NumberFormatInfo.InvariantInfo));
controllers.AcceptNewAxes(new[] { leftX, leftY, rightX, rightY });
}

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using BizHawk.Common;
@ -76,7 +77,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
{
//make a menuitem to show the last modified timestamp
var timestamp = File.GetLastWriteTime(hf.FullPathWithoutMember);
var tsmiTimestamp = new ToolStripLabel { Text = timestamp.ToString() };
var tsmiTimestamp = new ToolStripLabel { Text = timestamp.ToString(DateTimeFormatInfo.InvariantInfo) };
tsdd.Items.Add(tsmiTimestamp);
tsdd.Items.Add(new ToolStripSeparator());

View File

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
@ -98,9 +99,9 @@ namespace BizHawk.Client.EmuHawk
if (_config.DispCustomUserARHeight != -1)
txtCustomARHeight.Text = _config.DispCustomUserARHeight.ToString();
if (_config.DispCustomUserArx != -1)
txtCustomARX.Text = _config.DispCustomUserArx.ToString();
txtCustomARX.Text = _config.DispCustomUserArx.ToString(NumberFormatInfo.InvariantInfo);
if (_config.DispCustomUserAry != -1)
txtCustomARY.Text = _config.DispCustomUserAry.ToString();
txtCustomARY.Text = _config.DispCustomUserAry.ToString(NumberFormatInfo.InvariantInfo);
txtCropLeft.Text = _config.DispCropLeft.ToString();
txtCropTop.Text = _config.DispCropTop.ToString();

View File

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@ -76,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
}
private static string MovieTimeLengthStr(TimeSpan movieLength)
=> movieLength.ToString(movieLength.Days == 0 ? @"hh\:mm\:ss\.fff" : @"dd\:hh\:mm\:ss\.fff");
=> movieLength.ToString(movieLength.Days == 0 ? @"hh\:mm\:ss\.fff" : @"dd\:hh\:mm\:ss\.fff", DateTimeFormatInfo.InvariantInfo);
private void MovieView_QueryItemText(object sender, RetrieveVirtualItemEventArgs e)
{
@ -104,7 +105,7 @@ namespace BizHawk.Client.EmuHawk
{
return null;
}
var movie = LoadMovieInfo(file, force);
if (movie == null)
{
@ -257,7 +258,7 @@ namespace BizHawk.Client.EmuHawk
while (dpTodo.Count > 0)
{
string dp = dpTodo.Dequeue();
// enqueue subdirectories if appropriate
if (_config.PlayMovieIncludeSubDir)
{

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using BizHawk.Client.Common;
@ -110,7 +111,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
_values[PatternList.SelectedIndex] = ValueNum.Value.ToString();
_values[PatternList.SelectedIndex] = ValueNum.Value.ToString(NumberFormatInfo.InvariantInfo);
UpdatePattern();
UpdateDisplay();
}

View File

@ -3,7 +3,7 @@ using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Globalization;
using BizHawk.Emulation.Common;
using BizHawk.Common.NumberExtensions;
using BizHawk.Client.Common;
@ -356,7 +356,7 @@ namespace BizHawk.Client.EmuHawk
if (column.Type == ColumnType.Axis)
{
// feos: this could be cached, but I don't notice any slowdown this way either
if (text == ((float) ControllerType.Axes[columnName].Neutral).ToString())
if (text == ((float) ControllerType.Axes[columnName].Neutral).ToString(NumberFormatInfo.InvariantInfo))
{
text = "";
}
@ -1297,12 +1297,12 @@ namespace BizHawk.Client.EmuHawk
if (e.KeyCode == Keys.Right)
{
value = rMax;
_axisTypedValue = value.ToString();
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
else if (e.KeyCode == Keys.Left)
{
value = rMin;
_axisTypedValue = value.ToString();
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
else if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
{
@ -1332,7 +1332,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_axisTypedValue == "") // Very first key press is backspace?
{
_axisTypedValue = value.ToString();
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
_axisTypedValue = _axisTypedValue.Substring(0, _axisTypedValue.Length - 1);
@ -1384,7 +1384,7 @@ namespace BizHawk.Client.EmuHawk
value += changeBy;
if (changeBy != 0)
{
_axisTypedValue = value.ToString();
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
}
@ -1404,7 +1404,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (float.TryParse(_axisTypedValue, out value)) // String "-" can't be parsed.
if (float.TryParse(_axisTypedValue, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out value)) // String "-" can't be parsed.
{
if (value > rMax)
{
@ -1415,7 +1415,7 @@ namespace BizHawk.Client.EmuHawk
value = rMin;
}
_axisTypedValue = value.ToString();
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
CurrentTasMovie.SetAxisState(_axisEditRow, _axisEditColumn, (int) value);
}
}

View File

@ -9,7 +9,7 @@ namespace BizHawk.Common
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
if (value is not DateTime d || destinationType != typeof(string)) throw new NotSupportedException("can only do DateTime --> string");
return d.ToString();
return d.ToString(DateTimeFormatInfo.InvariantInfo);
}
}
}

View File

@ -50,7 +50,7 @@ namespace BizHawk.Common
if (destinationType == typeof(string))
{
var num = Convert.ToSingle(value);
return num.ToString();
return num.ToString(NumberFormatInfo.InvariantInfo);
}
return base.ConvertTo(context, culture, value, destinationType)!;

View File

@ -1230,7 +1230,7 @@ namespace BizHawk.Common
{
if (Present(name))
{
val = float.Parse(Item(name));
val = float.Parse(Item(name), NumberFormatInfo.InvariantInfo);
}
}
@ -1243,7 +1243,7 @@ namespace BizHawk.Common
{
if (Present(name))
{
val = double.Parse(Item(name));
val = double.Parse(Item(name), NumberFormatInfo.InvariantInfo);
}
}

View File

@ -1,3 +1,4 @@
using System.Globalization;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
@ -420,7 +421,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
if (end != 0)
p = ((double)pos / (double)end) * 100.0;
sb.Append(p.ToString("N0") + "%");
sb.Append(p.ToString("N0", NumberFormatInfo.InvariantInfo) + "%");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
sb.Clear();
@ -443,7 +444,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// work out overall position within the tape
p = 0;
p = ((double)ourPos / (double)cnt) * 100.0;
sb.Append(p.ToString("N0") + "%");
sb.Append(p.ToString("N0", NumberFormatInfo.InvariantInfo) + "%");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
@ -16,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
*/
public partial class NECUPD765 : IPortIODevice
{
public string outputfile = @"D:\Dropbox\Dropbox\_Programming\TASVideos\BizHawk\output\zxhawkio-" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
public string outputfile = @"D:\Dropbox\Dropbox\_Programming\TASVideos\BizHawk\output\zxhawkio-" + DateTime.Now.ToString("yyyyMMdd_HHmmss", DateTimeFormatInfo.InvariantInfo) + ".csv";
public string outputString = "STATUS,WRITE,READ,CODE,MT,MF,SK,CMDCNT,RESCNT,EXECCNT,EXECLEN\r\n";
public bool writeDebug = false;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -16,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
*/
public partial class NECUPD765 : IPortIODevice
{
public string outputfile = @"D:\Dropbox\Dropbox\_Programming\TASVideos\BizHawk\output\zxhawkio-" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
public string outputfile = @"D:\Dropbox\Dropbox\_Programming\TASVideos\BizHawk\output\zxhawkio-" + DateTime.Now.ToString("yyyyMMdd_HHmmss", DateTimeFormatInfo.InvariantInfo) + ".csv";
public string outputString = "STATUS,WRITE,READ,CODE,MT,MF,SK,CMDCNT,RESCNT,EXECCNT,EXECLEN\r\n";
public bool writeDebug = false;

View File

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -392,7 +393,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (end != 0)
p = ((double)pos / (double)end) * 100.0;
sb.Append(p.ToString("N0") + "%");
sb.Append(p.ToString("N0", NumberFormatInfo.InvariantInfo) + "%");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
sb.Clear();
@ -415,7 +416,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// work out overall position within the tape
p = 0;
p = ((double)ourPos / (double)cnt) * 100.0;
sb.Append(p.ToString("N0") + "%");
sb.Append(p.ToString("N0", NumberFormatInfo.InvariantInfo) + "%");
SendMessage(sb.ToString().TrimEnd('\n'), MessageCategory.Tape);
}

View File

@ -295,9 +295,9 @@ namespace BizHawk.Emulation.Cores.Waterbox
public override Type PropertyType => typeof(double);
protected override object ConvertFromString(string s)
{
var ret = double.Parse(s);
if (Setting.Min != null && ret < double.Parse(Setting.Min) || Setting.Max != null && ret > double.Parse(Setting.Max))
ret = double.Parse(Setting.DefaultValue);
var ret = double.Parse(s, NumberFormatInfo.InvariantInfo);
if (Setting.Min != null && ret < double.Parse(Setting.Min, NumberFormatInfo.InvariantInfo) || Setting.Max != null && ret > double.Parse(Setting.Max, NumberFormatInfo.InvariantInfo))
ret = double.Parse(Setting.DefaultValue, NumberFormatInfo.InvariantInfo);
return ret;
}
protected override string ConvertToString(object o)

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@ -166,10 +167,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
if (_disks != null)
_nyma.SetCDCallbacks(_cdTocCallback, _cdSectorCallback);
PutSettings(_settings);
DateTime RtcStart = DateTime.Parse("2010-01-01");
DateTime RtcStart = DateTime.Parse("2010-01-01", DateTimeFormatInfo.InvariantInfo);
try
{
RtcStart = DateTime.Parse(SettingsQuery("nyma.rtcinitialtime"));
RtcStart = DateTime.Parse(SettingsQuery("nyma.rtcinitialtime"), DateTimeFormatInfo.InvariantInfo);
}
catch
{