forked from OpenTabletDriver/OpenTabletDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple configs into OpenTabletDriver.Configurations
- Loading branch information
Showing
147 changed files
with
104 additions
and
23 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
OpenTabletDriver.Configurations/OpenTabletDriver.Configurations.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup Label="Project Properties"> | ||
<TargetFrameworks>net5</TargetFrameworks> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<VersionPrefix>0.6.0.0</VersionPrefix> | ||
<NoWarn>VSTHRD100; VSTHRD101; VSTHRD110; VSTHRD200</NoWarn> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label="NuGet Package Information"> | ||
<PackageId>OpenTabletDriver.Configurations</PackageId> | ||
<Version>0.6.0.0</Version> | ||
<Authors>InfinityGhost</Authors> | ||
<Description>OpenTabletDriver tablet configurations</Description> | ||
<PackageOutputPath>../nupkg</PackageOutputPath> | ||
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="NuGet Packages"> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Project References"> | ||
<ProjectReference Include="..\OpenTabletDriver.Plugin\OpenTabletDriver.Plugin.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Configurations"> | ||
<EmbeddedResource Include=".\Configurations\*\*.json"> | ||
<IncludeInPackage>true</IncludeInPackage> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 42 additions & 2 deletions
44
OpenTabletDriver.Desktop/DesktopDeviceConfigurationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using OpenTabletDriver.Configurations; | ||
using OpenTabletDriver.Plugin; | ||
using OpenTabletDriver.Plugin.Components; | ||
using OpenTabletDriver.Plugin.Tablet; | ||
|
||
#nullable enable | ||
|
||
namespace OpenTabletDriver.Desktop | ||
{ | ||
public class DesktopDeviceConfigurationProvider : IDeviceConfigurationProvider | ||
{ | ||
private readonly DeviceConfigurationProvider _inAssemblyConfigurationProvider = new(); | ||
|
||
public IEnumerable<TabletConfiguration> TabletConfigurations | ||
{ | ||
get | ||
{ | ||
var files = Directory.EnumerateFiles(AppInfo.Current.ConfigurationDirectory, "*.json", SearchOption.AllDirectories); | ||
return files.Select(path => Serialization.Deserialize<TabletConfiguration>(File.OpenRead(path))); | ||
IEnumerable<(ConfigurationSource, TabletConfiguration)> jsonConfigurations = Array.Empty<(ConfigurationSource, TabletConfiguration)>(); | ||
|
||
if (Directory.Exists(AppInfo.Current.ConfigurationDirectory)) | ||
{ | ||
var files = Directory.EnumerateFiles(AppInfo.Current.ConfigurationDirectory, "*.json", SearchOption.AllDirectories); | ||
|
||
jsonConfigurations = files.Select(path => Serialization.Deserialize<TabletConfiguration>(File.OpenRead(path))) | ||
.Select(jsonConfig => (ConfigurationSource.File, jsonConfig)); | ||
} | ||
else | ||
{ | ||
Log.Write("Detect", $"The configuration directory '{AppInfo.Current.ConfigurationDirectory}' does not exist.", LogLevel.Warning); | ||
} | ||
|
||
return _inAssemblyConfigurationProvider.TabletConfigurations | ||
.Select(asmConfig => (ConfigurationSource.Assembly, asmConfig)) | ||
.Concat(jsonConfigurations) | ||
.GroupBy(sourcedConfig => sourcedConfig.Item2.Name) | ||
.Select(multiSourcedConfig => | ||
{ | ||
var asmConfig = multiSourcedConfig.Where(m => m.Item1 == ConfigurationSource.Assembly) | ||
.Select(m => m.Item2) | ||
.FirstOrDefault(); | ||
var jsonConfig = multiSourcedConfig.Where(m => m.Item1 == ConfigurationSource.File) | ||
.Select(m => m.Item2) | ||
.FirstOrDefault(); | ||
|
||
return jsonConfig ?? asmConfig!; | ||
}); | ||
} | ||
} | ||
|
||
private enum ConfigurationSource | ||
{ | ||
Assembly, | ||
File | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters