Enable Net 7 and Net 8 style rules.

This commit is contained in:
RoosterDragon
2024-11-25 20:15:58 +00:00
committed by Gustas Kažukauskas
parent 71ae0aedfb
commit cfde11556f
31 changed files with 74 additions and 94 deletions

View File

@@ -210,8 +210,7 @@ namespace OpenRA
using (var rsa = new RSACryptoServiceProvider())
{
rsa.ImportParameters(parameters);
using (var csp = SHA1.Create())
return Convert.ToBase64String(rsa.SignHash(csp.ComputeHash(data), CryptoConfig.MapNameToOID("SHA1")));
return Convert.ToBase64String(rsa.SignHash(SHA1.HashData(data), CryptoConfig.MapNameToOID("SHA1")));
}
}
catch (Exception e)
@@ -236,8 +235,7 @@ namespace OpenRA
using (var rsa = new RSACryptoServiceProvider())
{
rsa.ImportParameters(parameters);
using (var csp = SHA1.Create())
return rsa.VerifyHash(csp.ComputeHash(data), CryptoConfig.MapNameToOID("SHA1"), Convert.FromBase64String(signature));
return rsa.VerifyHash(SHA1.HashData(data), CryptoConfig.MapNameToOID("SHA1"), Convert.FromBase64String(signature));
}
}
catch (Exception e)
@@ -252,14 +250,12 @@ namespace OpenRA
public static string SHA1Hash(Stream data)
{
using var csp = SHA1.Create();
return ToHex(csp.ComputeHash(data), true);
return ToHex(SHA1.HashData(data), true);
}
public static string SHA1Hash(byte[] data)
{
using var csp = SHA1.Create();
return ToHex(csp.ComputeHash(data), true);
return ToHex(SHA1.HashData(data), true);
}
public static string SHA1Hash(string data)

View File

@@ -27,8 +27,7 @@ namespace OpenRA.FileFormats
public ReplayMetadata(GameInformation info)
{
if (info == null)
throw new ArgumentNullException(nameof(info));
ArgumentNullException.ThrowIfNull(info);
GameInfo = info;
}

View File

@@ -111,8 +111,7 @@ namespace OpenRA
public bool TryGetMessage(string key, out string value, object[] args = null)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);
try
{

View File

@@ -100,11 +100,9 @@ namespace OpenRA
/// <summary>Adds the player information at start-up.</summary>
public void AddPlayer(OpenRA.Player runtimePlayer, Session lobbyInfo)
{
if (runtimePlayer == null)
throw new ArgumentNullException(nameof(runtimePlayer));
ArgumentNullException.ThrowIfNull(runtimePlayer);
if (lobbyInfo == null)
throw new ArgumentNullException(nameof(lobbyInfo));
ArgumentNullException.ThrowIfNull(lobbyInfo);
// We don't care about spectators and map players
if (runtimePlayer.NonCombatant || !runtimePlayer.Playable)

View File

@@ -31,9 +31,9 @@ namespace OpenRA.Graphics
public interface IModelWidget
{
public string Palette { get; }
public float Scale { get; }
public void Setup(Func<bool> isVisible, Func<string> getPalette, Func<string> getPlayerPalette,
string Palette { get; }
float Scale { get; }
void Setup(Func<bool> isVisible, Func<string> getPalette, Func<string> getPlayerPalette,
Func<float> getScale, Func<IModel> getVoxel, Func<WRot> getRotation);
}

View File

@@ -23,8 +23,7 @@ namespace OpenRA.Primitives
public void Add(Action a, long desiredTime)
{
if (a == null)
throw new ArgumentNullException(nameof(a));
ArgumentNullException.ThrowIfNull(a);
lock (actions)
{

View File

@@ -21,8 +21,7 @@ namespace OpenRA
public ActorInfoDictionary(IReadOnlyDictionary<string, ActorInfo> dict)
{
if (dict == null)
throw new ArgumentNullException(nameof(dict));
ArgumentNullException.ThrowIfNull(dict);
this.dict = new Dictionary<string, ActorInfo>(dict);
}

View File

@@ -21,8 +21,7 @@ namespace OpenRA.Primitives
public Cache(Func<T, U> loader, IEqualityComparer<T> c)
{
if (loader == null)
throw new ArgumentNullException(nameof(loader));
ArgumentNullException.ThrowIfNull(loader);
this.loader = loader;
cache = new Dictionary<T, U>(c);

View File

@@ -22,8 +22,7 @@ namespace OpenRA.Primitives
public ConcurrentCache(Func<T, U> loader, IEqualityComparer<T> c)
{
if (loader == null)
throw new ArgumentNullException(nameof(loader));
ArgumentNullException.ThrowIfNull(loader);
this.loader = loader;
cache = new ConcurrentDictionary<T, U>(c);

View File

@@ -27,8 +27,7 @@ namespace OpenRA.Primitives
protected ReadOnlyAdapterStream(Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
ArgumentNullException.ThrowIfNull(stream);
if (!stream.CanRead)
throw new ArgumentException("stream must be readable.", nameof(stream));

View File

@@ -65,8 +65,7 @@ namespace OpenRA.Primitives
public void CopyTo(T[] array, int arrayIndex)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
ArgumentNullException.ThrowIfNull(array);
if (arrayIndex < 0)
throw new ArgumentNullException(nameof(arrayIndex));

View File

@@ -32,8 +32,7 @@ namespace OpenRA.Primitives
/// <param name="count">The length of the segment.</param>
public SegmentStream(Stream stream, long offset, long count)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
ArgumentNullException.ThrowIfNull(stream);
if (!stream.CanSeek)
throw new ArgumentException("stream must be seekable.", nameof(stream));
if (offset < 0)

View File

@@ -150,7 +150,7 @@ namespace OpenRA.Scripting
// Remove the namespace and the trailing "Info"
return types.SelectMany(i => i.GetGenericArguments())
.Select(g => g.Name.Split('.', StringSplitOptions.RemoveEmptyEntries).LastOrDefault())
.Select(s => s.EndsWith("Info", StringComparison.Ordinal) ? s.Remove(s.Length - 4, 4) : s)
.Select(s => s.EndsWith("Info", StringComparison.Ordinal) ? s[..^4] : s)
.ToArray();
}
}

View File

@@ -359,8 +359,7 @@ namespace OpenRA
public bool PlayPredefined(SoundType soundType, Ruleset ruleset, Player player, Actor voicedActor, string type, string definition, string variant,
bool relative, WPos pos, float volumeModifier, bool attenuateVolume)
{
if (ruleset == null)
throw new ArgumentNullException(nameof(ruleset));
ArgumentNullException.ThrowIfNull(ruleset);
if (definition == null || DisableAllSounds || (DisableWorldSounds && soundType == SoundType.World))
return false;
@@ -460,8 +459,7 @@ namespace OpenRA
public bool PlayNotification(Ruleset rules, Player player, string type, string notification, string variant)
{
if (rules == null)
throw new ArgumentNullException(nameof(rules));
ArgumentNullException.ThrowIfNull(rules);
if (type == null || notification == null)
return false;