more build fixes

This commit is contained in:
Adam Hathcock
2026-02-16 11:15:58 +00:00
parent 5c1547c284
commit 7f286da74e
23 changed files with 142 additions and 25 deletions

View File

@@ -265,12 +265,12 @@ dotnet_diagnostic.CA1051.severity = suggestion # do not declare visible instance
dotnet_diagnostic.CA1068.severity = error # cancellation token parameters must come last
dotnet_diagnostic.CA1069.severity = error # enums should not have duplicate values
dotnet_diagnostic.CA1304.severity = error # specify CultureInfo for culture-sensitive operations
dotnet_diagnostic.CA1305.severity = suggestion # specify IFormatProvider
dotnet_diagnostic.CA1307.severity = suggestion # specify StringComparison for clarity
dotnet_diagnostic.CA1305.severity = error # specify IFormatProvider
dotnet_diagnostic.CA1307.severity = error # specify StringComparison for clarity
dotnet_diagnostic.CA1309.severity = error # use ordinal StringComparison
dotnet_diagnostic.CA1310.severity = error # specify StringComparison for correctness
dotnet_diagnostic.CA1507.severity = error # use nameof in place of string literals
dotnet_diagnostic.CA1513.severity = suggestion # use ObjectDisposedException throw helper
dotnet_diagnostic.CA1513.severity = error # use ObjectDisposedException throw helper
dotnet_diagnostic.CA1707.severity = suggestion # identifiers should not contain underscores
dotnet_diagnostic.CA1708.severity = suggestion # identifiers should differ by more than case
dotnet_diagnostic.CA1711.severity = suggestion # identifiers should not have incorrect suffixes
@@ -405,6 +405,8 @@ dotnet_diagnostic.VSTHRD200.severity = none # use Async suffix naming convention
[tests/**/*.cs]
dotnet_diagnostic.CA1861.severity = suggestion # avoid constant arrays as arguments
dotnet_diagnostic.CA1305.severity = suggestion # specify IFormatProvider
dotnet_diagnostic.CA1307.severity = suggestion # specify StringComparison for clarity
dotnet_diagnostic.IDE0042.severity = suggestion
dotnet_diagnostic.IDE0051.severity = suggestion
dotnet_diagnostic.IDE0063.severity = suggestion

View File

@@ -593,7 +593,7 @@ static Dictionary<string, BenchmarkMetric> ParseBenchmarkResults(string markdown
var parts = line.Split('|', StringSplitOptions.TrimEntries);
if (parts.Length >= 5)
{
var method = parts[1].Replace("&#39;", "'");
var method = parts[1].Replace("&#39;", "'", StringComparison.Ordinal);
var meanStr = parts[2];
// Find Allocated column - it's usually the last column or labeled "Allocated"
@@ -604,7 +604,7 @@ static Dictionary<string, BenchmarkMetric> ParseBenchmarkResults(string markdown
parts[j].Contains("KB", StringComparison.Ordinal)
|| parts[j].Contains("MB", StringComparison.Ordinal)
|| parts[j].Contains("GB", StringComparison.Ordinal)
|| parts[j].Contains('B')
|| parts[j].Contains('B', StringComparison.Ordinal)
)
{
memoryStr = parts[j];
@@ -642,7 +642,7 @@ static double ParseTimeValue(string timeStr)
}
// Remove thousands separators and parse
timeStr = timeStr.Replace(",", "").Trim();
timeStr = timeStr.Replace(",", "", StringComparison.Ordinal).Trim();
var match = Regex.Match(timeStr, @"([\d.]+)\s*(\w+)");
if (!match.Success)
@@ -671,7 +671,7 @@ static double ParseMemoryValue(string memStr)
return 0;
}
memStr = memStr.Replace(",", "").Trim();
memStr = memStr.Replace(",", "", StringComparison.Ordinal).Trim();
var match = Regex.Match(memStr, @"([\d.]+)\s*(\w+)");
if (!match.Success)

View File

@@ -19,7 +19,9 @@ internal abstract class ArchiveVolumeFactory
part1.DirectoryName!,
String.Concat(
m.Groups[1].Value,
(index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0')
(index + 1)
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
.PadLeft(m.Groups[2].Value.Length, '0')
)
)
);

View File

@@ -19,7 +19,9 @@ internal static class RarArchiveVolumeFactory
part1.DirectoryName!,
String.Concat(
m.Groups[1].Value,
(index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0'),
(index + 1)
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
.PadLeft(m.Groups[2].Value.Length, '0'),
m.Groups[3].Value
)
)
@@ -39,7 +41,15 @@ internal static class RarArchiveVolumeFactory
index == 0
? m.Groups[2].Value + m.Groups[3].Value
: (char)(m.Groups[2].Value[0] + ((index - 1) / 100))
+ (index - 1).ToString("D4").Substring(2)
+ (index - 1)
.ToString(
"D4",
global::SharpCompress
.Common
.Constants
.DefaultCultureInfo
)
.Substring(2)
)
)
);

View File

@@ -21,7 +21,9 @@ internal static class ZipArchiveVolumeFactory
String.Concat(
m.Groups[1].Value,
Regex.Replace(m.Groups[2].Value, @"[^xz]", ""),
index.ToString().PadLeft(2, '0')
index
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
.PadLeft(2, '0')
)
)
);

View File

@@ -32,5 +32,5 @@ public class DosDateTime
}
}
public override string ToString() => DateTime.ToString("yyyy-MM-dd HH:mm:ss");
public override string ToString() => DateTime.ToString("yyyy-MM-dd HH:mm:ss", Constants.DefaultCultureInfo);
}

View File

@@ -1,3 +1,5 @@
using System.Globalization;
namespace SharpCompress.Common;
public static class Constants
@@ -38,4 +40,6 @@ public static class Constants
/// </para>
/// </remarks>
public static int RewindableBufferSize { get; set; } = 81920;
public static CultureInfo DefaultCultureInfo { get; set; } = CultureInfo.InvariantCulture;
}

View File

@@ -46,7 +46,11 @@ internal static class FlagUtility
/// <param name="flag">Flag to test</param>
/// <returns></returns>
public static bool HasFlag<T>(T bitField, T flag)
where T : struct => HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag));
where T : struct =>
HasFlag(
Convert.ToInt64(bitField, Constants.DefaultCultureInfo),
Convert.ToInt64(flag, Constants.DefaultCultureInfo)
);
/// <summary>
/// Returns true if the flag is set on the specified bit field.
@@ -82,5 +86,10 @@ internal static class FlagUtility
/// <param name="on">bool</param>
/// <returns>The flagged variable with the flag changed</returns>
public static long SetFlag<T>(T bitField, T flag, bool on)
where T : struct => SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), on);
where T : struct =>
SetFlag(
Convert.ToInt64(bitField, Constants.DefaultCultureInfo),
Convert.ToInt64(flag, Constants.DefaultCultureInfo),
on
);
}

View File

@@ -76,6 +76,7 @@ public abstract class RarEntry : Entry
public override string ToString() =>
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}",
Key,
CompressedSize,

View File

@@ -457,7 +457,7 @@ internal sealed partial class TarHeader
{
return 0;
}
return Convert.ToInt64(s);
return Convert.ToInt64(s, Constants.DefaultCultureInfo);
}
private static readonly byte[] eightSpaces =

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SharpCompress.Common;
namespace SharpCompress.Compressors.Arj;
@@ -189,7 +190,11 @@ public sealed partial class HuffTree
var node = _tree[index];
if (node.Type == NodeType.Leaf)
{
result.AppendLine($"{prefix} -> {node.LeafValue}");
result
.Append(prefix)
.Append(" -> ")
.Append(node.LeafValue.ToString(Constants.DefaultCultureInfo))
.AppendLine();
}
else
{

View File

@@ -1706,7 +1706,11 @@ internal sealed partial class DeflateManager
if (memLevel < 1 || memLevel > MEM_LEVEL_MAX)
{
throw new ZlibException(
string.Format("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX)
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"memLevel must be in the range 1.. {0}",
MEM_LEVEL_MAX
)
);
}
@@ -1876,7 +1880,13 @@ internal sealed partial class DeflateManager
_codec.Message = _ErrorMessage[
ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_STREAM_ERROR)
];
throw new ZlibException(string.Format("Something is fishy. [{0}]", _codec.Message));
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Something is fishy. [{0}]",
_codec.Message
)
);
//return ZlibConstants.Z_STREAM_ERROR;
}

View File

@@ -120,6 +120,7 @@ public partial class DeflateStream : Stream, IStreamStack
{
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
value,
ZlibConstants.WorkingBufferSizeMin

View File

@@ -116,6 +116,7 @@ public partial class GZipStream : Stream
{
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
value,
ZlibConstants.WorkingBufferSizeMin
@@ -402,7 +403,11 @@ public partial class GZipStream : Stream
{
return;
}
#if LEGACY_DOTNET
if (_fileName.Contains('/'))
#else
if (_fileName.Contains('/', StringComparison.Ordinal))
#endif
{
_fileName = _fileName.Replace('/', '\\');
}
@@ -411,7 +416,11 @@ public partial class GZipStream : Stream
throw new InvalidOperationException("Illegal filename");
}
#if LEGACY_DOTNET
if (_fileName.Contains('\\'))
#else
if (_fileName.Contains('\\', StringComparison.Ordinal))
#endif
{
// trim any leading path
_fileName = Path.GetFileName(_fileName);

View File

@@ -1746,6 +1746,7 @@ internal sealed class InflateManager
{
mode = InflateManagerMode.BAD;
_codec.Message = string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"unknown compression method (0x{0:X2})",
method
);
@@ -1756,6 +1757,7 @@ internal sealed class InflateManager
{
mode = InflateManagerMode.BAD;
_codec.Message = string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"invalid window size ({0})",
(method >> 4) + 8
);
@@ -1945,7 +1947,13 @@ internal sealed class InflateManager
return ZlibConstants.Z_STREAM_END;
case InflateManagerMode.BAD:
throw new ZlibException(string.Format("Bad state ({0})", _codec.Message));
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Bad state ({0})",
_codec.Message
)
);
default:
throw new ZlibException("Stream error.");

View File

@@ -275,7 +275,14 @@ internal class ZlibBaseStream : Stream, IStreamStack
var verb = (_wantCompress ? "de" : "in") + "flating";
if (_z.Message is null)
{
throw new ZlibException(String.Format("{0}: (rc = {1})", verb, rc));
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"{0}: (rc = {1})",
verb,
rc
)
);
}
throw new ZlibException(verb + ": " + _z.Message);
}
@@ -344,6 +351,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
{
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Protocol error. AvailableBytesIn={0}, expected 8",
_z.AvailableBytesIn + bytesRead
)
@@ -364,6 +372,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
{
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Bad CRC32 in GZIP stream. (actual({0:X8})!=expected({1:X8}))",
crc32_actual,
crc32_expected
@@ -375,6 +384,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
{
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Bad size in GZIP stream. (actual({0})!=expected({1}))",
isize_actual,
isize_expected
@@ -413,7 +423,14 @@ internal class ZlibBaseStream : Stream, IStreamStack
var verb = (_wantCompress ? "de" : "in") + "flating";
if (_z.Message is null)
{
throw new ZlibException(String.Format("{0}: (rc = {1})", verb, rc));
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"{0}: (rc = {1})",
verb,
rc
)
);
}
throw new ZlibException(verb + ": " + _z.Message);
}
@@ -869,7 +886,12 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
{
throw new ZlibException(
String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Deflating: rc={0} msg={1}",
rc,
_z.Message
)
);
}
@@ -922,6 +944,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
{
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"{0}flating: rc={1} msg={2}",
(_wantCompress ? "de" : "in"),
rc,
@@ -961,7 +984,12 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
{
throw new ZlibException(
String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Deflating: rc={0} msg={1}",
rc,
_z.Message
)
);
}
}
@@ -1050,7 +1078,12 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
{
throw new ZlibException(
String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Deflating: rc={0} msg={1}",
rc,
_z.Message
)
);
}
@@ -1105,6 +1138,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
{
throw new ZlibException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"{0}flating: rc={1} msg={2}",
(_wantCompress ? "de" : "in"),
rc,
@@ -1144,7 +1178,12 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
{
throw new ZlibException(
String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Deflating: rc={0} msg={1}",
rc,
_z.Message
)
);
}
}

View File

@@ -696,6 +696,7 @@ internal sealed class ZlibCodec
{
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Invalid State. (pending.Length={0}, pendingCount={1})",
dstate.pending.Length,
dstate.pendingCount

View File

@@ -107,6 +107,7 @@ public partial class ZlibStream : Stream
{
throw new ZlibException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
value,
ZlibConstants.WorkingBufferSizeMin

View File

@@ -38,6 +38,7 @@ public partial class LzwStream
{
throw new IncompleteArchiveException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
hdr[0],
hdr[1]
@@ -325,6 +326,7 @@ public partial class LzwStream
{
throw new IncompleteArchiveException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
hdr[0],
hdr[1]

View File

@@ -64,6 +64,7 @@ public partial class LzwStream : Stream
{
throw new IncompleteArchiveException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
hdr[0],
hdr[1]
@@ -397,6 +398,7 @@ public partial class LzwStream : Stream
{
throw new IncompleteArchiveException(
String.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
hdr[0],
hdr[1]

View File

@@ -46,6 +46,7 @@ internal class MarkingBinaryReader(Stream stream)
{
throw new InvalidFormatException(
string.Format(
global::SharpCompress.Common.Constants.DefaultCultureInfo,
"Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}",
count,
bytes.Length

View File

@@ -65,7 +65,11 @@ public partial class TarWriter : AbstractWriter
{
filename = filename.Replace('\\', '/');
#if LEGACY_DOTNET
var pos = filename.IndexOf(':');
#else
var pos = filename.IndexOf(':', StringComparison.Ordinal);
#endif
if (pos >= 0)
{
filename = filename.Remove(0, pos + 1);

View File

@@ -133,7 +133,11 @@ public partial class ZipWriter : AbstractWriter
{
filename = filename.Replace('\\', '/');
#if LEGACY_DOTNET
var pos = filename.IndexOf(':');
#else
var pos = filename.IndexOf(':', StringComparison.Ordinal);
#endif
if (pos >= 0)
{
filename = filename.Remove(0, pos + 1);