Skip to content

Commit

Permalink
Merge pull request #5 from dorssel/versioning
Browse files Browse the repository at this point in the history
fix continuous delivery
  • Loading branch information
dorssel authored Nov 14, 2020
2 parents 77c3c6a + f6cd1fb commit 53044ff
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 49 deletions.
24 changes: 13 additions & 11 deletions Installer/Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,19 @@
<OutputName>usbipd-win</OutputName>
<DefineSolutionProperties>false</DefineSolutionProperties>
<PublishDir>..\UsbIpServer\bin\publish</PublishDir>
<!--
This ensures that each x.y.z version has a different product, so every upgrade is a MajorUpgrade.
It also ensures that 2 builds of the same x.y.z version will never be installed simultaneously.
The alternative (WiX AllowSameVersionUpgrades) causes ICE61.
The chance of a hash-collision is much smaller than the chance of forgetting to update ProductId manually.
-->
<ProductId>EA1D5623-E6A7-4E4A-9259-E397$(GitVersion_MajorMinorPatch.GetHashCode().ToString(X8))</ProductId>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
<DefineConstants>Debug;PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers</DefineConstants>
<Cultures>en-US</Cultures>
<SuppressAllWarnings>False</SuppressAllWarnings>
<Pedantic>True</Pedantic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers;ProductId=$(ProductId)</DefineConstants>
<DefineConstants>PublishDir=$(PublishDir);DriversDir=$(ProjectDir)..\Drivers</DefineConstants>
<Cultures>en-US</Cultures>
<SuppressAllWarnings>False</SuppressAllWarnings>
<Pedantic>True</Pedantic>
Expand Down Expand Up @@ -102,7 +94,7 @@
<Target Name="EnsureWixToolsetInstalled" AfterTargets="BeforeBuild" />
<Target Name="SetTarget" AfterTargets="GetVersion">
<Message Importance="high" Text="Version detected as $(GitVersion_FullSemVer)" />
<CreateProperty Value="$(OutputName)_$(GitVersion_FullSemVer)">
<CreateProperty Value="$(OutputName)_$(GitVersion_MajorMinorPatch)">
<Output TaskParameter="Value" PropertyName="TargetName" />
</CreateProperty>
<CreateProperty Value="$(TargetName)$(TargetExt)">
Expand All @@ -114,6 +106,16 @@
<CreateProperty Value="$(TargetName)$(TargetPdbExt)">
<Output TaskParameter="Value" PropertyName="TargetPdbName" />
</CreateProperty>
<!--
This ensures that each x.y.z version has a different ProductId, so every update is a MajorUpgrade.
It also ensures that 2 builds of the same x.y.z version will never be installed simultaneously.
The alternative (WiX AllowSameVersionUpgrades) causes ICE61.
The chance of a hash-collision is much smaller than the chance of forgetting to update ProductId manually.
-->
<CreateProperty Value="$(DefineConstants);ProductId=EA1D5623-E6A7-4E4A-9259-E397$(GitVersion_MajorMinorPatch.GetHashCode().ToString(X8))">
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>
</Target>
<PropertyGroup>
<PreBuildEvent>del /s /q "$(ProjectDir)..\UsbIpServer\bin\publish" &gt; NUL:
Expand Down
4 changes: 2 additions & 2 deletions UsbIpServer/AttachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Extensions.Logging;
using System;
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -25,6 +24,7 @@ You should have received a copy of the GNU General Public License
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static UsbIpServer.Interop.Usb;
using static UsbIpServer.Interop.UsbIp;
using static UsbIpServer.Interop.VBoxUsb;
Expand Down Expand Up @@ -82,10 +82,10 @@ async Task HandleSubmitAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSubmit submit
urb.type = UsbSupTransferType.USBSUP_TRANSFER_TYPE_BULK;
break;
case UsbEndpointType.USB_ENDPOINT_TYPE_INTERRUPT:
throw new NotImplementedException("USB_ENDPOINT_TYPE_INTERRUPT");
// TODO: requires queuing reuests and handling USBIP_CMD_UNLINK
// urb.type = UsbSupTransferType.USBSUP_TRANSFER_TYPE_INTR;
// break;
throw new NotImplementedException("USB_ENDPOINT_TYPE_INTERRUPT");
case UsbEndpointType.USB_ENDPOINT_TYPE_ISOCHRONOUS:
throw new NotImplementedException("USB_ENDPOINT_TYPE_ISOCHRONOUS");
}
Expand Down
4 changes: 2 additions & 2 deletions UsbIpServer/ConnectedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -27,6 +25,8 @@ You should have received a copy of the GNU General Public License
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using UsbIpServer.Interop;
using static UsbIpServer.Interop.UsbIp;
using static UsbIpServer.Tools;
Expand Down
4 changes: 2 additions & 2 deletions UsbIpServer/DeviceFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Win32.SafeHandles;
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
using static UsbIpServer.Interop.WinSDK;

namespace UsbIpServer
Expand Down Expand Up @@ -75,7 +75,7 @@ void OnCompletion(uint errorCode, uint numBytes, NativeOverlapped* nativeOverlap
}

var nativeOverlapped = overlapped.Pack(OnCompletion, new object?[] { input, output });
fixed (byte *pInput = input, pOutput = output)
fixed (byte* pInput = input, pOutput = output)
{
if (!NativeMethods.DeviceIoControl(handle, ioControlCode, (IntPtr)pInput, (uint)(input?.Length ?? 0),
(IntPtr)pOutput, (uint)(output?.Length ?? 0), out var bytesReturned, (IntPtr)nativeOverlapped))
Expand Down
4 changes: 2 additions & 2 deletions UsbIpServer/ExportedDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace UsbIpServer
sealed class ExportedDevice
{
public string Path { get; set; } = string.Empty;
public string BusId { get => $"{BusNum}-{DevNum}"; }
public string BusId => $"{BusNum}-{DevNum}";
public uint BusNum { get; set; }
public uint DevNum { get; set; }
public Linux.UsbDeviceSpeed Speed { get; set; }
Expand Down Expand Up @@ -197,7 +197,7 @@ public static async Task<ExportedDevice[]> GetAll(CancellationToken cancellation
await hubFile.IoControlAsync(IoControl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, buf, buf);
BytesToStruct(buf, 0, out data);

var exportedDevice = new ExportedDevice()
var exportedDevice = new ExportedDevice()
{
Path = instanceId,
BusNum = hubNum,
Expand Down
10 changes: 5 additions & 5 deletions UsbIpServer/Interop/VBoxUsb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public struct UsbFilterField
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct UsbFilter
{
private uint u32Magic;
private UsbFilterType enmType;
uint u32Magic;
UsbFilterType enmType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)UsbFilterIdx.END)]
public UsbFilterField[] aFields;
private readonly uint offCurEnd;
readonly uint offCurEnd;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
private byte[] achStrTab;
byte[] achStrTab;

public static UsbFilter Create(UsbFilterType type)
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public struct UsbSupGetDevMon
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct UsbSupClaimDev
{
private readonly byte bInterfaceNumber;
readonly byte bInterfaceNumber;
[MarshalAs(UnmanagedType.U1)]
public bool fClaimed;
}
Expand Down
6 changes: 3 additions & 3 deletions UsbIpServer/Interop/WinSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using static UsbIpServer.Interop.Usb;

namespace UsbIpServer.Interop
Expand Down Expand Up @@ -120,7 +120,7 @@ public struct SpDeviceInterfaceData
public uint cbSize;
public Guid interfaceClassGuid;
public uint flags;
private readonly UIntPtr reserved;
readonly UIntPtr reserved;
}

/// <summary>WinSDK: SetupAPI.h: SP_DEVINFO_DATA</summary>
Expand All @@ -130,7 +130,7 @@ public struct SpDevInfoData
public uint cbSize;
public Guid ClassGuid;
public uint DevInst;
private readonly UIntPtr Reserved;
readonly UIntPtr Reserved;
}

public static class NativeMethods
Expand Down
28 changes: 17 additions & 11 deletions UsbIpServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

[assembly: CLSCompliant(true)]

namespace UsbIpServer
{
static class Program
{
static string Product { get => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>()!.Product; }
static string Copyright { get => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()!.Copyright; }
static string Product => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>()!.Product;
static string Copyright => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()!.Copyright;

static void ShowCopyright()
{
Console.WriteLine($@"{Product} {GitVersionInformation.FullSemVer}
Console.WriteLine($@"{Product} {GitVersionInformation.MajorMinorPatch}
{Copyright}
This program is free software: you can redistribute it and/or modify
Expand All @@ -57,7 +59,7 @@ static int Main(string[] args)
{
Name = Path.ChangeExtension(Path.GetFileName(Assembly.GetExecutingAssembly().Location), "exe"),
};
app.VersionOption("-v|--version", GitVersionInformation.FullSemVer, GitVersionInformation.InformationalVersion);
app.VersionOption("-v|--version", GitVersionInformation.MajorMinorPatch, GitVersionInformation.InformationalVersion);

void DefaultCmdLine(CommandLineApplication cmd)
{
Expand All @@ -69,10 +71,12 @@ void DefaultCmdLine(CommandLineApplication cmd)

DefaultCmdLine(app);
app.OptionHelp.ShowInHelpText = true;
app.Command("license", (cmd) => {
app.Command("license", (cmd) =>
{
cmd.Description = "Display license information";
DefaultCmdLine(cmd);
cmd.OnExecute(() => {
cmd.OnExecute(() =>
{
ShowCopyright();
return 0;
});
Expand All @@ -91,14 +95,16 @@ void DefaultCmdLine(CommandLineApplication cmd)
cmd.Option("-b|--busid=<busid>", "Unbind VBoxUsb.sys from device on <busid>", CommandOptionType.SingleValue);
});
#endif
app.Command("server", (cmd) => {
app.Command("server", (cmd) =>
{
cmd.Description = "Run the server stand-alone on the console";
DefaultCmdLine(cmd);
cmd.Argument("key=value", ".NET configuration override", true);
cmd.OnExecute(() => ExecuteServer(cmd.Arguments.Single().Values.ToArray()));
});

app.OnExecute(() => {
app.OnExecute(() =>
{
app.ShowRootCommandFullNameAndVersion();
app.ShowHint();
return 0;
Expand Down
5 changes: 4 additions & 1 deletion UsbIpServer/SafeDeviceInfoSetHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public SafeDeviceInfoSetHandle()
{
}

protected override bool ReleaseHandle() => NativeMethods.SetupDiDestroyDeviceInfoList(handle);
protected override bool ReleaseHandle()
{
return NativeMethods.SetupDiDestroyDeviceInfoList(handle);
}
}
}
6 changes: 3 additions & 3 deletions UsbIpServer/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using static UsbIpServer.Interop.UsbIp;

namespace UsbIpServer
Expand Down
4 changes: 2 additions & 2 deletions UsbIpServer/UsbConfigurationDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public UsbEndpoint(UsbEndpointDescriptor descriptor)
Descriptor = descriptor;
}

public UsbEndpointType TransferType { get => (UsbEndpointType)(Descriptor.bmAttributes & 0x03); }
public UsbEndpointType TransferType => (UsbEndpointType)(Descriptor.bmAttributes & 0x03);

public UsbEndpointDescriptor Descriptor { get; }
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public void SetAlternate(byte alternateSetting)
CurrentAlternate = alternateSetting;
}

public UsbAlternateInterface Current { get => Alternates[CurrentAlternate]; }
public UsbAlternateInterface Current => Alternates[CurrentAlternate];
}

sealed class UsbConfiguration
Expand Down
7 changes: 3 additions & 4 deletions UsbIpServer/UsbIpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>

<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<Product>usbipd-win</Product>
<Company>Frans van Dorsselaer</Company>
<Copyright>Copyright (C) $([System.DateTime]::UtcNow.ToString("yyyy")) $(Company)</Copyright>
Expand All @@ -53,10 +56,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion UsbIpServer/VBoxUsbMon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task<DeviceFile> ClaimDevice(ExportedDevice device)
}
}

private bool IsDisposed;
bool IsDisposed;
public void Dispose()
{
if (!IsDisposed)
Expand Down

0 comments on commit 53044ff

Please sign in to comment.