Skip to content

Commit

Permalink
Merge pull request #1103 from dorssel/spelling
Browse files Browse the repository at this point in the history
Add spell check
  • Loading branch information
dorssel authored Dec 26, 2024
2 parents aadf755 + 19977c7 commit af57f8c
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 183 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_require_accessibility_modifiers = omit_if_default:suggestion
spelling_checkable_types = strings,identifiers,comments
spelling_error_severity = information
spelling_exclusion_path = .github/linters/vs-spell-exclusion.txt
spelling_languages = en-us
spelling_use_default_exclusion_dictionary = true

[*.{cs,razor}]
charset = utf-8-bom
Expand Down
28 changes: 28 additions & 0 deletions .github/linters/vs-spell-exclusion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Balisson
busid
Codecov
csharp
devid
Dushan
errno
ioctl
ioctls
linux
netstandard
nosemgrep
pcap
replug
replugged
seqnum
serializer
setupapi
stdout
usbfilter
usbids
usbioctl
usbip
usbipd
usblib
Vbox
vhci
wsl
3 changes: 3 additions & 0 deletions .github/linters/vs-spell-exclusion.txt.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Frans van Dorsselaer

SPDX-License-Identifier: GPL-3.0-only
2 changes: 1 addition & 1 deletion UnitTests/Automation_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void Device_BusId_Null()
}

[TestMethod]
public void Device_PeristedGuid()
public void Device_PersistedGuid()
{
var device = new Device()
{
Expand Down
10 changes: 5 additions & 5 deletions UnitTests/ConsoleTools_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public void ReportRebootRequired()
[DataRow("VID_80EE&PID_CAFE", false)]
[DataRow("VID_12AB&PID_34CD", true)]

public void CheckNoStub(string hardwareId, bool nostub)
public void CheckNoStub(string hardwareId, bool noStub)
{
var vidpid = VidPid.FromHardwareOrInstanceId(hardwareId);
var vidPid = VidPid.FromHardwareOrInstanceId(hardwareId);
var console = new TestConsole();
if (nostub)
if (noStub)
{
Assert.IsTrue(ConsoleTools.CheckNoStub(vidpid, console));
Assert.IsTrue(ConsoleTools.CheckNoStub(vidPid, console));
Assert.IsTrue(string.IsNullOrEmpty(console.Out.ToString()));
Assert.IsTrue(string.IsNullOrEmpty(console.Error.ToString()));
}
else
{
Assert.IsFalse(ConsoleTools.CheckNoStub(vidpid, console));
Assert.IsFalse(ConsoleTools.CheckNoStub(vidPid, console));
Assert.IsTrue(string.IsNullOrEmpty(console.Out.ToString()));
Assert.IsFalse(string.IsNullOrEmpty(console.Error.ToString()));
}
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/ExportedDevice_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ sealed class ExportedDevice_Tests
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// busid (32 bytes, text)
// busId (32 bytes, text)
(byte)'3', (byte)'-', (byte)'4', (byte)'2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// busnum (4 bytes, big endian)
// busNum (4 bytes, big endian)
0, 0, 0, 3,
// devnum (4 bytes, big endian)
// devNum (4 bytes, big endian)
0, 0, 0, 42,
// speed (4 bytes, enum, big endian)
0, 0, 0, (byte)UsbDeviceSpeed.USB_SPEED_SUPER_PLUS,
Expand Down
2 changes: 1 addition & 1 deletion Usbipd.Automation/BusId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public readonly record struct BusId
public BusId(ushort bus, ushort port)
{
// Do not allow the explicit creation of the special IncompatibleHub value.
// Instead, use the static IncompatibleHub field (preferrable) or "default".
// Instead, use the static IncompatibleHub field (preferable) or "default".
// USB supports up to 127 devices, but that would require multiple hubs; the "per hub" port will never be >99.
// And if you have more than 99 hubs on one system, then you win a prize! (but we're not going to support it...)
if (bus is 0 or > 99)
Expand Down
4 changes: 2 additions & 2 deletions Usbipd.PowerShell/GetUsbipdDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected override void BeginProcessing()

var captureTasks = new[]
{
Task.Run(async () => { stdout = await process.StandardOutput.ReadToEndAsync(); }),
Task.Run(async () => { stderr = await process.StandardError.ReadToEndAsync(); }),
Task.Run(async () => stdout = await process.StandardOutput.ReadToEndAsync()),
Task.Run(async () => stderr = await process.StandardError.ReadToEndAsync()),
};

process.WaitForExit();
Expand Down
4 changes: 2 additions & 2 deletions Usbipd.PowerShell/Installation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static string ExePath

var captureTasks = new[]
{
Task.Run(async () => { stdout = await process.StandardOutput.ReadToEndAsync(); }),
Task.Run(async () => { stderr = await process.StandardError.ReadToEndAsync(); }),
Task.Run(async () => stdout = await process.StandardOutput.ReadToEndAsync()),
Task.Run(async () => stderr = await process.StandardError.ReadToEndAsync()),
};

process.WaitForExit();
Expand Down
14 changes: 5 additions & 9 deletions Usbipd/AttachedEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,8 @@ async Task HandleSubmitIsochronousAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSu
}
finally
{
_ = Task.WhenAll(ioctls).ContinueWith(task =>
{
gcHandle.Free();
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
_ = Task.WhenAll(ioctls).ContinueWith(task => gcHandle.Free(),
CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
}

Expand Down Expand Up @@ -257,7 +255,7 @@ public async Task HandleSubmitAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSubmit
}

// We now have received the entire SUBMIT request:
// - If the request is "special" (reconfig, clear), then we will handle it immediately and await the result.
// - If the request is "special" (reconfigure, clear), then we will handle it immediately and await the result.
// This means no further requests will be read until the special request has completed.
// - Otherwise, we will start a new task so that the receiver can continue.
// This means multiple URBs can be outstanding awaiting completion.
Expand Down Expand Up @@ -329,10 +327,8 @@ public async Task HandleSubmitAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSubmit
gcHandle.Free();
throw;
}
_ = ioctl.ContinueWith(task =>
{
gcHandle.Free();
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
_ = ioctl.ContinueWith(task => gcHandle.Free(),
CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
else
{
Expand Down
36 changes: 18 additions & 18 deletions Usbipd/CommandHandlersCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ You should have received a copy of the GNU General Public License \
return Task.FromResult(ExitCode.Success);
}

static string GetDescription(UsbDevice device, bool usbids)
static string GetDescription(UsbDevice device, bool usbIds)
{
if (usbids)
if (usbIds)
{
var vendor = device.HardwareId.Vendor;
return vendor is not null
Expand All @@ -112,7 +112,7 @@ static string GetDescription(UsbDevice device, bool usbids)
}
}

Task<ExitCode> ICommandHandlers.List(bool usbids, IConsole console, CancellationToken cancellationToken)
Task<ExitCode> ICommandHandlers.List(bool usbIds, IConsole console, CancellationToken cancellationToken)
{
var allDevices = UsbDevice.GetAll().ToList();
console.WriteLine("Connected:");
Expand All @@ -126,7 +126,7 @@ Task<ExitCode> ICommandHandlers.List(bool usbids, IConsole console, Cancellation
: Policy.IsAutoBindAllowed(device) ? "Allowed" : "Not shared";
console.Write($"{(device.BusId.Value.IsIncompatibleHub ? string.Empty : device.BusId.Value),-5} ");
console.Write($"{device.HardwareId,-9} ");
console.WriteTruncated(GetDescription(device, usbids), 60, true);
console.WriteTruncated(GetDescription(device, usbIds), 60, true);
console.WriteLine($" {state}");
}
console.WriteLine(string.Empty);
Expand All @@ -137,7 +137,7 @@ Task<ExitCode> ICommandHandlers.List(bool usbids, IConsole console, Cancellation
{
Debug.Assert(device.Guid.HasValue);
console.Write($"{device.Guid.Value,-36:D} ");
console.WriteTruncated(GetDescription(device, usbids), 60, false);
console.WriteTruncated(GetDescription(device, usbIds), 60, false);
console.WriteLine(string.Empty);
}
console.WriteLine(string.Empty);
Expand Down Expand Up @@ -171,7 +171,7 @@ static ExitCode Bind(BusId busId, bool force, IConsole console)
}
if (!device.Guid.HasValue)
{
RegistryUtils.Persist(device.InstanceId, device.Description);
RegistryUtilities.Persist(device.InstanceId, device.Description);
}
if (!force)
{
Expand Down Expand Up @@ -221,7 +221,7 @@ Task<ExitCode> ICommandHandlers.Unbind(BusId busId, IConsole console, Cancellati
{
return Task.FromResult(ExitCode.AccessDenied);
}
RegistryUtils.StopSharingDevice(device.Guid.Value);
RegistryUtilities.StopSharingDevice(device.Guid.Value);
if (NewDev.UnforceVBoxDriver(device.InstanceId))
{
console.ReportRebootRequired();
Expand Down Expand Up @@ -251,7 +251,7 @@ static ExitCode Unbind(IEnumerable<UsbDevice> devices, IConsole console)
{
if (device.Guid is not null)
{
RegistryUtils.StopSharingDevice(device.Guid.Value);
RegistryUtilities.StopSharingDevice(device.Guid.Value);
}
try
{
Expand All @@ -278,7 +278,7 @@ static ExitCode Unbind(IEnumerable<UsbDevice> devices, IConsole console)

Task<ExitCode> ICommandHandlers.Unbind(Guid guid, IConsole console, CancellationToken cancellationToken)
{
var device = RegistryUtils.GetBoundDevices().SingleOrDefault(d => d.Guid.HasValue && d.Guid.Value == guid);
var device = RegistryUtilities.GetBoundDevices().SingleOrDefault(d => d.Guid.HasValue && d.Guid.Value == guid);
if (device is null)
{
console.ReportError($"There is no device with guid '{guid:D}'.");
Expand All @@ -302,7 +302,7 @@ Task<ExitCode> ICommandHandlers.UnbindAll(IConsole console, CancellationToken ca
{
return Task.FromResult(ExitCode.AccessDenied);
}
RegistryUtils.StopSharingAllDevices();
RegistryUtilities.StopSharingAllDevices();
var reboot = false;
var driverError = false;
foreach (var originalDeviceId in ConfigurationManager.GetOriginalDeviceIdsWithVBoxDriver())
Expand Down Expand Up @@ -373,7 +373,7 @@ static ExitCode Detach(IEnumerable<UsbDevice> devices, IConsole console)
console.ReportInfo($"Device with busid '{device.BusId}' was already not attached.");
continue;
}
if (!RegistryUtils.SetDeviceAsDetached(device.Guid.Value))
if (!RegistryUtilities.SetDeviceAsDetached(device.Guid.Value))
{
console.ReportError($"Failed to detach device with busid '{device.BusId}'.");
error = true;
Expand Down Expand Up @@ -406,7 +406,7 @@ Task<ExitCode> ICommandHandlers.Detach(VidPid vidPid, IConsole console, Cancella

Task<ExitCode> ICommandHandlers.DetachAll(IConsole console, CancellationToken cancellationToken)
{
if (!RegistryUtils.SetAllDevicesAsDetached())
if (!RegistryUtilities.SetAllDevicesAsDetached())
{
console.ReportError($"Failed to detach one or more devices.");
return Task.FromResult(ExitCode.Failure);
Expand Down Expand Up @@ -451,7 +451,7 @@ Task<ExitCode> ICommandHandlers.State(IConsole console, CancellationToken cancel

Task<ExitCode> ICommandHandlers.PolicyAdd(PolicyRule rule, IConsole console, CancellationToken cancellationToken)
{
if (RegistryUtils.GetPolicyRules().FirstOrDefault(r => r.Value == rule) is var existingRule && existingRule.Key != default)
if (RegistryUtilities.GetPolicyRules().FirstOrDefault(r => r.Value == rule) is var existingRule && existingRule.Key != default)
{
console.ReportError($"Policy rule already exists with guid '{existingRule.Key:D}'.");
return Task.FromResult(ExitCode.Failure);
Expand All @@ -462,14 +462,14 @@ Task<ExitCode> ICommandHandlers.PolicyAdd(PolicyRule rule, IConsole console, Can
return Task.FromResult(ExitCode.AccessDenied);
}

var guid = RegistryUtils.AddPolicyRule(rule);
var guid = RegistryUtilities.AddPolicyRule(rule);
console.ReportInfo($"Policy rule created with guid '{guid:D}'.");
return Task.FromResult(ExitCode.Success);
}

Task<ExitCode> ICommandHandlers.PolicyList(IConsole console, CancellationToken cancellationToken)
{
var policyRules = RegistryUtils.GetPolicyRules();
var policyRules = RegistryUtilities.GetPolicyRules();
console.WriteLine("Policy rules:");
console.WriteLine($"{"GUID",-36} {"EFFECT",-6} {"OPERATION",-9} {"BUSID",-5} {"VID:PID",-9}");
foreach (var rule in policyRules)
Expand All @@ -495,7 +495,7 @@ Task<ExitCode> ICommandHandlers.PolicyList(IConsole console, CancellationToken c

Task<ExitCode> ICommandHandlers.PolicyRemove(Guid guid, IConsole console, CancellationToken cancellationToken)
{
if (!RegistryUtils.GetPolicyRules().ContainsKey(guid))
if (!RegistryUtilities.GetPolicyRules().ContainsKey(guid))
{
console.ReportError($"There is no policy rule with guid '{guid:D}'.");
return Task.FromResult(ExitCode.Failure);
Expand All @@ -506,7 +506,7 @@ Task<ExitCode> ICommandHandlers.PolicyRemove(Guid guid, IConsole console, Cancel
return Task.FromResult(ExitCode.AccessDenied);
}

RegistryUtils.RemovePolicyRule(guid);
RegistryUtilities.RemovePolicyRule(guid);
return Task.FromResult(ExitCode.Success);
}

Expand All @@ -517,7 +517,7 @@ Task<ExitCode> ICommandHandlers.PolicyRemoveAll(IConsole console, CancellationTo
return Task.FromResult(ExitCode.AccessDenied);
}

RegistryUtils.RemovePolicyRuleAll();
RegistryUtilities.RemovePolicyRuleAll();
return Task.FromResult(ExitCode.Success);
}
}
5 changes: 1 addition & 4 deletions Usbipd/CommandHandlersServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ async Task<ExitCode> ICommandHandlers.Server(string[] args, IConsole console, Ca
{
EventLog.CreateEventSource(Program.Product, "Application");
}
_ = logging.AddEventLog(settings =>
{
settings.SourceName = Program.Product;
});
_ = logging.AddEventLog(settings => settings.SourceName = Program.Product);
})
.ConfigureServices((hostContext, services) =>
{
Expand Down
4 changes: 2 additions & 2 deletions Usbipd/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ public static bool HasVBoxDriver(string instanceId)
try
{
var deviceNode = Locate_DevNode(instanceId, false);
var driverDesc = (string)Get_DevNode_Property(deviceNode, PInvoke.DEVPKEY_Device_DriverDesc);
return driverDesc == "VirtualBox USB";
var driverDescription = (string)Get_DevNode_Property(deviceNode, PInvoke.DEVPKEY_Device_DriverDesc);
return driverDescription == "VirtualBox USB";
}
catch (ConfigurationManagerException)
{
Expand Down
18 changes: 9 additions & 9 deletions Usbipd/ConnectedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task RunAsync(CancellationToken cancellationToken)
{
try
{
var opCode = await RecvOpCodeAsync(cancellationToken);
var opCode = await ReceiveOpCodeAsync(cancellationToken);
Logger.Debug($"Received opcode: {opCode}");
switch (opCode)
{
Expand Down Expand Up @@ -138,11 +138,11 @@ async Task HandleRequestImportAsync(CancellationToken cancellationToken)
{
// The device is not currently bound, but it is allowed by the policy. Auto-bind it now...
Logger.AutoBind(ClientContext.ClientAddress, busId, bindDevice.InstanceId);
RegistryUtils.Persist(bindDevice.InstanceId, bindDevice.Description);
RegistryUtilities.Persist(bindDevice.InstanceId, bindDevice.Description);
}
}

var device = RegistryUtils.GetBoundDevices().SingleOrDefault(d => d.BusId.HasValue && d.BusId.Value == busId);
var device = RegistryUtilities.GetBoundDevices().SingleOrDefault(d => d.BusId.HasValue && d.BusId.Value == busId);
if (device is null)
{
await SendOpCodeAsync(OpCode.OP_REP_IMPORT, Status.ST_NODEV);
Expand Down Expand Up @@ -239,13 +239,13 @@ async Task HandleRequestImportAsync(CancellationToken cancellationToken)
}

// Detect unbind.
using var attachedKey = RegistryUtils.SetDeviceAsAttached(device.Guid.Value, device.BusId.Value, ClientContext.ClientAddress,
using var attachedKey = RegistryUtilities.SetDeviceAsAttached(device.Guid.Value, device.BusId.Value, ClientContext.ClientAddress,
vboxDevice.InstanceId);
var lresult = PInvoke.RegNotifyChangeKeyValue(attachedKey.Handle, false,
var result = PInvoke.RegNotifyChangeKeyValue(attachedKey.Handle, false,
Windows.Win32.System.Registry.REG_NOTIFY_FILTER.REG_NOTIFY_THREAD_AGNOSTIC, cancelEvent.SafeWaitHandle, true);
if (lresult != WIN32_ERROR.ERROR_SUCCESS)
if (result != WIN32_ERROR.ERROR_SUCCESS)
{
throw new Win32Exception((int)lresult, nameof(PInvoke.RegNotifyChangeKeyValue));
throw new Win32Exception((int)result, nameof(PInvoke.RegNotifyChangeKeyValue));
}

await ServiceProvider.GetRequiredService<AttachedClient>().RunAsync(attachedClientTokenSource.Token);
Expand All @@ -254,7 +254,7 @@ async Task HandleRequestImportAsync(CancellationToken cancellationToken)
{
notification?.Dispose();

_ = RegistryUtils.SetDeviceAsDetached(device.Guid.Value);
_ = RegistryUtilities.SetDeviceAsDetached(device.Guid.Value);

ClientContext.AttachedDevice.Dispose();

Expand Down Expand Up @@ -294,7 +294,7 @@ async Task HandleRequestImportAsync(CancellationToken cancellationToken)
}
}

async Task<OpCode> RecvOpCodeAsync(CancellationToken cancellationToken)
async Task<OpCode> ReceiveOpCodeAsync(CancellationToken cancellationToken)
{
var buf = new byte[8];
await Stream.ReadMessageAsync(buf, cancellationToken);
Expand Down
Loading

0 comments on commit af57f8c

Please sign in to comment.