0
0
Fork 0

Remove some warnings and cleaning code (#1736)

This commit is contained in:
Ac_K 2020-11-27 18:57:20 +01:00 committed by GitHub
parent 632a84155b
commit b1877632cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 71 deletions

View file

@ -1,8 +1,10 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Versioning;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
[SupportedOSPlatform("linux")]
internal class LinuxSysteminfo : SystemInfo internal class LinuxSysteminfo : SystemInfo
{ {
public override string CpuName { get; } public override string CpuName { get; }

View file

@ -1,11 +1,13 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text; using System.Text;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
[SupportedOSPlatform("macos")]
internal class MacOSSysteminfo : SystemInfo internal class MacOSSysteminfo : SystemInfo
{ {
public override string CpuName { get; } public override string CpuName { get; }

View file

@ -2,9 +2,11 @@ using Ryujinx.Common.Logging;
using System; using System;
using System.Management; using System.Management;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
[SupportedOSPlatform("windows")]
internal class WindowsSysteminfo : SystemInfo internal class WindowsSysteminfo : SystemInfo
{ {
public override string CpuName { get; } public override string CpuName { get; }

View file

@ -918,9 +918,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (mi.Mode != PredictionMode.ZeroMv) if (mi.Mode != PredictionMode.ZeroMv)
{ {
Span<Mv> tmpMvs = stackalloc Mv[Constants.MaxMvRefCandidates];
for (refr = 0; refr < 1 + isCompound; ++refr) for (refr = 0; refr < 1 + isCompound; ++refr)
{ {
Span<Mv> tmpMvs = stackalloc Mv[Constants.MaxMvRefCandidates];
sbyte frame = mi.RefFrame[refr]; sbyte frame = mi.RefFrame[refr];
int refmvCount; int refmvCount;

View file

@ -24,8 +24,8 @@ namespace Ryujinx.Motion
private readonly Dictionary<int, Dictionary<int, MotionInput>> _motionData; private readonly Dictionary<int, Dictionary<int, MotionInput>> _motionData;
private readonly Dictionary<int, UdpClient> _clients; private readonly Dictionary<int, UdpClient> _clients;
private bool[] _clientErrorStatus = new bool[Enum.GetValues(typeof(PlayerIndex)).Length]; private readonly bool[] _clientErrorStatus = new bool[Enum.GetValues(typeof(PlayerIndex)).Length];
private long[] _clientRetryTimer = new long[Enum.GetValues(typeof(PlayerIndex)).Length]; private readonly long[] _clientRetryTimer = new long[Enum.GetValues(typeof(PlayerIndex)).Length];
public Client() public Client()
{ {
@ -48,11 +48,9 @@ namespace Ryujinx.Motion
{ {
client.Value?.Dispose(); client.Value?.Dispose();
} }
#pragma warning disable CS0168 catch (SocketException socketException)
catch (SocketException ex)
#pragma warning restore CS0168
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to dispose motion client. Error code {ex.ErrorCode}"); Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to dispose motion client. Error: {socketException.ErrorCode}");
} }
} }
@ -94,20 +92,20 @@ namespace Ryujinx.Motion
ReceiveLoop(player); ReceiveLoop(player);
}); });
} }
catch (FormatException fex) catch (FormatException formatException)
{ {
if (!_clientErrorStatus[player]) if (!_clientErrorStatus[player])
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to connect to motion source at {host}:{port}. Error {fex.Message}"); Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to connect to motion source at {host}:{port}. Error: {formatException.Message}");
_clientErrorStatus[player] = true; _clientErrorStatus[player] = true;
} }
} }
catch (SocketException sex) catch (SocketException socketException)
{ {
if (!_clientErrorStatus[player]) if (!_clientErrorStatus[player])
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to connect to motion source at {host}:{port}. Error code {sex.ErrorCode}"); Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to connect to motion source at {host}:{port}. Error: {socketException.ErrorCode}");
_clientErrorStatus[player] = true; _clientErrorStatus[player] = true;
} }
@ -118,8 +116,10 @@ namespace Ryujinx.Motion
SetRetryTimer(player); SetRetryTimer(player);
} }
catch (Exception ex) catch (Exception exception)
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to register motion client. Error: {exception.Message}");
_clientErrorStatus[player] = true; _clientErrorStatus[player] = true;
RemoveClient(player); RemoveClient(player);
@ -166,11 +166,11 @@ namespace Ryujinx.Motion
{ {
_client?.Send(data, data.Length); _client?.Send(data, data.Length);
} }
catch (SocketException ex) catch (SocketException socketException)
{ {
if (!_clientErrorStatus[clientId]) if (!_clientErrorStatus[clientId])
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to send data request to motion source at {_client.Client.RemoteEndPoint}. Error code {ex.ErrorCode}"); Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to send data request to motion source at {_client.Client.RemoteEndPoint}. Error: {socketException.ErrorCode}");
} }
_clientErrorStatus[clientId] = true; _clientErrorStatus[clientId] = true;
@ -181,7 +181,7 @@ namespace Ryujinx.Motion
SetRetryTimer(clientId); SetRetryTimer(clientId);
} }
catch (ObjectDisposedException dex) catch (ObjectDisposedException)
{ {
_clientErrorStatus[clientId] = true; _clientErrorStatus[clientId] = true;
@ -231,7 +231,7 @@ namespace Ryujinx.Motion
private bool CanConnect(int clientId) private bool CanConnect(int clientId)
{ {
return _clientRetryTimer[clientId] == 0 ? true : PerformanceCounter.ElapsedMilliseconds - 5000 > _clientRetryTimer[clientId]; return _clientRetryTimer[clientId] == 0 || PerformanceCounter.ElapsedMilliseconds - 5000 > _clientRetryTimer[clientId];
} }
public void ReceiveLoop(int clientId) public void ReceiveLoop(int clientId)
@ -251,16 +251,14 @@ namespace Ryujinx.Motion
continue; continue;
} }
#pragma warning disable CS4014
Task.Run(() => HandleResponse(data, clientId)); Task.Run(() => HandleResponse(data, clientId));
#pragma warning restore CS4014
} }
} }
catch (SocketException ex) catch (SocketException socketException)
{ {
if (!_clientErrorStatus[clientId]) if (!_clientErrorStatus[clientId])
{ {
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to receive data from motion source at {endPoint}. Error code {ex.ErrorCode}"); Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to receive data from motion source at {endPoint}. Error: {socketException.ErrorCode}");
} }
_clientErrorStatus[clientId] = true; _clientErrorStatus[clientId] = true;
@ -285,19 +283,16 @@ namespace Ryujinx.Motion
} }
} }
#pragma warning disable CS1998
public void HandleResponse(byte[] data, int clientId) public void HandleResponse(byte[] data, int clientId)
#pragma warning restore CS1998
{ {
ResetRetryTimer(clientId); ResetRetryTimer(clientId);
MessageType type = (MessageType)BitConverter.ToUInt32(data.AsSpan().Slice(16, 4)); MessageType type = (MessageType)BitConverter.ToUInt32(data.AsSpan().Slice(16, 4));
data = data.AsSpan().Slice(16).ToArray(); data = data.AsSpan()[16..].ToArray();
using MemoryStream mem = new MemoryStream(data); using MemoryStream stream = new MemoryStream(data);
using BinaryReader reader = new BinaryReader(stream);
using BinaryReader reader = new BinaryReader(mem);
switch (type) switch (type)
{ {
@ -335,21 +330,25 @@ namespace Ryujinx.Motion
{ {
if (_motionData[clientId].ContainsKey(slot)) if (_motionData[clientId].ContainsKey(slot))
{ {
var previousData = _motionData[clientId][slot]; MotionInput previousData = _motionData[clientId][slot];
previousData.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); previousData.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone);
} }
else else
{ {
MotionInput input = new MotionInput(); MotionInput input = new MotionInput();
input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone);
_motionData[clientId].Add(slot, input); _motionData[clientId].Add(slot, input);
} }
} }
else else
{ {
MotionInput input = new MotionInput(); MotionInput input = new MotionInput();
input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone);
_motionData.Add(clientId, new Dictionary<int, MotionInput>() { { slot, input } }); _motionData.Add(clientId, new Dictionary<int, MotionInput>() { { slot, input } });
} }
} }
@ -366,36 +365,34 @@ namespace Ryujinx.Motion
Header header = GenerateHeader(clientId); Header header = GenerateHeader(clientId);
using (MemoryStream mem = new MemoryStream()) using (MemoryStream stream = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(stream))
{ {
using (BinaryWriter writer = new BinaryWriter(mem)) writer.WriteStruct(header);
ControllerInfoRequest request = new ControllerInfoRequest()
{ {
writer.WriteStruct(header); Type = MessageType.Info,
PortsCount = 4
};
ControllerInfoRequest request = new ControllerInfoRequest() request.PortIndices[0] = (byte)slot;
{
Type = MessageType.Info,
PortsCount = 4
};
request.PortIndices[0] = (byte)slot; writer.WriteStruct(request);
writer.WriteStruct(request); header.Length = (ushort)(stream.Length - 16);
header.Length = (ushort)(mem.Length - 16); writer.Seek(6, SeekOrigin.Begin);
writer.Write(header.Length);
writer.Seek(6, SeekOrigin.Begin); header.Crc32 = Crc32Algorithm.Compute(stream.ToArray());
writer.Write(header.Length);
header.Crc32 = Crc32Algorithm.Compute(mem.ToArray()); writer.Seek(8, SeekOrigin.Begin);
writer.Write(header.Crc32);
writer.Seek(8, SeekOrigin.Begin); byte[] data = stream.ToArray();
writer.Write(header.Crc32);
byte[] data = mem.ToArray(); Send(data, clientId);
Send(data, clientId);
}
} }
} }
@ -408,35 +405,33 @@ namespace Ryujinx.Motion
Header header = GenerateHeader(clientId); Header header = GenerateHeader(clientId);
using (MemoryStream mem = new MemoryStream()) using (MemoryStream stream = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(stream))
{ {
using (BinaryWriter writer = new BinaryWriter(mem)) writer.WriteStruct(header);
ControllerDataRequest request = new ControllerDataRequest()
{ {
writer.WriteStruct(header); Type = MessageType.Data,
Slot = (byte)slot,
SubscriberType = SubscriberType.Slot
};
ControllerDataRequest request = new ControllerDataRequest() writer.WriteStruct(request);
{
Type = MessageType.Data,
Slot = (byte)slot,
SubscriberType = SubscriberType.Slot
};
writer.WriteStruct(request); header.Length = (ushort)(stream.Length - 16);
header.Length = (ushort)(mem.Length - 16); writer.Seek(6, SeekOrigin.Begin);
writer.Write(header.Length);
writer.Seek(6, SeekOrigin.Begin); header.Crc32 = Crc32Algorithm.Compute(stream.ToArray());
writer.Write(header.Length);
header.Crc32 = Crc32Algorithm.Compute(mem.ToArray()); writer.Seek(8, SeekOrigin.Begin);
writer.Write(header.Crc32);
writer.Seek(8, SeekOrigin.Begin); byte[] data = stream.ToArray();
writer.Write(header.Crc32);
byte[] data = mem.ToArray(); Send(data, clientId);
Send(data, clientId);
}
} }
} }

View file

@ -128,7 +128,7 @@ namespace Ryujinx
if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false)) if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false))
{ {
Updater.BeginParse(mainWindow, false); _ = Updater.BeginParse(mainWindow, false);
} }
Application.Run(); Application.Run();

View file

@ -1192,7 +1192,7 @@ namespace Ryujinx.Ui
{ {
if (Updater.CanUpdate(true)) if (Updater.CanUpdate(true))
{ {
Updater.BeginParse(this, true); _ = Updater.BeginParse(this, true);
} }
} }

View file

@ -70,7 +70,7 @@ namespace Ryujinx.Ui
SecondaryText.Text = ""; SecondaryText.Text = "";
_restartQuery = true; _restartQuery = true;
Updater.UpdateRyujinx(this, _buildUrl); _ = Updater.UpdateRyujinx(this, _buildUrl);
} }
} }

View file

@ -10,6 +10,7 @@ using System.IO;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Ryujinx namespace Ryujinx
@ -163,7 +164,7 @@ namespace Ryujinx
{ {
using (Stream inStream = File.OpenRead(updateFile)) using (Stream inStream = File.OpenRead(updateFile))
using (Stream gzipStream = new GZipInputStream(inStream)) using (Stream gzipStream = new GZipInputStream(inStream))
using (TarInputStream tarStream = new TarInputStream(gzipStream)) using (TarInputStream tarStream = new TarInputStream(gzipStream, Encoding.ASCII))
{ {
updateDialog.ProgressBar.MaxValue = inStream.Length; updateDialog.ProgressBar.MaxValue = inStream.Length;