Skip to content

Commit

Permalink
Merge pull request #769 from dorssel/fix_powershell
Browse files Browse the repository at this point in the history
Remove unnecessary dependency from PowerShell
  • Loading branch information
dorssel committed Nov 18, 2023
2 parents e75310d + 7506964 commit 29760e4
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 12 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ SPDX-License-Identifier: GPL-3.0-only
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SPDX-License-Identifier: GPL-3.0-only
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<!-- Usbipd.PowerShell -->
<PackageVersion Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageVersion Include="System.Text.Json" Version="7.0.4" />
<!-- Installer -->
<PackageVersion Include="WixToolset.DifxApp.wixext" Version="4.0.3" />
<PackageVersion Include="WixToolset.Firewall.wixext" Version="4.0.3" />
Expand Down
4 changes: 4 additions & 0 deletions Usbipd.Automation/BusId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
//
// SPDX-License-Identifier: GPL-3.0-only

#if !NETSTANDARD
using System.Text.Json.Serialization;
#endif
using System.Text.RegularExpressions;

namespace Usbipd.Automation;

public readonly record struct BusId
: IComparable<BusId>
{
#if !NETSTANDARD
[JsonConstructor]
public BusId(ushort bus, ushort port) => (Bus, Port) = (bus, port);
#endif

public ushort Bus { get; init; }
public ushort Port { get; init; }
Expand Down
26 changes: 26 additions & 0 deletions Usbipd.Automation/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

using System.Net;
using System.Runtime.Serialization;
#if !NETSTANDARD
using System.Text.Json.Serialization;
#endif

namespace Usbipd.Automation;

Expand All @@ -13,16 +15,22 @@ public sealed partial class Device
{
public Device() { }

#if !NETSTANDARD
[JsonConstructor]
public Device(string instanceId, string description, bool isForced, BusId? busId, Guid? persistedGuid, string? stubInstanceId, IPAddress? clientIPAddress)
=> (InstanceId, Description, IsForced, BusId, PersistedGuid, StubInstanceId, ClientIPAddress)
= (instanceId, description, isForced, busId, persistedGuid, stubInstanceId, clientIPAddress);
#endif

[DataMember]
#if !NETSTANDARD
[JsonPropertyOrder(4)]
#endif
public string InstanceId { get; init; } = string.Empty;

#if !NETSTANDARD
[JsonIgnore]
#endif
public VidPid HardwareId
{
get
Expand All @@ -39,11 +47,15 @@ public VidPid HardwareId
}

[DataMember]
#if !NETSTANDARD
[JsonPropertyOrder(3)]
#endif
public string Description { get; init; } = string.Empty;

[DataMember]
#if !NETSTANDARD
[JsonPropertyOrder(5)]
#endif
public bool IsForced { get; init; }

/// <summary>
Expand All @@ -52,20 +64,26 @@ public VidPid HardwareId
[DataMember(Name = nameof(BusId))]
string? _BusId;

#if !NETSTANDARD
[JsonPropertyOrder(1)]
[JsonConverter(typeof(NullableBusIdJsonConverter))]
#endif
public BusId? BusId
{
get => Automation.BusId.TryParse(_BusId ?? string.Empty, out var busId) ? busId : null;
init => _BusId = value?.ToString();
}

[DataMember]
#if !NETSTANDARD
[JsonPropertyOrder(6)]
#endif
public Guid? PersistedGuid { get; init; }

[DataMember]
#if !NETSTANDARD
[JsonPropertyOrder(7)]
#endif
public string? StubInstanceId { get; init; }

/// <summary>
Expand All @@ -74,20 +92,28 @@ public VidPid HardwareId
[DataMember(Name = nameof(ClientIPAddress))]
string? _ClientIPAddress;

#if !NETSTANDARD
[JsonPropertyOrder(2)]
[JsonConverter(typeof(NullableIPAddressJsonConverter))]
#endif
public IPAddress? ClientIPAddress
{
get => IPAddress.TryParse(_ClientIPAddress, out var clientIPAddress) ? clientIPAddress : null;
init => _ClientIPAddress = value?.ToString();
}

#if !NETSTANDARD
[JsonIgnore]
#endif
public bool IsBound { get => PersistedGuid is not null; }

#if !NETSTANDARD
[JsonIgnore]
#endif
public bool IsConnected { get => BusId is not null; }

#if !NETSTANDARD
[JsonIgnore]
#endif
public bool IsAttached { get => ClientIPAddress is not null; }
}
13 changes: 13 additions & 0 deletions Usbipd.Automation/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023 Frans van Dorsselaer
//
// SPDX-License-Identifier: GPL-3.0-only

// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "SYSLIB1045:Convert to 'GeneratedRegexAttribute'.", Justification = "Not available in netstandard2.0.")]
[assembly: SuppressMessage("Style", "IDE0057:Use range operator", Justification = "Not available in netstandard2.0.")]
4 changes: 4 additions & 0 deletions Usbipd.Automation/NullableBusIdJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: GPL-3.0-only

#if !NETSTANDARD

using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -32,3 +34,5 @@ public override void Write(Utf8JsonWriter writer, BusId? value, JsonSerializerOp
writer.WriteStringValue(value.ToString());
}
}

#endif
4 changes: 4 additions & 0 deletions Usbipd.Automation/NullableIPAddressJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: GPL-3.0-only

#if !NETSTANDARD

using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -33,3 +35,5 @@ public override void Write(Utf8JsonWriter writer, IPAddress? value, JsonSerializ
writer.WriteStringValue(value.ToString());
}
}

#endif
6 changes: 5 additions & 1 deletion Usbipd.Automation/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
// SPDX-License-Identifier: GPL-3.0-only

using System.Runtime.Serialization;
#if !NETSTANDARD
using System.Text.Json.Serialization;
#endif

namespace Usbipd.Automation;

[DataContract]
public sealed partial class State
{
public State() : this([]) { }
public State() { }

#if !NETSTANDARD
[JsonConstructor]
public State(IReadOnlyCollection<Device> devices) => Devices = devices;
#endif

/// <summary>
/// Serialization for <see cref="Devices" />.
Expand Down
9 changes: 5 additions & 4 deletions Usbipd.Automation/Usbipd.Automation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ SPDX-License-Identifier: GPL-3.0-only

<Import Project="..\NetStandard.props" />

<PropertyGroup>
<TargetFrameworks>net8.0-windows10.0.17763;netstandard2.0</TargetFrameworks>
<TargetFramework></TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="usb.ids" />
<AdditionalFiles Include="usb.ids" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UsbIds\UsbIds.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Usbipd.Automation/VidPid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
// SPDX-License-Identifier: GPL-3.0-only

using System.Globalization;
#if !NETSTANDARD
using System.Text.Json.Serialization;
#endif
using System.Text.RegularExpressions;

namespace Usbipd.Automation;

public readonly record struct VidPid
: IComparable<VidPid>
{
#if !NETSTANDARD
[JsonConstructor]
public VidPid(ushort vid, ushort pid) => (Vid, Pid) = (vid, pid);
#endif

public ushort Vid { get; init; }
public ushort Pid { get; init; }
Expand Down
5 changes: 0 additions & 5 deletions Usbipd.PowerShell/Usbipd.PowerShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ SPDX-License-Identifier: GPL-3.0-only
<RuntimeIdentifier>win</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<None Include="$(PkgSystem_Text_Json)\lib\$(TargetFramework)\System.Text.Json.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PowerShellStandard.Library">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 29760e4

Please sign in to comment.