Move ESCL USB code to a separate project

This commit is contained in:
Ben Olden-Cooligan 2023-04-03 18:03:45 -07:00
parent bd02fe6b46
commit 049a9fc703
10 changed files with 147 additions and 25 deletions

View File

@ -5,13 +5,10 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0'">USB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NAPS2.Escl\NAPS2.Escl.csproj" />
<PackageReference Include="LibUsbDotNet" Version="3.0.102-alpha" Condition="'$(TargetFramework)' == 'net6.0'" />
<ProjectReference Include="..\NAPS2.Escl\NAPS2.Escl.csproj" />
</ItemGroup>
</Project>
</Project>

View File

@ -5,18 +5,18 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0'">USB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NAPS2.Escl.Client\NAPS2.Escl.Client.csproj" />
<ProjectReference Include="..\NAPS2.Escl.Server\NAPS2.Escl.Server.csproj" />
<ProjectReference Include="..\NAPS2.Escl.Client\NAPS2.Escl.Client.csproj" />
<ProjectReference Include="..\NAPS2.Escl.Server\NAPS2.Escl.Server.csproj" />
<ProjectReference Include="..\NAPS2.Escl.Usb\NAPS2.Escl.Usb.csproj" />
</ItemGroup>
</Project>
</Project>

View File

@ -1,5 +1,4 @@
#if USB
using NAPS2.Escl.Client;
using NAPS2.Escl.Usb;
using Xunit;
namespace NAPS2.Escl.Tests;
@ -20,4 +19,3 @@ public class UsbTests
Assert.NotNull(caps);
}
}
#endif

32
NAPS2.Escl.Usb/.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/
publish/
bin/
temp/

View File

@ -0,0 +1,61 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -1,4 +1,3 @@
#if USB
using System.Net;
using System.Net.Sockets;
using System.Text;
@ -6,8 +5,9 @@ using LibUsbDotNet;
using LibUsbDotNet.Info;
using LibUsbDotNet.LibUsb;
using LibUsbDotNet.Main;
using NAPS2.Escl.Client;
namespace NAPS2.Escl.Client;
namespace NAPS2.Escl.Usb;
public class EsclUsbContext : IDisposable
{
@ -153,4 +153,3 @@ public class EsclUsbContext : IDisposable
_usbContext.Dispose();
}
}
#endif

View File

@ -1,5 +1,3 @@
#if USB
namespace NAPS2.Escl.Client;
namespace NAPS2.Escl.Usb;
public record EsclUsbDescriptor(int VendorId, int ProductId, string SerialNumber, string Manufacturer, string Product);
#endif

View File

@ -1,9 +1,8 @@
#if USB
using LibUsbDotNet;
using LibUsbDotNet;
using LibUsbDotNet.Info;
using LibUsbDotNet.LibUsb;
namespace NAPS2.Escl.Client;
namespace NAPS2.Escl.Usb;
public class EsclUsbPoller
{
@ -50,4 +49,3 @@ public class EsclUsbPoller
});
}
}
#endif

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NAPS2.Escl\NAPS2.Escl.csproj" />
<ProjectReference Include="..\NAPS2.Escl.Client\NAPS2.Escl.Client.csproj" />
<PackageReference Include="LibUsbDotNet" Version="3.0.102-alpha" />
</ItemGroup>
</Project>

View File

@ -68,6 +68,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAPS2.Sdk.Worker", "NAPS2.S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAPS2.Sdk.Worker.Build", "NAPS2.Sdk.Worker\NAPS2.Sdk.Worker.Build.csproj", "{786DD865-259C-462C-A311-06A227D41EE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAPS2.Escl.Usb", "NAPS2.Escl.Usb\NAPS2.Escl.Usb.csproj", "{33721E7A-6C67-497B-B21F-0A965A9B23B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -539,6 +541,26 @@ Global
{786DD865-259C-462C-A311-06A227D41EE3}.Release-Linux|Any CPU.ActiveCfg = Release|Any CPU
{786DD865-259C-462C-A311-06A227D41EE3}.Release-Msi|Any CPU.ActiveCfg = Release|Any CPU
{786DD865-259C-462C-A311-06A227D41EE3}.Release-Zip|Any CPU.ActiveCfg = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.DebugLang|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.DebugLang|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release|Any CPU.Build.0 = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Msi|Any CPU.ActiveCfg = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Msi|Any CPU.Build.0 = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Zip|Any CPU.ActiveCfg = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Zip|Any CPU.Build.0 = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Tools|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Tools|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Linux|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Linux|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Windows|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Windows|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Mac|Any CPU.ActiveCfg = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Debug-Mac|Any CPU.Build.0 = Debug|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Linux|Any CPU.ActiveCfg = Release|Any CPU
{33721E7A-6C67-497B-B21F-0A965A9B23B9}.Release-Linux|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE