mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-18 23:07:15 -05:00
add game bar and some other functions, upgrade to .NET 6
This commit is contained in:
1 parent
e1800b8d50
commit
6f5f7c4dd3
54 files changed
+2022
-2857
No files matched your search
+2
-1
@@ -337,4 +337,5 @@ ASALocalRun/
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
healthchecksdb
|
||||
*.clef
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30128.74
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32014.148
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorControl", "ColorControl\ColorControl.csproj", "{A6005D08-70F0-44CB-A384-9219EBA84F21}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorControl", "ColorControl\ColorControl.csproj", "{A6005D08-70F0-44CB-A384-9219EBA84F21}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,8 +15,8 @@ Global
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|x64.Build.0 = Debug|x64
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|x64.ActiveCfg = Release|x64
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"Build":"0.3.261602\u002Befb3cc30a24e699e6e4337f263a2b9478f04f618","CurrentProject":"ColorControl.csproj","EntryPoints":["ColorControl.csproj"],"Properties":{}}
|
||||
@@ -1,4 +1,5 @@
|
||||
using ATI.ADL;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -49,7 +50,7 @@ namespace ColorControl
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = _JsonSerializer.Serialize(_presets);
|
||||
var json = JsonConvert.SerializeObject(_presets);
|
||||
File.WriteAllText(_presetsFilename, json);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
{
|
||||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
||||
"version": "2.1.0",
|
||||
"runs": [
|
||||
{
|
||||
"tool": {
|
||||
"driver": {
|
||||
"name": "Dependency Analysis",
|
||||
"semanticVersion": "0.3.261602",
|
||||
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview",
|
||||
"rules": [
|
||||
{
|
||||
"id": "UA103",
|
||||
"name": "ReferenceToBeDeleted",
|
||||
"fullDescription": {
|
||||
"text": "References that need to be deleted in order to upgrade the project to chosen TFM"
|
||||
},
|
||||
"helpUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
|
||||
},
|
||||
{
|
||||
"id": "UA106",
|
||||
"name": "PackageToBeAdded",
|
||||
"fullDescription": {
|
||||
"text": "Packages that need to be added in order to upgrade the project to chosen TFM"
|
||||
},
|
||||
"helpUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
|
||||
},
|
||||
{
|
||||
"id": "UA108",
|
||||
"name": "FrameworkReferenceToBeAdded",
|
||||
"fullDescription": {
|
||||
"text": "Framework Reference that need to be added in order to upgrade the project to chosen TFM"
|
||||
},
|
||||
"helpUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"ruleId": "UA103",
|
||||
"message": {
|
||||
"text": "Reference to System.Configuration needs to be deleted."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA103",
|
||||
"message": {
|
||||
"text": "Reference to System.ServiceModel needs to be deleted."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA103",
|
||||
"message": {
|
||||
"text": "Reference to System.Web needs to be deleted."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA103",
|
||||
"message": {
|
||||
"text": "Reference to System.Web.Extensions needs to be deleted."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.Configuration.ConfigurationManager, Version=5.0.0 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.Primitives, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.Http, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.Duplex, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.NetTcp, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.Security, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package System.ServiceModel.Federation, Version=4.8.1 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.3.261602 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA106",
|
||||
"message": {
|
||||
"text": "Package Microsoft.Windows.Compatibility, Version=6.0.0 needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"ruleId": "UA108",
|
||||
"message": {
|
||||
"text": "Framework Reference to Microsoft.AspNetCore.App needs to be added."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/ColorControl.csproj"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"columnKind": "utf16CodeUnits"
|
||||
},
|
||||
{
|
||||
"tool": {
|
||||
"driver": {
|
||||
"name": "API Upgradability",
|
||||
"semanticVersion": "0.3.261602",
|
||||
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview"
|
||||
}
|
||||
},
|
||||
"results": [],
|
||||
"columnKind": "utf16CodeUnits"
|
||||
},
|
||||
{
|
||||
"tool": {
|
||||
"driver": {
|
||||
"name": "Component Analysis",
|
||||
"semanticVersion": "0.3.261602",
|
||||
"informationUri": "https://docs.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview",
|
||||
"rules": [
|
||||
{
|
||||
"id": "UA202",
|
||||
"name": "Microsoft.DotNet.UpgradeAssistant.Extensions.Windows.WinformsDpiSettingUpdater",
|
||||
"fullDescription": {
|
||||
"text": "Winforms Source Updater"
|
||||
},
|
||||
"helpUri": "about:blank"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"ruleId": "UA202",
|
||||
"message": {
|
||||
"text": "HighDpiMode needs to set in Main() instead of app.config or app.manifest - Application.SetHighDpiMode(HighDpiMode.<setting>). It is recommended to use SystemAware as the HighDpiMode option for better results."
|
||||
},
|
||||
"locations": [
|
||||
{
|
||||
"physicalLocation": {
|
||||
"artifactLocation": {
|
||||
"uri": "file:///C:/Users/vinni/source/repos/ColorControl/ColorControl/Program.cs"
|
||||
},
|
||||
"region": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"columnKind": "utf16CodeUnits"
|
||||
}
|
||||
]
|
||||
}
|
||||
+12
-12
@@ -1,29 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="PacketDotNet" publicKeyToken="451414c7667b2a58" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
|
||||
<assemblyIdentity name="PacketDotNet" publicKeyToken="451414c7667b2a58" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<System.Windows.Forms.ApplicationConfigurationSection>
|
||||
<add key="DpiAwareness" value="PerMonitorV2" />
|
||||
<add key="DpiAwareness" value="PerMonitorV2"/>
|
||||
</System.Windows.Forms.ApplicationConfigurationSection>
|
||||
</configuration>
|
||||
</configuration>
|
||||
@@ -1,17 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A6005D08-70F0-44CB-A384-9219EBA84F21}</ProjectGuid>
|
||||
<TargetFramework>net6.0-windows10.0.20348.0</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>ColorControl</RootNamespace>
|
||||
<AssemblyName>ColorControl</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
@@ -26,271 +16,52 @@
|
||||
<UpdateUrl>https://www.maassoft.com/downloads/ColorControl/</UpdateUrl>
|
||||
<ProductName>ColorControl</ProductName>
|
||||
<PublisherName>Maassoft</PublisherName>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>4.5.0.0</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<Company>Maassoft</Company>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>5.0.0.0</ApplicationVersion>
|
||||
<Version>5.0.0.0</Version>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<BootstrapperEnabled>false</BootstrapperEnabled>
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UseWPF>false</UseWPF>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
<ApplicationIcon>pngbarn.ico</ApplicationIcon>
|
||||
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
|
||||
<Copyright>2020-2022 Maassoft</Copyright>
|
||||
<Authors>Maassoft</Authors>
|
||||
<ManifestCertificateThumbprint>CF0BC153EA664CD97AC6F234B91F45D34630958F</ManifestCertificateThumbprint>
|
||||
<ManifestKeyFile>ColorControl_1_TemporaryKey.pfx</ManifestKeyFile>
|
||||
<GenerateManifests>true</GenerateManifests>
|
||||
<TargetZone>LocalIntranet</TargetZone>
|
||||
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
||||
<SignManifests>true</SignManifests>
|
||||
<AssemblyOriginatorKeyFile>ColorControl_TemporaryKey.pfx</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ManifestCertificateThumbprint>CF0BC153EA664CD97AC6F234B91F45D34630958F</ManifestCertificateThumbprint>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ManifestKeyFile>ColorControl_1_TemporaryKey.pfx</ManifestKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GenerateManifests>true</GenerateManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetZone>LocalIntranet</TargetZone>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignManifests>true</SignManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>ColorControl_TemporaryKey.pfx</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>pngbarn.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.9.1.0, Culture=neutral, PublicKeyToken=e25603a88b3aa7da, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\TaskScheduler.2.9.1\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Native, Version=0.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Native.0.1.1\lib\net46\Native.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.7.10\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NStandard, Version=0.8.9.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NStandard.0.8.9\lib\net46\NStandard.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NvAPIWrapper, Version=0.8.1.100, Culture=neutral, PublicKeyToken=310fd07b25df79b3, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NvAPIWrapper.Net.0.8.1.101\lib\net45\NvAPIWrapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NWin32, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NWin32.1.2.0\lib\net46\NWin32.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PacketDotNet, Version=1.2.0.0, Culture=neutral, PublicKeyToken=451414c7667b2a58, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\PacketDotNet.1.2.0\lib\net45\PacketDotNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="SharpPcap, Version=5.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpPcap.5.4.0\lib\netstandard2.0\SharpPcap.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Windows">
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ADL.cs" />
|
||||
<Compile Include="ADLWrapper.cs" />
|
||||
<Compile Include="AmdDisplayInfo.cs" />
|
||||
<Compile Include="AppContext.cs" />
|
||||
<Compile Include="CCD.cs" />
|
||||
<Compile Include="LgDevice.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<Compile Update="Properties\Settings.Designer.cs">
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="RemoteControlPanel.cs">
|
||||
<Compile Update="RemoteControlPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RemoteControlPanel.Designer.cs">
|
||||
<DependentUpon>RemoteControlPanel.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UserSessionInfo.cs" />
|
||||
<Compile Include="ServiceBase.cs" />
|
||||
<Compile Include="NvDisplayInfo.cs" />
|
||||
<Compile Include="MessageForms.cs" />
|
||||
<Compile Include="GraphicsService.cs" />
|
||||
<Compile Include="AmdService.cs" />
|
||||
<Compile Include="AmdPreset.cs" />
|
||||
<Compile Include="RemoteControlForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RemoteControlForm.Designer.cs">
|
||||
<DependentUpon>RemoteControlForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="StartUpParams.cs" />
|
||||
<Compile Include="LgServiceConfig.cs" />
|
||||
<Compile Include="WOL.cs" />
|
||||
<Compile Include="RestartDetector.cs" />
|
||||
<Compile Include="ExceptionExtensions.cs" />
|
||||
<Compile Include="lgtv\App.cs" />
|
||||
<Compile Include="lgtv\Channel.cs" />
|
||||
<Compile Include="lgtv\ClientKeyStore.cs" />
|
||||
<Compile Include="lgtv\ExternalInput.cs" />
|
||||
<Compile Include="lgtv\IsConnectedDelegate.cs" />
|
||||
<Compile Include="lgtv\LgTvApi.cs" />
|
||||
<Compile Include="lgtv\LgTvConnection.cs" />
|
||||
<Compile Include="lgtv\LgWebOsMouseService.cs" />
|
||||
<Compile Include="lgtv\MessageType.cs" />
|
||||
<Compile Include="lgtv\RawRequestMessage.cs" />
|
||||
<Compile Include="lgtv\RequestMessage.cs" />
|
||||
<Compile Include="PnpDev.cs" />
|
||||
<Compile Include="TreeNodeBuilder.cs" />
|
||||
<Compile Include="ColorDataConverter.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="lgtv\LgApp.cs" />
|
||||
<Compile Include="PresetBase.cs" />
|
||||
<Compile Include="LgPreset.cs" />
|
||||
<Compile Include="NvPreset.cs" />
|
||||
<Compile Include="LgService.cs" />
|
||||
<Compile Include="NvService.cs" />
|
||||
<Compile Include="ScreenInterrogatory.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainForm.Designer.cs">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Resources\LG_register.json" />
|
||||
<EmbeddedResource Include="Resources\RC_coords.txt" />
|
||||
<None Include="ColorControl_1_TemporaryKey.pfx" />
|
||||
<EmbeddedResource Include="Resources\LG_remote.jpg" />
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="RemoteControlForm.resx">
|
||||
<DependentUpon>RemoteControlForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="RemoteControlPanel.resx">
|
||||
<DependentUpon>RemoteControlPanel.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="ColorControl_TemporaryKey.pfx" />
|
||||
<Content Include="LgPresets.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="lgtv\README.md" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\app.manifest" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="pngbarn.ico" />
|
||||
@@ -309,5 +80,28 @@
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NLog" Version="4.7.13" />
|
||||
<PackageReference Include="NStandard" Version="0.8.28" />
|
||||
<PackageReference Include="NvAPIWrapper.Net" Version="0.8.1.101" />
|
||||
<PackageReference Include="NWin32" Version="1.2.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.9.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,27 +1,40 @@
|
||||
using NvAPIWrapper.Display;
|
||||
using Newtonsoft.Json;
|
||||
using NvAPIWrapper.Display;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace ColorControl
|
||||
{
|
||||
public class ColorDataConverter : JavaScriptConverter
|
||||
public class ColorDataConverter : JsonConverter<ColorData>
|
||||
{
|
||||
public override IEnumerable<Type> SupportedTypes
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ColorData ReadJson(JsonReader reader, Type objectType, ColorData existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
get { return new List<Type>() { typeof(ColorData) }; }
|
||||
var result = new Dictionary<string, object>();
|
||||
|
||||
if (reader.TokenType == JsonToken.StartObject)
|
||||
{
|
||||
reader.Read();
|
||||
while (reader.TokenType == JsonToken.PropertyName)
|
||||
{
|
||||
var propertyName = reader.Value;
|
||||
|
||||
reader.Read();
|
||||
var value = reader.Value;
|
||||
|
||||
result.Add(propertyName.ToString(), value);
|
||||
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
|
||||
return NvPreset.GenerateColorData(result);
|
||||
}
|
||||
|
||||
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
|
||||
public override void WriteJson(JsonWriter writer, ColorData value, JsonSerializer serializer)
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
if (obj == null) return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
|
||||
{
|
||||
return NvPreset.GenerateColorData(dictionary);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,17 @@
|
||||
public class Config
|
||||
{
|
||||
public bool StartMinimized { get; set; }
|
||||
|
||||
public bool MinimizeOnClose { get; set; }
|
||||
|
||||
public bool MinimizeToTray { get; set; }
|
||||
|
||||
public bool CheckForUpdates { get; set; }
|
||||
|
||||
public int DisplaySettingsDelay { get; set; }
|
||||
|
||||
public string ScreenSaverShortcut { get; set; }
|
||||
|
||||
public int FormWidth { get; set; }
|
||||
public int FormHeight { get; set; }
|
||||
|
||||
public int NvPresetId_ApplyOnStartup { get; set; }
|
||||
|
||||
public int AmdPresetId_ApplyOnStartup { get; set; }
|
||||
|
||||
public bool FixChromeFonts { get; set; }
|
||||
public bool UseGdiScaling { get; set; }
|
||||
|
||||
public Config()
|
||||
{
|
||||
@@ -32,6 +24,7 @@
|
||||
MinimizeToTray = true;
|
||||
CheckForUpdates = true;
|
||||
FixChromeFonts = false;
|
||||
UseGdiScaling = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
-17
@@ -19,12 +19,17 @@ namespace ColorControl
|
||||
public decimal MinValue { get; set; }
|
||||
public decimal MaxValue { get; set; }
|
||||
public string Category { get; set; }
|
||||
public string Title { get; set; }
|
||||
public int CurrentValue { get; set; }
|
||||
public LgPreset Preset { get; set; }
|
||||
}
|
||||
|
||||
public class LgDevicePictureSettings
|
||||
{
|
||||
public int Backlight { get; set; }
|
||||
public int Contrast { get; set; }
|
||||
public int Brightness { get; set; }
|
||||
public int Color { get; set; }
|
||||
}
|
||||
|
||||
public enum PowerState
|
||||
@@ -46,8 +51,9 @@ namespace ColorControl
|
||||
|
||||
protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
public static Func<string, string[], bool> ExternalServiceHandler;
|
||||
public static List<string> DefaultActionsOnGameBar = new() { "backlight", "contrast", "brightness", "color" };
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string IpAddress { get; private set; }
|
||||
public string MacAddress { get; private set; }
|
||||
public bool IsCustom { get; private set; }
|
||||
@@ -60,6 +66,26 @@ namespace ColorControl
|
||||
public bool PowerOffOnStandby { get; set; }
|
||||
public bool PowerSwitchOnScreenSaver { get; set; }
|
||||
|
||||
private List<string> _actionsForGameBar;
|
||||
|
||||
public List<string> ActionsOnGameBar {
|
||||
get
|
||||
{
|
||||
return _actionsForGameBar;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value?.Any() == false)
|
||||
{
|
||||
_actionsForGameBar = DefaultActionsOnGameBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
_actionsForGameBar = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public PowerState CurrentState { get; set; }
|
||||
|
||||
@@ -85,10 +111,13 @@ namespace ColorControl
|
||||
[JsonIgnore]
|
||||
public LgDevicePictureSettings PictureSettings { get; private set; }
|
||||
|
||||
public event EventHandler PictureSettingsChangedEvent;
|
||||
|
||||
[JsonConstructor]
|
||||
public LgDevice(string name, string ipAddress, string macAddress, bool isCustom = true, bool isDummy = false)
|
||||
{
|
||||
PictureSettings = new LgDevicePictureSettings();
|
||||
ActionsOnGameBar = new List<string> { "backlight", "contrast", "brightness", "color" };
|
||||
|
||||
Name = name;
|
||||
IpAddress = ipAddress;
|
||||
@@ -101,19 +130,20 @@ namespace ColorControl
|
||||
AddGenericPictureAction("brightness", minValue: 0, maxValue: 100);
|
||||
AddGenericPictureAction("contrast", minValue: 0, maxValue: 100);
|
||||
AddGenericPictureAction("color", minValue: 0, maxValue: 100);
|
||||
AddGenericPictureAction("pictureMode", typeof(PictureMode));
|
||||
AddGenericPictureAction("colorGamut", typeof(ColorGamut));
|
||||
AddGenericPictureAction("dynamicContrast", typeof(OffToAuto));
|
||||
AddGenericPictureAction("pictureMode", typeof(PictureMode), title: "Picture Mode");
|
||||
AddGenericPictureAction("colorGamut", typeof(ColorGamut), title: "Color Gamut");
|
||||
AddGenericPictureAction("dynamicContrast", typeof(OffToHigh), title: "Dynamic Contrast");
|
||||
AddGenericPictureAction("gamma", typeof(GammaExp));
|
||||
//AddGenericPictureAction("dynamicColor", typeof(OffToAuto));
|
||||
//AddGenericPictureAction("superResolution", typeof(OffToAuto));
|
||||
AddGenericPictureAction("peakBrightness", typeof(OffToAuto));
|
||||
AddGenericPictureAction("smoothGradation", typeof(OffToAuto));
|
||||
AddGenericPictureAction("energySaving", typeof(EnergySaving));
|
||||
AddGenericPictureAction("hdrDynamicToneMapping", typeof(DynamicTonemapping));
|
||||
AddGenericPictureAction("peakBrightness", typeof(OffToHigh), title: "Peak Brightness");
|
||||
AddGenericPictureAction("smoothGradation", typeof(OffToAuto), title: "Smooth Gradation");
|
||||
AddGenericPictureAction("energySaving", typeof(EnergySaving), title: "Energy Saving");
|
||||
AddGenericPictureAction("hdrDynamicToneMapping", typeof(DynamicTonemapping), title: "HDR Dynamic Tone Mapping");
|
||||
//AddGenericPictureAction("blackLevel", typeof(LowToAuto));
|
||||
//AddGenericPictureAction("ambientLightCompensation", typeof(OffToAuto2));
|
||||
//AddGenericPictureAction("truMotionMode", typeof(TruMotionMode));
|
||||
AddGenericPictureAction("motionProOLED", typeof(OffToHigh));
|
||||
AddGenericPictureAction("motionProOLED", typeof(OffToHigh), title: "OLED Motion Pro");
|
||||
AddGenericPictureAction("uhdDeepColorHDMI1", typeof(OffToOn), category: "other");
|
||||
AddGenericPictureAction("uhdDeepColorHDMI2", typeof(OffToOn), category: "other");
|
||||
AddGenericPictureAction("uhdDeepColorHDMI3", typeof(OffToOn), category: "other");
|
||||
@@ -132,6 +162,9 @@ namespace ColorControl
|
||||
AddGenericPictureAction("adjustingLuminance", minValue: -50, maxValue: 50);
|
||||
AddInvokableAction("turnScreenOff", new Func<Dictionary<string, object>, bool>(TurnScreenOffAction));
|
||||
AddInvokableAction("turnScreenOn", new Func<Dictionary<string, object>, bool>(TurnScreenOnAction));
|
||||
|
||||
AddInternalPresetAction(new LgPreset("InStart", "com.webos.app.factorywin", new[] { "0", "4", "1", "3" }));
|
||||
AddInternalPresetAction(new LgPreset("Software Update", "com.webos.app.softwareupdate"));
|
||||
}
|
||||
|
||||
private void AddInvokableAction(string name, Func<Dictionary<string, object>, bool> function)
|
||||
@@ -145,7 +178,18 @@ namespace ColorControl
|
||||
_invokableActions.Add(action);
|
||||
}
|
||||
|
||||
private void AddGenericPictureAction(string name, Type type = null, decimal minValue = 0, decimal maxValue = 0, string category = "picture")
|
||||
private void AddInternalPresetAction(LgPreset preset)
|
||||
{
|
||||
var action = new InvokableAction
|
||||
{
|
||||
Name = preset.name,
|
||||
Preset = preset
|
||||
};
|
||||
|
||||
_invokableActions.Add(action);
|
||||
}
|
||||
|
||||
private void AddGenericPictureAction(string name, Type type = null, decimal minValue = 0, decimal maxValue = 0, string category = "picture", string title = null)
|
||||
{
|
||||
var action = new InvokableAction
|
||||
{
|
||||
@@ -154,12 +198,26 @@ namespace ColorControl
|
||||
EnumType = type,
|
||||
MinValue = minValue,
|
||||
MaxValue = maxValue,
|
||||
Category = category
|
||||
Category = category,
|
||||
Title = title == null ? name.Substring(0, 1).ToUpper() + name.Substring(1) : title
|
||||
};
|
||||
|
||||
_invokableActions.Add(action);
|
||||
}
|
||||
|
||||
public void AddGameBarAction(string name)
|
||||
{
|
||||
if (!ActionsOnGameBar.Contains(name))
|
||||
{
|
||||
ActionsOnGameBar.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveGameBarAction(string name)
|
||||
{
|
||||
ActionsOnGameBar.Remove(name);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
//return (IsDummy ? string.Empty : (IsCustom ? "Custom: " : "Auto detect: ")) + $"{Name}" + (!string.IsNullOrEmpty(IpAddress) ? $" ({IpAddress})" : string.Empty);
|
||||
@@ -242,8 +300,18 @@ namespace ColorControl
|
||||
{
|
||||
PictureSettings.Contrast = Utils.ParseDynamicAsInt(settings.contrast, PictureSettings.Contrast);
|
||||
}
|
||||
if (settings.brightness != null)
|
||||
{
|
||||
PictureSettings.Brightness = Utils.ParseDynamicAsInt(settings.brightness, PictureSettings.Brightness);
|
||||
}
|
||||
if (settings.color != null)
|
||||
{
|
||||
PictureSettings.Color = Utils.ParseDynamicAsInt(settings.color, PictureSettings.Color);
|
||||
}
|
||||
}
|
||||
|
||||
PictureSettingsChangedEvent?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -323,7 +391,7 @@ namespace ColorControl
|
||||
try
|
||||
{
|
||||
dynamic @params = null;
|
||||
if (config.AllowFirmwareDowngrade && preset.appId.Equals("com.webos.app.softwareupdate"))
|
||||
if (config.ShowAdvancedActions && preset.appId.Equals("com.webos.app.softwareupdate"))
|
||||
{
|
||||
@params = new { mode = "user", flagUpdate = true };
|
||||
}
|
||||
@@ -409,10 +477,7 @@ namespace ColorControl
|
||||
var action = _invokableActions.FirstOrDefault(a => a.Name.Equals(key, StringComparison.OrdinalIgnoreCase));
|
||||
if (action != null)
|
||||
{
|
||||
if (!key.Equals("WOL"))
|
||||
{
|
||||
ExecuteAction(action, parameters);
|
||||
}
|
||||
ExecuteAction(action, parameters);
|
||||
|
||||
executeKey = false;
|
||||
}
|
||||
@@ -458,7 +523,7 @@ namespace ColorControl
|
||||
|
||||
private void SendKey(LgWebOsMouseService mouse, string key)
|
||||
{
|
||||
if (key.Length == 1 && int.TryParse(key, out _))
|
||||
if (key.Length >= 1 && int.TryParse(key[0].ToString(), out _))
|
||||
{
|
||||
key = "_" + key;
|
||||
}
|
||||
@@ -606,6 +671,18 @@ namespace ColorControl
|
||||
return _invokableActions;
|
||||
}
|
||||
|
||||
public List<InvokableAction> GetInvokableActionsForGameBar()
|
||||
{
|
||||
var actions = GetInvokableActions();
|
||||
return actions.Where(a => a.Category == "picture" && (a.EnumType != null && a.EnumType != typeof(PictureMode) || a.MinValue >= 0 && a.MaxValue > 0)).ToList();
|
||||
}
|
||||
|
||||
public List<InvokableAction> GetActionsForGameBar()
|
||||
{
|
||||
var actions = GetInvokableActions();
|
||||
return actions.Where(a => ActionsOnGameBar.Contains(a.Name)).ToList();
|
||||
}
|
||||
|
||||
public async Task PowerOn()
|
||||
{
|
||||
var mouse = await _lgTvApi.GetMouse();
|
||||
@@ -654,6 +731,11 @@ namespace ColorControl
|
||||
await _lgTvApi.SetSystemSettings("backlight", backlight.ToString());
|
||||
}
|
||||
|
||||
internal async Task SetContrast(int contrast)
|
||||
{
|
||||
await _lgTvApi.SetSystemSettings("contrast", contrast.ToString());
|
||||
}
|
||||
|
||||
public async Task SetOLEDMotionPro(string mode)
|
||||
{
|
||||
await _lgTvApi.SetConfig("tv.model.motionProMode", mode);
|
||||
@@ -666,6 +748,8 @@ namespace ColorControl
|
||||
internal async Task SetSystemSettings(string name, string value)
|
||||
{
|
||||
await _lgTvApi.SetSystemSettings(name, value);
|
||||
|
||||
UpdateCurrentValueOfAction(name, value);
|
||||
}
|
||||
|
||||
internal async Task<dynamic> GetPictureSettings()
|
||||
@@ -710,7 +794,34 @@ namespace ColorControl
|
||||
var task = _lgTvApi.SetSystemSettings(settingName, value, category);
|
||||
Utils.WaitForTask(task);
|
||||
|
||||
UpdateCurrentValueOfAction(settingName, value.ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateCurrentValueOfAction(string settingName, string value)
|
||||
{
|
||||
if (settingName != "backlight" && settingName != "contrast" && settingName != "brightness" && settingName != "color")
|
||||
{
|
||||
var action = _invokableActions.FirstOrDefault(a => a.Name == settingName);
|
||||
if (action != null)
|
||||
{
|
||||
if (action.EnumType != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var enumValue = Enum.Parse(action.EnumType, value);
|
||||
var intEnum = (int)enumValue;
|
||||
action.CurrentValue = intEnum;
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
action.CurrentValue = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+134
@@ -0,0 +1,134 @@
|
||||
|
||||
namespace ColorControl
|
||||
{
|
||||
partial class LgGameBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.flowPanel = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.btnClose = new System.Windows.Forms.Button();
|
||||
this.lblTvName = new System.Windows.Forms.Label();
|
||||
this.tmrHide = new System.Windows.Forms.Timer(this.components);
|
||||
this.lblProcessName = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// flowPanel
|
||||
//
|
||||
this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.flowPanel.Location = new System.Drawing.Point(12, 41);
|
||||
this.flowPanel.Name = "flowPanel";
|
||||
this.flowPanel.Size = new System.Drawing.Size(231, 282);
|
||||
this.flowPanel.TabIndex = 0;
|
||||
this.flowPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown);
|
||||
this.flowPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.flowPanel_MouseMove);
|
||||
this.flowPanel.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.flowPanel_PreviewKeyDown);
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnClose.FlatAppearance.BorderColor = System.Drawing.Color.DarkGray;
|
||||
this.btnClose.FlatAppearance.BorderSize = 0;
|
||||
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnClose.ForeColor = System.Drawing.Color.White;
|
||||
this.btnClose.Location = new System.Drawing.Point(240, 0);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(14, 23);
|
||||
this.btnClose.TabIndex = 1;
|
||||
this.btnClose.TabStop = false;
|
||||
this.btnClose.Text = "x";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
//
|
||||
// lblTvName
|
||||
//
|
||||
this.lblTvName.AutoSize = true;
|
||||
this.lblTvName.ForeColor = System.Drawing.Color.White;
|
||||
this.lblTvName.Location = new System.Drawing.Point(12, 0);
|
||||
this.lblTvName.Name = "lblTvName";
|
||||
this.lblTvName.Size = new System.Drawing.Size(25, 13);
|
||||
this.lblTvName.TabIndex = 0;
|
||||
this.lblTvName.Text = " ";
|
||||
//
|
||||
// tmrHide
|
||||
//
|
||||
this.tmrHide.Interval = 5000;
|
||||
this.tmrHide.Tick += new System.EventHandler(this.tmrHide_Tick);
|
||||
//
|
||||
// lblProcessName
|
||||
//
|
||||
this.lblProcessName.AutoSize = true;
|
||||
this.lblProcessName.ForeColor = System.Drawing.Color.White;
|
||||
this.lblProcessName.Location = new System.Drawing.Point(12, 20);
|
||||
this.lblProcessName.Name = "lblProcessName";
|
||||
this.lblProcessName.Size = new System.Drawing.Size(25, 13);
|
||||
this.lblProcessName.TabIndex = 2;
|
||||
this.lblProcessName.Text = " ";
|
||||
//
|
||||
// LgGameBar
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Black;
|
||||
this.ClientSize = new System.Drawing.Size(255, 335);
|
||||
this.Controls.Add(this.lblProcessName);
|
||||
this.Controls.Add(this.lblTvName);
|
||||
this.Controls.Add(this.btnClose);
|
||||
this.Controls.Add(this.flowPanel);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.KeyPreview = true;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "LgGameBar";
|
||||
this.Opacity = 0.7D;
|
||||
this.Text = "RemoteControlForm";
|
||||
this.TopMost = true;
|
||||
this.Activated += new System.EventHandler(this.LgGameBar_Activated);
|
||||
this.Deactivate += new System.EventHandler(this.LgGameBar_Deactivate);
|
||||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.RemoteControlForm_FormClosed);
|
||||
this.Load += new System.EventHandler(this.RemoteControlForm_Load);
|
||||
this.Shown += new System.EventHandler(this.RemoteControlForm_Shown);
|
||||
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.RemoteControlForm_KeyDown);
|
||||
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RemoteControlForm_KeyUp);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.RemoteControlForm_MouseDown);
|
||||
this.Move += new System.EventHandler(this.LgGameBar_Move);
|
||||
this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.RemoteControlForm_PreviewKeyDown);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.FlowLayoutPanel flowPanel;
|
||||
private System.Windows.Forms.Button btnClose;
|
||||
private System.Windows.Forms.Label lblTvName;
|
||||
private System.Windows.Forms.Timer tmrHide;
|
||||
private System.Windows.Forms.Label lblProcessName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
using NWin32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ColorControl
|
||||
{
|
||||
partial class LgGameBar : Form
|
||||
{
|
||||
private class TbSetting
|
||||
{
|
||||
public TrackBar TrackBar { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Type EnumType { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
}
|
||||
|
||||
private LgService _lgService;
|
||||
private LgDevice _lgDevice;
|
||||
private ToolTip _toolTip;
|
||||
private bool _settingChanged = false;
|
||||
private List<TrackBar> _trackBars = new List<TrackBar>();
|
||||
private List<string> _lastActions = new List<string>();
|
||||
|
||||
public LgGameBar(LgService lgService)
|
||||
{
|
||||
_lgService = lgService;
|
||||
|
||||
_lgDevice = _lgService.SelectedDevice;
|
||||
|
||||
_lgDevice.PictureSettingsChangedEvent += LgDevice_PictureSettingsChangedEvent;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_toolTip = new ToolTip();
|
||||
}
|
||||
|
||||
private void GenerateComponents()
|
||||
{
|
||||
var actions = _lgDevice.GetActionsForGameBar();
|
||||
var actionNames = actions.Select(a => a.Name).ToList();
|
||||
|
||||
if (_lastActions.Count == actions.Count && _lastActions.All(a => actionNames.Contains(a))) {
|
||||
return;
|
||||
}
|
||||
|
||||
flowPanel.Controls.Clear();
|
||||
_trackBars.Clear();
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
CreateGroup(action.Title, action.Name, (int)action.MinValue, (int)action.MaxValue, action.EnumType);
|
||||
}
|
||||
|
||||
_lastActions.Clear();
|
||||
_lastActions.AddRange(actionNames);
|
||||
|
||||
Width = 28 + (_trackBars.Count() * 56);
|
||||
}
|
||||
|
||||
private TrackBar CreateGroup(string title, string settingName = null, int min = 0, int max = 100, Type enumType = null)
|
||||
{
|
||||
if (settingName == null)
|
||||
{
|
||||
settingName = title.ToLowerInvariant();
|
||||
}
|
||||
|
||||
var panel = new Panel();
|
||||
panel.Width = 50;
|
||||
panel.Height = flowPanel.Height;
|
||||
var label = new Label();
|
||||
label.Text = title;
|
||||
label.ForeColor = Color.White;
|
||||
label.Parent = panel;
|
||||
|
||||
if (min == 0 && max == 0 && enumType != null)
|
||||
{
|
||||
max = Enum.GetValues(enumType).Length - 1;
|
||||
}
|
||||
|
||||
var trackBar = CreateTrackBar(min, max);
|
||||
trackBar.Top = label.Height;
|
||||
trackBar.Height = panel.Height - trackBar.Top - 4;
|
||||
trackBar.Parent = panel;
|
||||
trackBar.Scroll += tbTrackBar_Scroll;
|
||||
var margin = trackBar.Margin;
|
||||
margin.Top = 0;
|
||||
margin.Bottom = 0;
|
||||
trackBar.Margin = margin;
|
||||
trackBar.ValueChanged += TrackBar_ValueChanged;
|
||||
|
||||
var setting = new TbSetting
|
||||
{
|
||||
TrackBar = trackBar,
|
||||
Name = settingName,
|
||||
EnumType = enumType,
|
||||
PropertyName = title
|
||||
};
|
||||
|
||||
trackBar.Tag = setting;
|
||||
|
||||
panel.Parent = flowPanel;
|
||||
|
||||
_trackBars.Add(trackBar);
|
||||
|
||||
return trackBar;
|
||||
}
|
||||
|
||||
private void TrackBar_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
//var trackBar = sender as TrackBar;
|
||||
|
||||
//if (_toolTip != null)
|
||||
//{
|
||||
// _toolTip.SetToolTip(trackBar, trackBar.Value.ToString());
|
||||
//}
|
||||
}
|
||||
|
||||
private TrackBar CreateTrackBar(int min, int max)
|
||||
{
|
||||
var trackBar = new TrackBar();
|
||||
trackBar.BackColor = Color.Black;
|
||||
trackBar.Orientation = Orientation.Vertical;
|
||||
trackBar.TickFrequency = (max >= 50) ? 5 : 1;
|
||||
trackBar.TickStyle = TickStyle.Both;
|
||||
trackBar.Minimum = min;
|
||||
trackBar.Maximum = max;
|
||||
|
||||
return trackBar;
|
||||
}
|
||||
|
||||
private void LgDevice_PictureSettingsChangedEvent(object sender, EventArgs e)
|
||||
{
|
||||
if (_settingChanged)
|
||||
{
|
||||
_settingChanged = false;
|
||||
return;
|
||||
}
|
||||
BeginInvoke(new Action(UpdateValues));
|
||||
}
|
||||
|
||||
private void UpdateValues()
|
||||
{
|
||||
var dynType = _lgDevice.PictureSettings.GetType();
|
||||
var actions = _lgDevice.GetInvokableActions();
|
||||
foreach (var trackbar in _trackBars.Where(t => !t.Focused))
|
||||
{
|
||||
var setting = (TbSetting)trackbar.Tag;
|
||||
|
||||
if (setting.PropertyName == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var prop = dynType.GetProperty(setting.PropertyName);
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var value = prop.GetValue(_lgDevice.PictureSettings);
|
||||
|
||||
if (value is int intValue)
|
||||
{
|
||||
trackbar.Value = intValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var action = actions.FirstOrDefault(a => a.Name == setting.Name);
|
||||
if (action != null)
|
||||
{
|
||||
trackbar.Value = action.CurrentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoteControlForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
if (e is MouseEventArgs)
|
||||
{
|
||||
var preset = (LgPreset)(sender as Button).Tag;
|
||||
|
||||
var _ = _lgService.ApplyPreset(preset);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void RemoteControlForm_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
NativeMethods.ReleaseCapture();
|
||||
var intPtr = new UIntPtr(2);
|
||||
NativeMethods.SendMessageW(Handle, NativeConstants.WM_NCLBUTTONDOWN, intPtr, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoteControlForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
//var key = e.KeyCode;
|
||||
//HandleKey(key);
|
||||
}
|
||||
|
||||
private void flowPanel_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
||||
{
|
||||
//HandleKey(e.KeyCode);
|
||||
}
|
||||
|
||||
private void HandleKey(Keys key)
|
||||
{
|
||||
var cvt = new KeysConverter();
|
||||
var shortcut = (string)cvt.ConvertTo(key, typeof(string));
|
||||
}
|
||||
|
||||
private void RemoteControlForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
||||
{
|
||||
//HandleKey(e.KeyCode);
|
||||
}
|
||||
|
||||
private void RemoteControlForm_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.F1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HandleKey(e.KeyCode);
|
||||
}
|
||||
|
||||
private void flowPanel_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
ResetAutoHide();
|
||||
}
|
||||
|
||||
private void pnlMouse_MouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void RemoteControlForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void pnlMouse_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void HandleMouse(MouseEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void RemoteControlForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
GenerateComponents();
|
||||
UpdateInfo();
|
||||
ResetAutoHide();
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
{
|
||||
lblTvName.Text = $"Device: {_lgDevice?.Name ?? "No tv selected"}";
|
||||
lblProcessName.Text = $"Current process: {_lgService.MonitorContext?.ForegroundProcess?.ProcessName ?? _lgService.MonitorContext?.LastFullScreenProcessName ?? "No full screen process"}";
|
||||
|
||||
UpdateValues();
|
||||
}
|
||||
|
||||
private void pnlMouse_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
HandleMouse(e);
|
||||
}
|
||||
|
||||
private void pnlMouse_MouseWheel(object sender, MouseEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void LgGameBar_Deactivate(object sender, EventArgs e)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void tmrHide_Tick(object sender, EventArgs e)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void tbTrackBar_Scroll(object sender, EventArgs e)
|
||||
{
|
||||
_settingChanged = true;
|
||||
ResetAutoHide();
|
||||
|
||||
var trackBar = sender as TrackBar;
|
||||
var setting = (TbSetting)trackBar.Tag;
|
||||
|
||||
var value = string.Empty;
|
||||
|
||||
if (setting.EnumType == null)
|
||||
{
|
||||
value = trackBar.Value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
var enumValue = Enum.Parse(setting.EnumType, trackBar.Value.ToString());
|
||||
value = enumValue.ToString();
|
||||
}
|
||||
|
||||
_lgDevice.SetSystemSettings(setting.Name, value).ConfigureAwait(false);
|
||||
|
||||
if (_toolTip != null)
|
||||
{
|
||||
_toolTip.Show(value, trackBar, 10, 50, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
private void LgGameBar_Activated(object sender, EventArgs e)
|
||||
{
|
||||
GenerateComponents();
|
||||
UpdateInfo();
|
||||
ResetAutoHide();
|
||||
}
|
||||
|
||||
private void LgGameBar_Move(object sender, EventArgs e)
|
||||
{
|
||||
ResetAutoHide();
|
||||
}
|
||||
|
||||
private void ResetAutoHide()
|
||||
{
|
||||
tmrHide.Enabled = false;
|
||||
tmrHide.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="tmrHide.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -37,6 +37,16 @@ namespace ColorControl
|
||||
}
|
||||
}
|
||||
|
||||
public LgPreset(string name, string appId, IEnumerable<string> steps = null) : this()
|
||||
{
|
||||
this.name = name;
|
||||
this.appId = appId;
|
||||
if (steps != null)
|
||||
{
|
||||
this.steps.AddRange(steps);
|
||||
}
|
||||
}
|
||||
|
||||
public LgPreset Clone()
|
||||
{
|
||||
var preset = new LgPreset(this);
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace ColorControl
|
||||
}
|
||||
|
||||
public LgServiceConfig Config { get; private set; }
|
||||
public ProcessMonitorContext MonitorContext { get; private set; }
|
||||
|
||||
private string _configFilename;
|
||||
private bool _allowPowerOn;
|
||||
@@ -65,7 +66,7 @@ namespace ColorControl
|
||||
private Task _monitorTask;
|
||||
private int _monitorTaskCounter;
|
||||
private LgPreset _lastTriggeredPreset;
|
||||
|
||||
|
||||
public LgService(string dataPath, bool allowPowerOn) : base(dataPath, "LgPresets.json")
|
||||
{
|
||||
_allowPowerOn = allowPowerOn;
|
||||
@@ -137,9 +138,9 @@ namespace ColorControl
|
||||
{
|
||||
var json = File.ReadAllText(defaultPresetsFileName);
|
||||
|
||||
presets = _JsonDeserializer.Deserialize<List<LgPreset>>(json);
|
||||
presets = JsonConvert.DeserializeObject<List<LgPreset>>(json);
|
||||
}
|
||||
|
||||
|
||||
return presets;
|
||||
}
|
||||
|
||||
@@ -253,7 +254,7 @@ namespace ColorControl
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = _JsonSerializer.Serialize(_presets);
|
||||
var json = JsonConvert.SerializeObject(_presets);
|
||||
File.WriteAllText(_presetsFilename, json);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -547,7 +548,7 @@ namespace ColorControl
|
||||
var validCounter = _monitorTaskCounter;
|
||||
var lastProcessId = 0;
|
||||
|
||||
var monitorContext = new ProcessMonitorContext();
|
||||
MonitorContext = new ProcessMonitorContext();
|
||||
//Process[] lastProcesses = null;
|
||||
|
||||
while (validCounter == _monitorTaskCounter)
|
||||
@@ -622,8 +623,8 @@ namespace ColorControl
|
||||
wasConnected = true;
|
||||
}
|
||||
|
||||
monitorContext.Devices = connectedDevices;
|
||||
monitorContext.RunningProcesses = processes;
|
||||
MonitorContext.Devices = connectedDevices;
|
||||
MonitorContext.RunningProcesses = processes;
|
||||
//if (lastProcesses != null)
|
||||
//{
|
||||
// monitorContext.StartedProcesses = processes.Where(p => !lastProcesses.Any(lp => lp.Id == p.Id)).ToArray();
|
||||
@@ -692,7 +693,7 @@ namespace ColorControl
|
||||
}
|
||||
else
|
||||
{
|
||||
await ExecuteProcessPresets(monitorContext);
|
||||
await ExecuteProcessPresets(MonitorContext);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -714,6 +715,11 @@ namespace ColorControl
|
||||
|
||||
var (processId, isFullScreen) = Utils.GetForegroundProcessIdAndIfFullScreen();
|
||||
|
||||
if (processId == Process.GetCurrentProcess().Id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (processId > 0)
|
||||
{
|
||||
context.ForegroundProcess = context.RunningProcesses.FirstOrDefault(p => p.Id == processId);
|
||||
|
||||
@@ -5,22 +5,14 @@ namespace ColorControl
|
||||
class LgServiceConfig
|
||||
{
|
||||
public bool PowerOnAfterStartup { get; set; }
|
||||
|
||||
public int PowerOnDelayAfterResume { get; set; }
|
||||
|
||||
public int PowerOnRetries { get; set; }
|
||||
|
||||
public string PreferredMacAddress { get; set; }
|
||||
|
||||
public string DeviceSearchKey { get; set; }
|
||||
|
||||
public bool UseOldNpcapWol { get; set; }
|
||||
|
||||
public List<LgDevice> Devices { get; set; }
|
||||
|
||||
public bool ShowRemoteControl { get; set; }
|
||||
|
||||
public bool AllowFirmwareDowngrade { get; set; }
|
||||
public bool ShowAdvancedActions { get; set; }
|
||||
public string GameBarShortcut { get; set; }
|
||||
|
||||
public LgServiceConfig()
|
||||
{
|
||||
|
||||
Generated
+415
-264
File diff suppressed because it is too large.
Load diff
+266
-90
@@ -1,5 +1,6 @@
|
||||
using ATI.ADL;
|
||||
using LgTv;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NStandard;
|
||||
using NvAPIWrapper.Display;
|
||||
@@ -8,8 +9,6 @@ using NWin32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Deployment.Application;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
@@ -23,11 +22,11 @@ namespace ColorControl
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private static string TS_TASKNAME = "ColorControl";
|
||||
private static bool SystemShutdown = false;
|
||||
private static bool EndSession = false;
|
||||
private static bool UserExit = false;
|
||||
private static int SHORTCUTID_SCREENSAVER = -100;
|
||||
private static int SHORTCUTID_GAMEBAR = -101;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
@@ -45,9 +44,9 @@ namespace ColorControl
|
||||
|
||||
private LgService _lgService;
|
||||
|
||||
private MenuItem _nvTrayMenu;
|
||||
private MenuItem _amdTrayMenu;
|
||||
private MenuItem _lgTrayMenu;
|
||||
private ToolStripMenuItem _nvTrayMenu;
|
||||
private ToolStripMenuItem _amdTrayMenu;
|
||||
private ToolStripMenuItem _lgTrayMenu;
|
||||
|
||||
private StartUpParams StartUpParams { get; }
|
||||
|
||||
@@ -57,6 +56,8 @@ namespace ColorControl
|
||||
private bool _checkedForUpdates = false;
|
||||
private string _updateHtmlUrl;
|
||||
|
||||
private LgGameBar _gameBarForm;
|
||||
|
||||
public MainForm(AppContext appContext)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -69,29 +70,32 @@ namespace ColorControl
|
||||
|
||||
MessageForms.MainForm = this;
|
||||
|
||||
_nvTrayMenu = new MenuItem("NVIDIA presets");
|
||||
_amdTrayMenu = new MenuItem("NVIDIA presets");
|
||||
_lgTrayMenu = new MenuItem("LG presets");
|
||||
_nvTrayMenu = new ToolStripMenuItem("NVIDIA presets");
|
||||
_amdTrayMenu = new ToolStripMenuItem("NVIDIA presets");
|
||||
_lgTrayMenu = new ToolStripMenuItem("LG presets");
|
||||
_trayIcon = new NotifyIcon()
|
||||
{
|
||||
Icon = Icon,
|
||||
ContextMenu = new ContextMenu(new MenuItem[] {
|
||||
_nvTrayMenu,
|
||||
_amdTrayMenu,
|
||||
_lgTrayMenu,
|
||||
new MenuItem("-"),
|
||||
new MenuItem("Open", OpenForm),
|
||||
new MenuItem("-"),
|
||||
new MenuItem("Exit", Exit)
|
||||
}),
|
||||
ContextMenuStrip = new ContextMenuStrip(),
|
||||
Visible = _config.MinimizeToTray,
|
||||
Text = Text
|
||||
};
|
||||
|
||||
_trayIcon.ContextMenuStrip.Items.AddRange(new ToolStripItem[] {
|
||||
_nvTrayMenu,
|
||||
_amdTrayMenu,
|
||||
_lgTrayMenu,
|
||||
new ToolStripSeparator(),
|
||||
new ToolStripMenuItem("Open", null, OpenForm),
|
||||
new ToolStripSeparator(),
|
||||
new ToolStripMenuItem("Exit", null, Exit)
|
||||
});
|
||||
|
||||
_trayIcon.MouseDoubleClick += trayIcon_MouseDoubleClick;
|
||||
_trayIcon.ContextMenu.Popup += trayIconContextMenu_Popup;
|
||||
_trayIcon.ContextMenuStrip.Opened += trayIconContextMenu_Popup;
|
||||
_trayIcon.BalloonTipClicked += trayIconBalloonTip_Clicked;
|
||||
|
||||
chkStartAfterLogin.Checked = Utils.TaskExists(TS_TASKNAME, true);
|
||||
chkStartAfterLogin.Checked = Utils.TaskExists(Program.TS_TASKNAME, true);
|
||||
|
||||
chkFixChromeFonts.Enabled = Utils.IsChromeInstalled();
|
||||
if (chkFixChromeFonts.Enabled)
|
||||
@@ -177,8 +181,7 @@ namespace ColorControl
|
||||
|
||||
edtLgMaxPowerOnRetries.Value = _lgService.Config.PowerOnRetries;
|
||||
edtLgDeviceFilter.Text = _lgService.Config.DeviceSearchKey;
|
||||
chkLgOldWolMechanism.Checked = _lgService.Config.UseOldNpcapWol;
|
||||
chkLgAllowDowngrade.Checked = _lgService.Config.AllowFirmwareDowngrade;
|
||||
chkLgShowAdvancedActions.Checked = _lgService.Config.ShowAdvancedActions;
|
||||
|
||||
var values = Enum.GetValues(typeof(ButtonType));
|
||||
foreach (var button in values)
|
||||
@@ -196,6 +199,13 @@ namespace ColorControl
|
||||
_lgService.InstallEventHandlers();
|
||||
|
||||
LgDevice.ExternalServiceHandler = HandleExternalServiceForLgDevice;
|
||||
|
||||
if (!string.IsNullOrEmpty(_lgService.Config.GameBarShortcut))
|
||||
{
|
||||
Utils.RegisterShortcut(Handle, SHORTCUTID_GAMEBAR, _lgService.Config.GameBarShortcut);
|
||||
|
||||
edtLgGameBarShortcut.Text = _lgService.Config.GameBarShortcut;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -236,14 +246,14 @@ namespace ColorControl
|
||||
{
|
||||
_currentVersionInfo = FileVersionInfo.GetVersionInfo(Path.GetFileName(Application.ExecutablePath));
|
||||
|
||||
if (ApplicationDeployment.IsNetworkDeployed)
|
||||
{
|
||||
Text = Application.ProductName + " " + ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (ApplicationDeployment.IsNetworkDeployed)
|
||||
//{
|
||||
// Text = Application.ProductName + " " + ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
Text = Application.ProductName + " " + Application.ProductVersion;
|
||||
}
|
||||
//}
|
||||
|
||||
lblInfo.Text = Text + " - " + _currentVersionInfo.LegalCopyright;
|
||||
|
||||
@@ -316,7 +326,7 @@ namespace ColorControl
|
||||
return;
|
||||
}
|
||||
|
||||
var text = TS_TASKNAME;
|
||||
var text = Program.TS_TASKNAME;
|
||||
foreach (var displayInfo in displays)
|
||||
{
|
||||
var display = displayInfo.Display;
|
||||
@@ -372,7 +382,7 @@ namespace ColorControl
|
||||
return;
|
||||
}
|
||||
|
||||
var text = TS_TASKNAME;
|
||||
var text = Program.TS_TASKNAME;
|
||||
foreach (var displayInfo in displays)
|
||||
{
|
||||
var display = displayInfo.Display;
|
||||
@@ -504,10 +514,29 @@ namespace ColorControl
|
||||
}
|
||||
}
|
||||
|
||||
private Control FindFocusedControl()
|
||||
{
|
||||
ContainerControl container = this;
|
||||
Control control = null;
|
||||
while (container != null)
|
||||
{
|
||||
control = container.ActiveControl;
|
||||
container = control as ContainerControl;
|
||||
}
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
private bool IsShortcutControlFocused()
|
||||
{
|
||||
var control = FindFocusedControl();
|
||||
return control?.Name.Contains("Shortcut") ?? false;
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
// 5. Catch when a HotKey is pressed !
|
||||
if (m.Msg == NativeConstants.WM_HOTKEY && !edtShortcut.Focused && !edtShortcutLg.Focused && !edtAmdShortcut.Focused && !edtBlankScreenSaverShortcut.Focused)
|
||||
if (m.Msg == NativeConstants.WM_HOTKEY && !IsShortcutControlFocused())
|
||||
{
|
||||
int id = m.WParam.ToInt32();
|
||||
|
||||
@@ -515,7 +544,11 @@ namespace ColorControl
|
||||
if (id == SHORTCUTID_SCREENSAVER)
|
||||
{
|
||||
var screenSaver = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "scrnsave.scr");
|
||||
Process.Start(screenSaver);
|
||||
Process.Start("explorer.exe", screenSaver);
|
||||
}
|
||||
else if (id == SHORTCUTID_GAMEBAR)
|
||||
{
|
||||
ToggleGameBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -623,7 +656,7 @@ namespace ColorControl
|
||||
return;
|
||||
}
|
||||
var enabled = chkStartAfterLogin.Checked;
|
||||
Utils.RegisterTask(TS_TASKNAME, enabled);
|
||||
Utils.ExecuteElevated(enabled ? StartUpParams.EnableAutoStartParam : StartUpParams.DisableAutoStartParam);
|
||||
}
|
||||
|
||||
private void LoadConfig()
|
||||
@@ -634,6 +667,7 @@ namespace ColorControl
|
||||
chkCheckForUpdates.Checked = _config.CheckForUpdates;
|
||||
edtDelayDisplaySettings.Value = _config.DisplaySettingsDelay;
|
||||
edtBlankScreenSaverShortcut.Text = _config.ScreenSaverShortcut;
|
||||
chkGdiScaling.Checked = _config.UseGdiScaling;
|
||||
|
||||
if (!string.IsNullOrEmpty(_config.ScreenSaverShortcut))
|
||||
{
|
||||
@@ -663,7 +697,7 @@ namespace ColorControl
|
||||
|
||||
try
|
||||
{
|
||||
var data = Utils.JsonSerializer.Serialize(_config);
|
||||
var data = JsonConvert.SerializeObject(_config);
|
||||
File.WriteAllText(Program.ConfigFilename, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1348,9 +1382,25 @@ namespace ColorControl
|
||||
var preset = _nvService.GetLastAppliedPreset() ?? GetSelectedNvPreset();
|
||||
if (firstTime || preset != null)
|
||||
{
|
||||
chkDitheringEnabled.Checked = preset?.ditheringEnabled ?? true;
|
||||
cbxDitheringBitDepth.SelectedIndex = (int)(preset?.ditheringBits ?? (int)NvDitherBits.Bits8);
|
||||
cbxDitheringMode.SelectedIndex = (int)(preset?.ditheringMode ?? (int)NvDitherMode.Temporal);
|
||||
var ditheringEnabled = true;
|
||||
int ditherBitsIndex;
|
||||
int ditherModeIndex;
|
||||
if (preset == null)
|
||||
{
|
||||
var hdrEnabled = _nvService.IsHDREnabled();
|
||||
ditherBitsIndex = (int)(hdrEnabled ? NvDitherBits.Bits8 : NvDitherBits.Bits6);
|
||||
ditherModeIndex = (int)NvDitherMode.Temporal;
|
||||
}
|
||||
else
|
||||
{
|
||||
ditheringEnabled = preset.ditheringEnabled;
|
||||
ditherBitsIndex = (int)preset.ditheringBits;
|
||||
ditherModeIndex = (int)preset.ditheringMode;
|
||||
}
|
||||
|
||||
chkDitheringEnabled.Checked = ditheringEnabled;
|
||||
cbxDitheringBitDepth.SelectedIndex = ditherBitsIndex;
|
||||
cbxDitheringMode.SelectedIndex = ditherModeIndex;
|
||||
FillGradient();
|
||||
}
|
||||
}
|
||||
@@ -1445,7 +1495,7 @@ namespace ColorControl
|
||||
{
|
||||
var presets = _nvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate);
|
||||
|
||||
_nvTrayMenu.MenuItems.Clear();
|
||||
_nvTrayMenu.DropDownItems.Clear();
|
||||
|
||||
foreach (var preset in presets)
|
||||
{
|
||||
@@ -1455,10 +1505,10 @@ namespace ColorControl
|
||||
name += "\t" + preset.shortcut;
|
||||
}
|
||||
|
||||
var item = new MenuItem(name);
|
||||
var item = new ToolStripMenuItem(name);
|
||||
item.Tag = preset;
|
||||
item.Click += TrayMenuItemNv_Click;
|
||||
_nvTrayMenu.MenuItems.Add(item);
|
||||
_nvTrayMenu.DropDownItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1466,7 +1516,7 @@ namespace ColorControl
|
||||
{
|
||||
var presets = _amdService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate);
|
||||
|
||||
_amdTrayMenu.MenuItems.Clear();
|
||||
_amdTrayMenu.DropDownItems.Clear();
|
||||
|
||||
foreach (var preset in presets)
|
||||
{
|
||||
@@ -1476,16 +1526,16 @@ namespace ColorControl
|
||||
name += "\t" + preset.shortcut;
|
||||
}
|
||||
|
||||
var item = new MenuItem(name);
|
||||
var item = new ToolStripMenuItem(name);
|
||||
item.Tag = preset;
|
||||
item.Click += TrayMenuItemAmd_Click;
|
||||
_amdTrayMenu.MenuItems.Add(item);
|
||||
_amdTrayMenu.DropDownItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void TrayMenuItemNv_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as MenuItem;
|
||||
var item = sender as ToolStripMenuItem;
|
||||
var preset = (NvPreset)item.Tag;
|
||||
|
||||
ApplyNvPreset(preset);
|
||||
@@ -1493,7 +1543,7 @@ namespace ColorControl
|
||||
|
||||
private void TrayMenuItemAmd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as MenuItem;
|
||||
var item = sender as ToolStripMenuItem;
|
||||
var preset = (AmdPreset)item.Tag;
|
||||
|
||||
ApplyAmdPreset(preset);
|
||||
@@ -1524,7 +1574,7 @@ namespace ColorControl
|
||||
{
|
||||
var presets = _lgService.GetPresets().Where(x => !string.IsNullOrEmpty(x.appId) || x.steps.Any());
|
||||
|
||||
_lgTrayMenu.MenuItems.Clear();
|
||||
_lgTrayMenu.DropDownItems.Clear();
|
||||
|
||||
foreach (var preset in presets)
|
||||
{
|
||||
@@ -1534,16 +1584,16 @@ namespace ColorControl
|
||||
name += "\t" + preset.shortcut;
|
||||
}
|
||||
|
||||
var item = new MenuItem(name);
|
||||
var item = new ToolStripMenuItem(name);
|
||||
item.Tag = preset;
|
||||
item.Click += TrayMenuItemLg_Click;
|
||||
_lgTrayMenu.MenuItems.Add(item);
|
||||
_lgTrayMenu.DropDownItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void TrayMenuItemLg_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as MenuItem;
|
||||
var item = sender as ToolStripMenuItem;
|
||||
var preset = (LgPreset)item.Tag;
|
||||
|
||||
ApplyLgPreset(preset);
|
||||
@@ -2182,11 +2232,6 @@ Do you want to continue?";
|
||||
AddOrUpdateItem();
|
||||
}
|
||||
|
||||
private void chkLgAlternateWolMechanism_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
_lgService.Config.UseOldNpcapWol = chkLgOldWolMechanism.Checked;
|
||||
}
|
||||
|
||||
private void MainForm_Deactivate(object sender, EventArgs e)
|
||||
{
|
||||
GlobalSave();
|
||||
@@ -2218,7 +2263,7 @@ Do you want to continue?";
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShortCutExists(string shortcut, int presetId)
|
||||
private bool ShortCutExists(string shortcut, int presetId = 0)
|
||||
{
|
||||
return
|
||||
(_nvService?.GetPresets().Any(x => x.id != presetId && shortcut.Equals(x.shortcut)) ?? false) ||
|
||||
@@ -2708,28 +2753,85 @@ Do you want to continue?"
|
||||
mnuLgOLEDMotionPro.Visible = visible;
|
||||
miLgExpertSeparator1.Visible = visible;
|
||||
|
||||
if (mnuLgExpertBacklight.DropDownItems.Count == 0)
|
||||
{
|
||||
for (var i = 0; i <= 10; i++)
|
||||
{
|
||||
var name = (i * 10).ToString();
|
||||
|
||||
var item = mnuLgExpertBacklight.DropDownItems.Add(name);
|
||||
item.Click += btnLgExpertBacklight_Click;
|
||||
}
|
||||
}
|
||||
|
||||
// Does not work yet, getting a "401 no permissions" error
|
||||
//var task = device?.GetPictureSettings();
|
||||
//var settings = Utils.WaitForTask<dynamic>(task);
|
||||
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Picture Mode", typeof(PictureMode), btnLgExpertColorGamut_Click, "pictureMode");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Color Gamut", typeof(ColorGamut), btnLgExpertColorGamut_Click, "colorGamut");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Dynamic Contrast", typeof(OffToAuto), btnLgExpertColorGamut_Click, "dynamicContrast");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Smooth Gradation", typeof(OffToAuto), btnLgExpertColorGamut_Click, "smoothGradation");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Peak Brightness", typeof(OffToAuto), btnLgExpertColorGamut_Click, "peakBrightness");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "OLED Motion Pro", typeof(OffToHigh), btnLgExpertColorGamut_Click, "motionProOLED");
|
||||
Utils.BuildDropDownMenuEx(mnuLgExpert, "Energy Saving", typeof(EnergySaving), btnLgExpertColorGamut_Click, "energySaving");
|
||||
if (device == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var actions = device.GetInvokableActions();
|
||||
var gameBarActions = device.GetInvokableActionsForGameBar();
|
||||
var activatedGameBarActions = device.GetActionsForGameBar();
|
||||
|
||||
const string gameBarName = "miGameBar";
|
||||
|
||||
foreach (var action in actions.Where(a => !a.Name.Contains("Hdmi", StringComparison.OrdinalIgnoreCase) && (a.EnumType != null || a.MinValue >= 0 && a.MaxValue > a.MinValue)))
|
||||
{
|
||||
var menu = Utils.BuildDropDownMenuEx(mnuLgExpert, action.Title, action.EnumType, btnLgExpertColorGamut_Click, action.Name, (int)action.MinValue, (int)action.MaxValue);
|
||||
|
||||
if (!gameBarActions.Contains(action))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var itemName = $"{menu.Name}_{gameBarName}";
|
||||
var gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Find(itemName, false).FirstOrDefault();
|
||||
|
||||
if (gameBarItem == null)
|
||||
{
|
||||
var separator = new ToolStripSeparator();
|
||||
menu.DropDownItems.Add(separator);
|
||||
|
||||
gameBarItem = (ToolStripMenuItem)menu.DropDownItems.Add("Show in Game Bar", null, miLgGameBarToggle_Click);
|
||||
gameBarItem.CheckOnClick = true;
|
||||
gameBarItem.Checked = activatedGameBarActions.Contains(action);
|
||||
gameBarItem.Name = itemName;
|
||||
gameBarItem.Tag = action.Name;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_lgService.Config.ShowAdvancedActions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var presetActions = actions.Where(a => a.Preset != null);
|
||||
|
||||
if (presetActions.Any() && mnuLgExpert.Items.Find("miLgExpertActionsSeparator", false).Length == 0)
|
||||
{
|
||||
mnuLgExpert.Items.Add(new ToolStripSeparator
|
||||
{
|
||||
Name = "miLgExpertActionsSeparator"
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var presetAction in presetActions)
|
||||
{
|
||||
var menu = Utils.BuildDropDownMenuEx(mnuLgExpert, presetAction.Name, null, btnLgExpertPresetAction_Click, presetAction.Preset);
|
||||
}
|
||||
}
|
||||
|
||||
private void miLgGameBarToggle_Click(object sender, EventArgs e)
|
||||
{
|
||||
var device = _lgService.SelectedDevice;
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = sender as ToolStripMenuItem;
|
||||
if (item.Checked)
|
||||
{
|
||||
device.AddGameBarAction((string)item.Tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
device.RemoveGameBarAction((string)item.Tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnLgExpert_Click(object sender, EventArgs e)
|
||||
@@ -2737,14 +2839,6 @@ Do you want to continue?"
|
||||
mnuLgExpert.Show(btnLgExpert, btnLgExpert.PointToClient(Cursor.Position));
|
||||
}
|
||||
|
||||
private void btnLgExpertBacklight_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as ToolStripItem;
|
||||
var backlight = int.Parse(item.Text);
|
||||
|
||||
_lgService.SelectedDevice?.SetBacklight(backlight);
|
||||
}
|
||||
|
||||
private void btnLgExpertColorGamut_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as ToolStripItem;
|
||||
@@ -2754,6 +2848,14 @@ Do you want to continue?"
|
||||
_lgService.SelectedDevice?.SetSystemSettings(name, value);
|
||||
}
|
||||
|
||||
private void btnLgExpertPresetAction_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = sender as ToolStripItem;
|
||||
var preset = (LgPreset)item.Tag;
|
||||
|
||||
_lgService.ApplyPreset(preset).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void miLgEnableMotionPro_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageForms.QuestionYesNo("Are you sure you want to enable OLED Motion Pro? This app and its creator are in no way accountable for any damages it may cause to your tv.") == DialogResult.Yes)
|
||||
@@ -2818,31 +2920,105 @@ Do you want to continue?"
|
||||
}
|
||||
}
|
||||
|
||||
private void chkLgAllowDowngrade_CheckedChanged(object sender, EventArgs e)
|
||||
private void chkLgShowAdvancedActions_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (chkLgAllowDowngrade.Checked)
|
||||
if (chkLgShowAdvancedActions.Checked)
|
||||
{
|
||||
if (MessageForms.QuestionYesNo(
|
||||
@"Are you sure you want to enable firmware downgrade functionality with the Software Update-app?
|
||||
This may cause irreversible damage to your tv and will void your warranty.
|
||||
@"Are you sure you want to enable the advanced actions under the Expert-button?
|
||||
These actions include:
|
||||
- InStart service menu
|
||||
- Software Update-app with firmware downgrade functionality enabled
|
||||
|
||||
These features may cause irreversible damage to your tv and will void your warranty.
|
||||
This app and its creator are in no way accountable for any damages it may cause to your tv."
|
||||
) != DialogResult.Yes)
|
||||
{
|
||||
chkLgAllowDowngrade.Checked = false;
|
||||
chkLgShowAdvancedActions.Checked = false;
|
||||
return;
|
||||
}
|
||||
MessageForms.InfoOk(
|
||||
@"Firmware downgrade functionality activated.
|
||||
In order to use it, you must create and execute a preset on the LG controller tab that starts the app Software Update (com.webos.app.softwareupdate)."
|
||||
@"Advanced actions activated.
|
||||
The InStart and Software Update items are now visible under the Expert-button."
|
||||
);
|
||||
}
|
||||
|
||||
_lgService.Config.AllowFirmwareDowngrade = chkLgAllowDowngrade.Checked;
|
||||
_lgService.Config.ShowAdvancedActions = chkLgShowAdvancedActions.Checked;
|
||||
}
|
||||
|
||||
private void ToggleGameBar()
|
||||
{
|
||||
if (_gameBarForm == null || !_gameBarForm.Visible)
|
||||
{
|
||||
if (_gameBarForm == null || _gameBarForm.IsDisposed)
|
||||
{
|
||||
_gameBarForm = new LgGameBar(_lgService);
|
||||
}
|
||||
|
||||
_gameBarForm.Show();
|
||||
_gameBarForm.Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
_gameBarForm?.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnLgGameBar_Click(object sender, EventArgs e)
|
||||
{
|
||||
ToggleGameBar();
|
||||
}
|
||||
|
||||
private void edtLgGameBarShortcut_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
((TextBox)sender).Text = Utils.FormatKeyboardShortcut(e);
|
||||
}
|
||||
|
||||
private void edtLgGameBarShortcut_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
Utils.HandleKeyboardShortcutUp(e);
|
||||
}
|
||||
|
||||
private void edtLgGameBarShortcut_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
var text = edtLgGameBarShortcut.Text;
|
||||
|
||||
var blnOk = string.IsNullOrEmpty(text) || !ShortCutExists(text);
|
||||
edtLgGameBarShortcut.ForeColor = blnOk ? Color.Red : SystemColors.WindowText;
|
||||
|
||||
if (blnOk)
|
||||
{
|
||||
_lgService.Config.GameBarShortcut = text;
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Utils.UnregisterHotKey(Handle, SHORTCUTID_GAMEBAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.RegisterShortcut(Handle, SHORTCUTID_GAMEBAR, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chkGdiScaling_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
_config.UseGdiScaling = chkGdiScaling.Checked;
|
||||
}
|
||||
|
||||
private void MainForm_ResizeBegin(object sender, EventArgs e)
|
||||
{
|
||||
SuspendLayout();
|
||||
}
|
||||
|
||||
private void MainForm_ResizeEnd(object sender, EventArgs e)
|
||||
{
|
||||
ResumeLayout(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using NvAPIWrapper;
|
||||
using Newtonsoft.Json;
|
||||
using NvAPIWrapper;
|
||||
using NvAPIWrapper.Display;
|
||||
using NvAPIWrapper.Native.Display;
|
||||
using NvAPIWrapper.Native.Display.Structures;
|
||||
using NvAPIWrapper.Native.GPU.Structures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -71,8 +71,7 @@ namespace ColorControl
|
||||
|
||||
public NvService(string dataPath) : base(dataPath, "NvPresets.json")
|
||||
{
|
||||
var converter = new ColorDataConverter();
|
||||
_JsonDeserializer.RegisterConverters(new[] { converter });
|
||||
AddJsonConverter(new ColorDataConverter());
|
||||
|
||||
LoadPresets();
|
||||
}
|
||||
@@ -135,7 +134,7 @@ namespace ColorControl
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = _JsonSerializer.Serialize(_presets);
|
||||
var json = JsonConvert.SerializeObject(_presets);
|
||||
File.WriteAllText(_presetsFilename, json);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
+15
-2
@@ -1,4 +1,5 @@
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NWin32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -10,11 +11,13 @@ namespace ColorControl
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
public const string TS_TASKNAME = "ColorControl";
|
||||
public static string DataDir { get; private set; }
|
||||
public static string ConfigFilename { get; private set; }
|
||||
public static Config Config { get; private set; }
|
||||
public static AppContext AppContext { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@@ -32,6 +35,11 @@ namespace ColorControl
|
||||
|
||||
LoadConfig();
|
||||
|
||||
if (Config.UseGdiScaling)
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.DpiUnawareGdiScaled);
|
||||
}
|
||||
|
||||
var startUpParams = StartUpParams.Parse(args);
|
||||
|
||||
AppContext = new AppContext(Config, startUpParams);
|
||||
@@ -112,7 +120,7 @@ namespace ColorControl
|
||||
if (File.Exists(ConfigFilename))
|
||||
{
|
||||
var data = File.ReadAllText(ConfigFilename);
|
||||
Config = Utils.JsonSerializer.Deserialize<Config>(data);
|
||||
Config = JsonConvert.DeserializeObject<Config>(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,6 +135,11 @@ namespace ColorControl
|
||||
Utils.InstallChromeFix(startUpParams.ActivateChromeFontFix);
|
||||
return true;
|
||||
}
|
||||
if (startUpParams.EnableAutoStart || startUpParams.DisableAutoStart)
|
||||
{
|
||||
Utils.RegisterTask(TS_TASKNAME, startUpParams.EnableAutoStart);
|
||||
return true;
|
||||
}
|
||||
|
||||
var useConsole = startUpParams.NoGui || existingProcess != null;
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ColorControl")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Maassoft")]
|
||||
[assembly: AssemblyProduct("ColorControl")]
|
||||
[assembly: AssemblyCopyright("Copyright © Maassoft 2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a6005d08-70f0-44cb-a384-9219eba84f21")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("4.5.0.0")]
|
||||
+21
-4
@@ -19,7 +19,7 @@ namespace ColorControl.Properties {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
@@ -71,7 +71,7 @@ namespace ColorControl.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Power;120;132
|
||||
/// Looks up a localized string similar to Power;120;136
|
||||
///1;106;228
|
||||
///2;196;228
|
||||
///3;286;228
|
||||
@@ -81,15 +81,32 @@ namespace ColorControl.Properties {
|
||||
///7;106;362
|
||||
///8;196;362
|
||||
///9;286;362
|
||||
///List;106;425
|
||||
///0;196;425
|
||||
///SAP;286;425
|
||||
///Vol +;98;513
|
||||
///Mute;198;513
|
||||
///Channel +;298;513
|
||||
///Vol -;98;622
|
||||
///Speech;198;633
|
||||
///Channel -;298;622
|
||||
///Home;78;695
|
||||
///Settings;318;695.
|
||||
///Settings;318;695
|
||||
///Up;200;748
|
||||
///Left;98;852
|
||||
///Enter;200;852
|
||||
///Right;304;852
|
||||
///Down;200;952
|
||||
///Back;80;1000
|
||||
///TV Guide;320;1000
|
||||
///Netflix;92;1076
|
||||
///Inputs;200;1066
|
||||
///Amazon Prime;312;1076
|
||||
///Red;90;1150
|
||||
///Green;164;1150
|
||||
///Yellow;240;1150
|
||||
///Blue;316;1150
|
||||
///Rakuten TV;116;1218
|
||||
///Play;202 [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string RC_coords {
|
||||
get {
|
||||
|
||||
+9
-13
@@ -8,21 +8,17 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ColorControl.Properties
|
||||
{
|
||||
|
||||
|
||||
namespace ColorControl.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace ColorControl
|
||||
{
|
||||
@@ -16,20 +16,17 @@ namespace ColorControl
|
||||
protected string _presetsBaseFilename;
|
||||
protected string _presetsFilename;
|
||||
protected string _presetsBackupFilename;
|
||||
protected JavaScriptSerializer _JsonSerializer;
|
||||
protected JavaScriptSerializer _JsonDeserializer;
|
||||
protected bool _initialized = false;
|
||||
protected List<T> _presets;
|
||||
protected T _lastAppliedPreset;
|
||||
protected string _loadPresetsError;
|
||||
private List<JsonConverter> _jsonConverters;
|
||||
|
||||
public ServiceBase(string dataPath, string presetsBaseFilename)
|
||||
{
|
||||
_dataPath = dataPath;
|
||||
_presetsBaseFilename = presetsBaseFilename;
|
||||
|
||||
_JsonSerializer = new JavaScriptSerializer();
|
||||
_JsonDeserializer = new JavaScriptSerializer();
|
||||
_jsonConverters = new List<JsonConverter>();
|
||||
|
||||
Initialize();
|
||||
}
|
||||
@@ -92,7 +89,7 @@ namespace ColorControl
|
||||
// Hack to convert incorrect triggers
|
||||
json = json.Replace(@"""Triggers"":0", @"""Triggers"":[]");
|
||||
|
||||
_presets = _JsonDeserializer.Deserialize<List<T>>(json);
|
||||
_presets = JsonConvert.DeserializeObject<List<T>>(json, _jsonConverters.ToArray());
|
||||
|
||||
if (_presets != null)
|
||||
{
|
||||
@@ -134,5 +131,10 @@ namespace ColorControl
|
||||
}
|
||||
|
||||
protected abstract List<T> GetDefaultPresets();
|
||||
|
||||
protected void AddJsonConverter(JsonConverter jsonConverter)
|
||||
{
|
||||
_jsonConverters.Add(jsonConverter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace ColorControl
|
||||
public const string ExecuteAmdPresetParam = "--amdpreset";
|
||||
public const string ExecuteLgPresetParam = "--lgpreset";
|
||||
public const string NoGuiParam = "--nogui";
|
||||
public const string EnableAutoStartParam = "--enable-auto-start";
|
||||
public const string DisableAutoStartParam = "--disable-auto-start";
|
||||
|
||||
public bool RunningFromScheduledTask { get; private set; }
|
||||
public bool ActivateChromeFontFix { get; private set; }
|
||||
@@ -24,6 +26,8 @@ namespace ColorControl
|
||||
public bool ExecuteLgPreset { get; private set; }
|
||||
public string LgPresetName { get; private set; }
|
||||
public bool NoGui { get; set; }
|
||||
public bool EnableAutoStart { get; private set; }
|
||||
public bool DisableAutoStart { get; private set; }
|
||||
|
||||
public static StartUpParams Parse(IEnumerable<string> args)
|
||||
{
|
||||
@@ -102,6 +106,16 @@ namespace ColorControl
|
||||
settings.NoGui = true;
|
||||
break;
|
||||
}
|
||||
case EnableAutoStartParam:
|
||||
{
|
||||
settings.EnableAutoStart = true;
|
||||
break;
|
||||
}
|
||||
case DisableAutoStartParam:
|
||||
{
|
||||
settings.DisableAutoStart = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ColorControl
|
||||
@@ -19,7 +14,6 @@ namespace ColorControl
|
||||
|
||||
public static TreeNode CreateTree(object obj, string text)
|
||||
{
|
||||
JavaScriptSerializer jss = new JavaScriptSerializer();
|
||||
var serialized = JsonConvert.SerializeObject(obj, Formatting.None,
|
||||
new JsonSerializerSettings {
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
@@ -30,7 +24,7 @@ namespace ColorControl
|
||||
},
|
||||
Converters = new [] { new Newtonsoft.Json.Converters.StringEnumConverter() }
|
||||
});
|
||||
Dictionary<string, object> dic = jss.Deserialize<Dictionary<string, object>>(serialized);
|
||||
var dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(serialized);
|
||||
var root = new TreeNode();
|
||||
root.Text = text;
|
||||
BuildTree(dic, root);
|
||||
@@ -48,9 +42,9 @@ namespace ColorControl
|
||||
node.Nodes.Add(keyValueNode);
|
||||
BuildTree(kv.Value, keyValueNode);
|
||||
}
|
||||
else if (item is ArrayList)
|
||||
else if (item.GetType() == typeof(JArray))
|
||||
{
|
||||
ArrayList list = (ArrayList)item;
|
||||
var list = (JArray)item;
|
||||
int index = 0;
|
||||
foreach (object value in list)
|
||||
{
|
||||
@@ -70,6 +64,14 @@ namespace ColorControl
|
||||
BuildTree(d, node);
|
||||
}
|
||||
}
|
||||
else if (item.GetType() == typeof(JObject))
|
||||
{
|
||||
var jobject = item as JObject;
|
||||
foreach (var property in jobject.Properties())
|
||||
{
|
||||
BuildTree(new KeyValuePair<string, object>(property.Name, property.Value), node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetValueAsString(object value)
|
||||
@@ -82,13 +84,13 @@ namespace ColorControl
|
||||
return "[]";
|
||||
}
|
||||
|
||||
if (value is ArrayList)
|
||||
if (value.GetType() == typeof(JArray))
|
||||
{
|
||||
var arr = value as ArrayList;
|
||||
var arr = value as JArray;
|
||||
return $"[{arr.Count}]";
|
||||
}
|
||||
|
||||
if (type.IsGenericType)
|
||||
if (type.IsGenericType || value.GetType() == typeof(JObject))
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
+46
-25
@@ -7,7 +7,6 @@ using NWin32.NativeTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Deployment.Application;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
@@ -19,7 +18,6 @@ using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using Windows.Devices.Enumeration;
|
||||
using Windows.Devices.Enumeration.Pnp;
|
||||
@@ -64,8 +62,6 @@ namespace ColorControl
|
||||
|
||||
public delegate void PCREATE_PROCESS_NOTIFY_ROUTINE(IntPtr ParentId, IntPtr ProcessId, bool Create);
|
||||
|
||||
public static JavaScriptSerializer JsonSerializer = new JavaScriptSerializer();
|
||||
|
||||
public static bool ConsoleOpened { get; private set; }
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
@@ -205,9 +201,10 @@ namespace ColorControl
|
||||
|
||||
internal static bool ExecuteElevated(string args)
|
||||
{
|
||||
var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location, args)
|
||||
var info = new ProcessStartInfo(Process.GetCurrentProcess().MainModule.FileName, args)
|
||||
{
|
||||
Verb = "runas", // indicates to elevate privileges
|
||||
UseShellExecute = true,
|
||||
};
|
||||
|
||||
var process = new Process
|
||||
@@ -470,7 +467,7 @@ namespace ColorControl
|
||||
|
||||
public static void RegisterTask(string taskName, bool enabled)
|
||||
{
|
||||
var file = Assembly.GetExecutingAssembly().Location;
|
||||
var file = Process.GetCurrentProcess().MainModule.FileName;
|
||||
var directory = Path.GetDirectoryName(file);
|
||||
|
||||
try
|
||||
@@ -509,19 +506,16 @@ namespace ColorControl
|
||||
|
||||
if (task != null)
|
||||
{
|
||||
if (update && ApplicationDeployment.IsNetworkDeployed)
|
||||
{
|
||||
var action = task.Definition.Actions.FirstOrDefault(x => x.ActionType == TaskActionType.Execute);
|
||||
if (action != null)
|
||||
{
|
||||
var execAction = action as ExecAction;
|
||||
if (!execAction.Path.Equals(file))
|
||||
{
|
||||
RegisterTask(taskName, false);
|
||||
RegisterTask(taskName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//var action = task.Definition.Actions.FirstOrDefault(x => x.ActionType == TaskActionType.Execute);
|
||||
//if (action != null)
|
||||
//{
|
||||
// var execAction = action as ExecAction;
|
||||
// if (!execAction.Path.Equals(file))
|
||||
// {
|
||||
// RegisterTask(taskName, false);
|
||||
// RegisterTask(taskName, true);
|
||||
// }
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -551,16 +545,22 @@ namespace ColorControl
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void BuildDropDownMenuEx(ContextMenuStrip mnuParent, string name, Type enumType, EventHandler clickEvent, object tag = null)
|
||||
public static ToolStripMenuItem BuildDropDownMenuEx(ContextMenuStrip mnuParent, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0)
|
||||
{
|
||||
var subMenuName = $"{mnuParent.Name}_{name}";
|
||||
var subMenuItems = mnuParent.Items.Find(subMenuName, false);
|
||||
ToolStripMenuItem subMenuItem;
|
||||
if (subMenuItems.Length == 0)
|
||||
{
|
||||
subMenuItem = (ToolStripMenuItem)mnuParent.Items.Add(name);
|
||||
subMenuItem.Name = subMenuName;
|
||||
|
||||
if (subMenuItems.Length > 0)
|
||||
{
|
||||
return subMenuItems[0] as ToolStripMenuItem;
|
||||
}
|
||||
|
||||
ToolStripMenuItem subMenuItem;
|
||||
subMenuItem = (ToolStripMenuItem)mnuParent.Items.Add(name);
|
||||
subMenuItem.Name = subMenuName;
|
||||
|
||||
if (enumType != null)
|
||||
{
|
||||
foreach (var enumValue in Enum.GetValues(enumType))
|
||||
{
|
||||
var item = subMenuItem.DropDownItems.Add(enumValue.ToString());
|
||||
@@ -568,6 +568,27 @@ namespace ColorControl
|
||||
item.Click += clickEvent;
|
||||
}
|
||||
}
|
||||
else if (min >= 0 && max > min)
|
||||
{
|
||||
for (var i = 0; i <= 10; i++)
|
||||
{
|
||||
var value = i * (max / 10);
|
||||
|
||||
var subSubItemName = $"{subMenuName}_{value}";
|
||||
|
||||
var item = subMenuItem.DropDownItems.Add(value.ToString());
|
||||
item.Name = subSubItemName;
|
||||
item.Tag = tag;
|
||||
item.Click += clickEvent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
subMenuItem.Tag = tag;
|
||||
subMenuItem.Click += clickEvent;
|
||||
}
|
||||
|
||||
return subMenuItem;
|
||||
}
|
||||
|
||||
public static void BuildDropDownMenu(ToolStripDropDownItem mnuParent, string name, Type enumType, object colorData, string propertyName, EventHandler clickEvent)
|
||||
|
||||
+2
-75
@@ -1,9 +1,6 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using PacketDotNet;
|
||||
using System.Net.NetworkInformation;
|
||||
using SharpPcap;
|
||||
using SharpPcap.Npcap;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
@@ -17,13 +14,8 @@ namespace ColorControl
|
||||
private const string ArgumentExceptionInvalidPasswordLength = "Invalid password length.";
|
||||
private const int DefaultWolPort = 9;
|
||||
|
||||
public static bool WakeFunction(string macAddress, bool usePcap = false)
|
||||
public static bool WakeFunction(string macAddress)
|
||||
{
|
||||
if (usePcap)
|
||||
{
|
||||
return WakeFunctionPcap(macAddress);
|
||||
}
|
||||
|
||||
return WakeFunctionToAllNics(macAddress);
|
||||
}
|
||||
|
||||
@@ -117,70 +109,5 @@ namespace ColorControl
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
||||
//You need SharpPcap for this to work
|
||||
private static bool WakeFunctionPcap(string macAddress)
|
||||
{
|
||||
/* Retrieve the device list */
|
||||
var devices = CaptureDeviceList.Instance;
|
||||
|
||||
Logger.Debug("Waking device with MAC-address " + macAddress);
|
||||
|
||||
/*If no device exists, print error */
|
||||
if (devices.Count < 1)
|
||||
{
|
||||
Logger.Debug("No network device found on this machine");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var device in devices)
|
||||
{
|
||||
//if (device is NpcapDevice npcapDevice)
|
||||
//{
|
||||
// if (!npcapDevice.Interface.GatewayAddresses.Any())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (device is NpcapDevice npcapDevice)
|
||||
{
|
||||
Logger.Debug($"Opening network device (NpcapDevice): FriendlyName: {npcapDevice.Interface.FriendlyName}, Description: {npcapDevice.Interface.Description}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Debug($"Opening network device (NOT A NpcapDevice!): {device.Name}, Description: {device.Description}");
|
||||
}
|
||||
|
||||
//Open the device
|
||||
device.Open();
|
||||
|
||||
//A magic packet is a broadcast frame containing anywhere within its payload: 6 bytes of ones
|
||||
//(resulting in hexadecimal FF FF FF FF FF FF), followed by sixteen repetitions
|
||||
|
||||
string response = macAddress.Replace(":", "-");
|
||||
|
||||
var address = PhysicalAddress.Parse("FFFFFFFFFFFF");
|
||||
EthernetPacket ethernet = new EthernetPacket(address, address, EthernetType.WakeOnLan);
|
||||
ethernet.PayloadPacket = new WakeOnLanPacket(PhysicalAddress.Parse(response));
|
||||
|
||||
byte[] bytes = ethernet.Bytes;
|
||||
|
||||
try
|
||||
{
|
||||
//Send the packet out the network device
|
||||
device.SendPacket(bytes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Debug(e.Message);
|
||||
}
|
||||
|
||||
device.Close();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,11 @@ namespace LgTv
|
||||
|
||||
public enum PictureMode
|
||||
{
|
||||
cinema, eco, expert1, expert2, game,
|
||||
normal, photo, sports, technicolor, vivid, hdrEffect, hdrCinema,
|
||||
hdrCinemaBright, hdrExternal, hdrGame, hdrStandard, hdrTechnicolor,
|
||||
hdrVivid, dolbyHdrCinema, dolbyHdrCinemaBright, dolbyHdrDarkAmazon,
|
||||
dolbyHdrGame, dolbyHdrStandard, dolbyHdrVivid, dolbyStandard
|
||||
cinema, eco, expert1, expert2, game, normal, photo, sports, technicolor, vivid, hdrEffect, filmMaker,
|
||||
|
||||
hdrCinema, hdrCinemaBright, hdrExternal, hdrGame, hdrStandard, hdrTechnicolor, hdrVivid, hdrFilmMaker,
|
||||
|
||||
dolbyHdrCinema, dolbyHdrCinemaBright, dolbyHdrDarkAmazon, dolbyHdrGame, dolbyHdrStandard, dolbyHdrVivid, dolbyStandard
|
||||
}
|
||||
|
||||
public enum OffToHigh
|
||||
@@ -102,6 +102,14 @@ namespace LgTv
|
||||
true_
|
||||
}
|
||||
|
||||
public enum GammaExp
|
||||
{
|
||||
low,
|
||||
medium,
|
||||
high1,
|
||||
high2
|
||||
}
|
||||
|
||||
public class LgTvApi:IDisposable
|
||||
{
|
||||
public bool ConnectionClosed { get => _connection?.ConnectionClosed ?? true; }
|
||||
@@ -383,7 +391,7 @@ namespace LgTv
|
||||
{
|
||||
if (payload == null)
|
||||
{
|
||||
var keys = @"[ ""contrast"", ""backlight"" ]";
|
||||
var keys = @"[ ""contrast"", ""backlight"", ""brightness"", ""color"" ]";
|
||||
|
||||
var json = @"{ ""category"": ""picture"", ""keys"": " + keys + @", ""subscribe"": true }";
|
||||
|
||||
|
||||
@@ -41,7 +41,20 @@ namespace LgTv
|
||||
SAP,
|
||||
PROGRAM,
|
||||
PLAY,
|
||||
PAUSE
|
||||
PAUSE,
|
||||
STOP,
|
||||
REWIND,
|
||||
FASTFORWARD,
|
||||
GUIDE,
|
||||
AMAZON,
|
||||
NETFLIX,
|
||||
MAGNIFIER_ZOOM,
|
||||
LIVE_ZOOM,
|
||||
_3D_MODE,
|
||||
ASPECT_RATIO,
|
||||
RECENT,
|
||||
RECORD,
|
||||
SCREEN_REMOTE
|
||||
}
|
||||
|
||||
public class LgWebOsMouseService : IDisposable
|
||||
@@ -59,7 +72,7 @@ namespace LgTv
|
||||
}
|
||||
public void SendButton(int number)
|
||||
{
|
||||
_connection.SendMessageAsync($"type:button\nname:{number}\n\n");
|
||||
_connection.SendMessageAsync($"type:button\nname:{number}\n\n").ConfigureAwait(false);
|
||||
}
|
||||
public void SendButton(ButtonType bt)
|
||||
{
|
||||
@@ -68,23 +81,23 @@ namespace LgTv
|
||||
{
|
||||
text = text.Substring(1);
|
||||
}
|
||||
_connection.SendMessageAsync($"type:button\nname:{text}\n\n");
|
||||
_connection.SendMessageAsync($"type:button\nname:{text}\n\n").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
public void Move(double dx, double dy, bool drag = false)
|
||||
{
|
||||
_connection.SendMessageAsync($"type:move\ndx:{dx}\ndy:{dy}\ndown:{(drag ? 1 : 0)}\n\n");
|
||||
_connection.SendMessageAsync($"type:move\ndx:{dx}\ndy:{dy}\ndown:{(drag ? 1 : 0)}\n\n").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void Scroll(double dx, double dy)
|
||||
{
|
||||
_connection.SendMessageAsync($"type:scroll\ndx:{dx}\ndy:{dy}\n\n");
|
||||
_connection.SendMessageAsync($"type:scroll\ndx:{dx}\ndy:{dy}\n\n").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void Click()
|
||||
{
|
||||
_connection.SendMessageAsync("type:click\n\n");
|
||||
_connection.SendMessageAsync("type:click\n\n").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net472" />
|
||||
<package id="Native" version="0.1.1" targetFramework="net472" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
|
||||
<package id="NLog" version="4.7.10" targetFramework="net472" />
|
||||
<package id="NStandard" version="0.8.9" targetFramework="net472" />
|
||||
<package id="NvAPIWrapper.Net" version="0.8.1.101" targetFramework="net472" />
|
||||
<package id="NWin32" version="1.2.0" targetFramework="net472" />
|
||||
<package id="PacketDotNet" version="1.2.0" targetFramework="net472" />
|
||||
<package id="SharpPcap" version="5.4.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
||||
<package id="TaskScheduler" version="2.9.1" targetFramework="net472" />
|
||||
</packages>
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Stellt Methoden für das Senden von Anfragen über das ARP-Protokoll bereit.</summary>
|
||||
public static class ArpRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben.
|
||||
/// </summary>
|
||||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <returns>Eine <see cref="T:System.Net.ArpRequestResult">ArpRequestResult</see>-Instanz, welche die Ergebnisse der Anfrage enthält.</returns>
|
||||
public static ArpRequestResult Send(IPAddress destination)
|
||||
{
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException(nameof(destination));
|
||||
|
||||
int destIp = BitConverter.ToInt32(destination.GetAddressBytes(), 0);
|
||||
|
||||
var addr = new byte[6];
|
||||
var len = addr.Length;
|
||||
|
||||
var res = NativeMethods.SendARP(destIp, 0, addr, ref len);
|
||||
|
||||
if (res == 0)
|
||||
return new ArpRequestResult(new PhysicalAddress(addr));
|
||||
return new ArpRequestResult(new Win32Exception(res));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben.
|
||||
/// </summary>
|
||||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <returns>Ein asynchroner Task, welcher einen ARP-Request sendet.</returns>
|
||||
public static Task<ArpRequestResult> SendAsync(IPAddress destination) => Task.Run(() => Send(destination));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
// TODO: rethink the whole exception thing
|
||||
|
||||
/// <summary>
|
||||
/// Enthält die Rückgabewerte der ArpRequest.Send-Funktion.
|
||||
/// </summary>
|
||||
public class ArpRequestResult
|
||||
{
|
||||
/// <summary>Falls Fehler bei der Protokollanfrage auftreten, werden diese in dieser Eigenschaft abgelegt. Andernfalls null.</summary>
|
||||
public Exception Exception { get; }
|
||||
|
||||
/// <summary>Die aufgelöste physikalische Adresse.</summary>
|
||||
public PhysicalAddress Address { get; }
|
||||
|
||||
/// <summary>Erstellt eine neue ArpRequestResult-Instanz</summary>
|
||||
/// <param name="address">Die physikalische Adresse</param>
|
||||
public ArpRequestResult(PhysicalAddress address)
|
||||
{
|
||||
this.Exception = null;
|
||||
Address = address;
|
||||
}
|
||||
|
||||
/// <summary>Erstellt eine neue ArpRequestResult-Instanz</summary>
|
||||
/// <param name="exception">Der aufgetretene Fehler</param>
|
||||
public ArpRequestResult(Exception exception)
|
||||
{
|
||||
this.Exception = exception;
|
||||
Address = null;
|
||||
}
|
||||
|
||||
/// <summary>Konvertiert ARP-Rückgabewerte in eine Zeichenfolge.</summary>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (Address == null)
|
||||
sb.Append("no address");
|
||||
else
|
||||
{
|
||||
sb.Append("address: ");
|
||||
sb.Append(Address);
|
||||
}
|
||||
sb.Append(", ");
|
||||
if (Exception == null)
|
||||
sb.Append("no exception");
|
||||
else
|
||||
{
|
||||
sb.Append("exception: ");
|
||||
sb.Append(Exception.Message);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// 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.
|
||||
//
|
||||
// To add a suppression to this file, right-click the message in the
|
||||
// Code Analysis results, point to "Suppress Message", and click
|
||||
// "In Suppression File".
|
||||
// You do not need to add suppressions to this file manually.
|
||||
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Int32)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte[],System.Int32)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte[],System.Int32,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte[])")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Byte[],System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWol(System.Net.IPAddress,System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Int32)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte[],System.Int32)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte[],System.Int32,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte[])")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Byte[],System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPAddressExtensions.#SendWolAsync(System.Net.IPAddress,System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWol(System.Net.IPEndPoint,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWol(System.Net.IPEndPoint,System.Byte[])")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWol(System.Net.IPEndPoint,System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWol(System.Net.IPEndPoint,System.Byte[],System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWol(System.Net.IPEndPoint,System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWolAsync(System.Net.IPEndPoint,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte,System.Byte)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWolAsync(System.Net.IPEndPoint,System.Byte[])")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWolAsync(System.Net.IPEndPoint,System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWolAsync(System.Net.IPEndPoint,System.Byte[],System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.IPEndPointExtensions.#SendWolAsync(System.Net.IPEndPoint,System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Lan")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Scope = "member", Target = "System.Net.Topology.INetMask.#GetMaskBytes()")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#op_Equality(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#op_Inequality(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#op_BitwiseAnd(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Scope = "type", Target = "System.Net.Topology.SiblingOptions")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "type", Target = "System.Net.SendWol")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPEndPoint)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPEndPoint,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPEndPoint)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWol(System.Net.NetworkInformation.PhysicalAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#op_BitwiseOr(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#BitwiseOr(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPAddress)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPAddress,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wol", Scope = "member", Target = "System.Net.PhysicalAddressExtensions.#SendWolAsync(System.Net.NetworkInformation.PhysicalAddress,System.Net.IPEndPoint,System.Net.SecureOnPassword)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cidr", Scope = "member", Target = "System.Net.Topology.INetMask.#Cidr")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "m", Scope = "member", Target = "System.Net.Topology.NetMask.#.ctor(System.Byte,System.Byte,System.Byte,System.Byte)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "n", Scope = "member", Target = "System.Net.Topology.NetMask.#BitwiseAnd(System.Net.Topology.NetMask,System.Net.Topology.NetMask)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cidr", Scope = "member", Target = "System.Net.Topology.NetMask.#.ctor(System.Int32)")]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cidr", Scope = "member", Target = "System.Net.Topology.NetMask.#.ctor(System.Byte)")]
|
||||
@@ -1,166 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Provides extension methods for sending Wake On LAN signals (magic packets) to a specific <see cref="IPAddress"/>.</summary>
|
||||
public static class IPAddressExtensions
|
||||
{
|
||||
private const int DefaultWolPort = 7;
|
||||
#region Wol
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="port">The port to send the packet to.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, byte[] macAddress, int port) => target.SendWol(macAddress, port, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="port">The port to send the packet to.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, byte[] macAddress, int port, SecureOnPassword password)
|
||||
{
|
||||
Net.MagicPacket.Send(new IPEndPoint(target, port), macAddress, password);
|
||||
}
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, byte[] macAddress) => target.SendWol(macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
Net.MagicPacket.Send(new IPEndPoint(target, DefaultWolPort), macAddress, password);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="PhysicalAddress" /> <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, PhysicalAddress macAddress) => target.SendWol(macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="PhysicalAddress" /> <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void SendWol(this IPAddress target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
Net.MagicPacket.Send(new IPEndPoint(target, DefaultWolPort), macAddress, password);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region ARP
|
||||
|
||||
/// <summary>
|
||||
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben.
|
||||
/// </summary>
|
||||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <returns>Eine <see cref="T:System.Net.ArpRequestResult">ArpRequestResult</see>-Instanz, welche die Ergebnisse der Anfrage enthält.</returns>
|
||||
public static ArpRequestResult SendArpRequest(this IPAddress destination) => ArpRequest.Send(destination);
|
||||
|
||||
#endregion
|
||||
#region TAP
|
||||
|
||||
#region Wol
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="port">The port to send the packet to.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, int port) => target.SendWolAsync(macAddress, port, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="port">The port to send the packet to.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, int port, SecureOnPassword password)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(new IPEndPoint(target, port), macAddress, password);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, byte[] macAddress) => target.SendWolAsync(macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(new IPEndPoint(target, DefaultWolPort), macAddress, password);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="PhysicalAddress" /> <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, PhysicalAddress macAddress) => target.SendWolAsync(macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="PhysicalAddress" /> <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPAddress target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(new IPEndPoint(target, DefaultWolPort), macAddress, password);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ARP
|
||||
|
||||
/// <summary>Sends a request via ARP to resolve an IP address to aphysical address. If the physical address is already cached, it's cached value is returned.</summary>
|
||||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends an ARP request.</returns>
|
||||
public static Task<ArpRequestResult> SendArpRequestAsync(this IPAddress destination) => ArpRequest.SendAsync(destination);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Provides extension methods for sending Wake On LAN signals (magic packets) to a specific <see cref="IPEndPoint"/>.</summary>
|
||||
public static class IPEndPointExtensions
|
||||
{
|
||||
#region Wol
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array macAddress is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
public static void SendWol(this IPEndPoint target, byte[] macAddress)
|
||||
{
|
||||
Net.MagicPacket.Send(target, macAddress);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
public static void SendWol(this IPEndPoint target, PhysicalAddress macAddress)
|
||||
{
|
||||
Net.MagicPacket.Send(target, macAddress);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array macAddress is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
public static void SendWol(this IPEndPoint target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
Net.MagicPacket.Send(target, macAddress, password);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendet ein Wake-On-LAN-Signal an einen Client.
|
||||
/// </summary>
|
||||
/// <param name="target">Der Ziel-IPEndPoint.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
public static void SendWol(this IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
Net.MagicPacket.Send(target, macAddress, password);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region TAP
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array macAddress is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPEndPoint target, byte[] macAddress)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(target, macAddress);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPEndPoint target, PhysicalAddress macAddress)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(target, macAddress);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array macAddress is not 6.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPEndPoint target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(target, macAddress, password);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
return Net.MagicPacket.SendAsync(target, macAddress, password);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#define GERMAN
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
internal static class Localization
|
||||
{
|
||||
public const string ArgumentExceptionInvalidMacAddressLength = "Invalid MAC address length.";
|
||||
public const string ArgumentExceptionInvalidPasswordLength = "Invalid password length.";
|
||||
|
||||
public const string ArgumentExceptionIsNotAValidMadAddress = " is not a valid MAC address.";
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Provides methods for sending Wake On LAN signals (magic packets).</summary>
|
||||
public static class MagicPacket
|
||||
{
|
||||
#region Wol
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <exception cref="ArgumentNullException">target is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array macAddress is not 6.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void Send(IPEndPoint target, byte[] macAddress) => Send(target, macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void Send(IPEndPoint target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
if (macAddress == null)
|
||||
throw new ArgumentNullException(nameof(macAddress));
|
||||
|
||||
byte[] passwordBuffer = password?.GetPasswordBytes();
|
||||
byte[] packet = GetWolPacket(macAddress, passwordBuffer);
|
||||
SendPacket(target, packet);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void Send(IPEndPoint target, PhysicalAddress macAddress) => Send(target, macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
|
||||
public static void Send(IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
if (macAddress == null)
|
||||
throw new ArgumentNullException(nameof(macAddress));
|
||||
|
||||
byte[] passwordBuffer = password?.GetPasswordBytes();
|
||||
byte[] packet = GetWolPacket(macAddress.GetAddressBytes(), passwordBuffer);
|
||||
SendPacket(target, packet);
|
||||
}
|
||||
|
||||
private static void SendPacket(IPEndPoint target, byte[] packet)
|
||||
{
|
||||
using (var cl = new UdpClient())
|
||||
cl.Send(packet, packet.Length, target);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region TAP
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendAsync(IPEndPoint target, byte[] macAddress) => SendAsync(target, macAddress);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendAsync(IPEndPoint target, byte[] macAddress, SecureOnPassword password)
|
||||
{
|
||||
if (target == null)
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
if (macAddress == null)
|
||||
throw new ArgumentNullException(nameof(macAddress));
|
||||
|
||||
var passwordBuffer = password?.GetPasswordBytes();
|
||||
var packet = GetWolPacket(macAddress, passwordBuffer);
|
||||
return SendPacketAsync(target, packet);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendAsync(IPEndPoint target, PhysicalAddress macAddress) => SendAsync(target, macAddress, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="macAddress">The MAC address of the designated client.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendAsync(IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
|
||||
{
|
||||
if (target == null)
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
if (macAddress == null)
|
||||
throw new ArgumentNullException(nameof(macAddress));
|
||||
|
||||
var passwordBuffer = password?.GetPasswordBytes();
|
||||
var p = GetWolPacket(macAddress.GetAddressBytes(), passwordBuffer);
|
||||
return SendPacketAsync(target, p);
|
||||
}
|
||||
|
||||
private static Task SendPacketAsync(IPEndPoint target, byte[] packet)
|
||||
{
|
||||
var cl = new UdpClient();
|
||||
return cl.SendAsync(packet, packet.Length, target).ContinueWith((Task t) => cl.Close());
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region internal
|
||||
|
||||
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="macAddress"/> is not 6.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array <paramref name="password"/> is not 0 or 6.</exception>
|
||||
private static byte[] GetWolPacket(byte[] macAddress, byte[] password)
|
||||
{
|
||||
if (macAddress == null)
|
||||
throw new ArgumentNullException(nameof(macAddress));
|
||||
if (macAddress.Length != 6)
|
||||
throw new ArgumentException(Localization.ArgumentExceptionInvalidMacAddressLength);
|
||||
|
||||
password = password ?? new byte[0];
|
||||
if (password.Length != 0 && password.Length != 6)
|
||||
throw new ArgumentException(Localization.ArgumentExceptionInvalidPasswordLength);
|
||||
|
||||
var packet = new byte[17 * 6 + password.Length];
|
||||
|
||||
int offset, i;
|
||||
for (offset = 0; offset < 6; ++offset)
|
||||
packet[offset] = 0xFF;
|
||||
|
||||
for (offset = 6; offset < 17 * 6; offset += 6)
|
||||
for (i = 0; i < 6; ++i)
|
||||
packet[i + offset] = macAddress[i];
|
||||
|
||||
if (password.Length > 0)
|
||||
{
|
||||
for (offset = 16 * 6 + 6; offset < (17 * 6 + password.Length); offset += 6)
|
||||
for (i = 0; i < 6; ++i)
|
||||
packet[i + offset] = password[i];
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
private const string IphlpApi = "iphlpapi.dll";
|
||||
|
||||
[DllImport(IphlpApi, ExactSpelling = true)]
|
||||
[SecurityCritical]
|
||||
internal static extern int SendARP(int destinationIp, int sourceIp, byte[] macAddress, ref int physicalAddrLength);
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Provides extension methods for sending Wake On LAN signals (magic packets) using a specific <see cref="PhysicalAddress"/>.</summary>
|
||||
public static class PhysicalAddressExtensions
|
||||
{
|
||||
#region Wol
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to the broadcast IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static void SendWol(this PhysicalAddress address) => address.SendWol(IPAddress.Broadcast, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static void SendWol(this PhysicalAddress address, IPAddress target) => address.SendWol(target, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static void SendWol(this PhysicalAddress address, IPAddress target, SecureOnPassword password)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
target.SendWol(address.GetAddressBytes(), password);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP end point with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static void SendWol(this PhysicalAddress address, IPEndPoint target) => address.SendWol(target, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP end point with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static void SendWol(this PhysicalAddress address, IPEndPoint target, SecureOnPassword password)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
target.SendWol(address.GetAddressBytes(), password);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region TAP
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to the broadcast IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
public static Task SendWolAsync(this PhysicalAddress address)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
return IPAddress.Broadcast.SendWolAsync(address.GetAddressBytes());
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this PhysicalAddress address, IPAddress target) => address.SendWolAsync(target, null);
|
||||
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP address with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPAddress"/>.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this PhysicalAddress address, IPAddress target, SecureOnPassword password)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
return target.SendWolAsync(address.GetAddressBytes(), password);
|
||||
}
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP end point with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this PhysicalAddress address, IPEndPoint target) => address.SendWolAsync(target, null);
|
||||
|
||||
/// <summary>Sends a Wake On LAN signal (magic packet) to a specific IP end point with the physical address.</summary>
|
||||
/// <param name="address">The instance of the physical address that should be used in the magic packet.</param>
|
||||
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
|
||||
/// <param name="password">The SecureOn password of the client.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>An asynchronous <see cref="Task"/> which sends a Wake On LAN signal (magic packet) to a client.</returns>
|
||||
public static Task SendWolAsync(this PhysicalAddress address, IPEndPoint target, SecureOnPassword password)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
return target.SendWolAsync(address.GetAddressBytes(), password);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region common
|
||||
|
||||
/// <summary>Gets the type (<see cref="PhysicalAddressAdministrator"/>) of the <see cref="PhysicalAddress" />.</summary>
|
||||
/// <param name="address">The address.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>The <see cref="PhysicalAddressType" /> of the physical addess (MAC address).</returns>
|
||||
public static PhysicalAddressType GetAddressType(this PhysicalAddress address)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
var bytes = address.GetAddressBytes();
|
||||
if (bytes == null || bytes.Length < 1)
|
||||
throw new ArgumentException($"Invalid {nameof(address)}.");
|
||||
return (bytes[0] & 0x1) == 0 ? PhysicalAddressType.Unicast : PhysicalAddressType.Multicast;
|
||||
}
|
||||
|
||||
/// <summary>Gets the administrator (<see cref="PhysicalAddressAdministrator"/>) of the <see cref="PhysicalAddress" />.</summary>
|
||||
/// <param name="address">The address.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="address"/> is null.</exception>
|
||||
/// <returns>The <see cref="PhysicalAddressAdministrator" /> of the physical addess (MAC address).</returns>
|
||||
public static PhysicalAddressAdministrator GetAddressAdministrator(this PhysicalAddress address)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
|
||||
var bytes = address.GetAddressBytes();
|
||||
if (bytes == null || bytes.Length < 1)
|
||||
throw new ArgumentException($"Invalid {nameof(address)}.");
|
||||
return (bytes[0] & 0x2) == 0 ? PhysicalAddressAdministrator.Global : PhysicalAddressAdministrator.Local;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Der Administrator der physikalischen Adresse gibt an, ob die Adresse globally unique oder local administrated ist.
|
||||
/// </summary>
|
||||
public enum PhysicalAddressAdministrator
|
||||
{
|
||||
/// <summary>
|
||||
/// Die Adresse ist global einzigartig (nach der OUI).
|
||||
/// </summary>
|
||||
Global,
|
||||
|
||||
/// <summary>
|
||||
/// Die Adresse ist lokal administriert.
|
||||
/// </summary>
|
||||
Local
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Der Typ der physikalischen Adresse gibt an, ob es um eine UNicast oder Multicast-Adresse handelt.
|
||||
/// </summary>
|
||||
public enum PhysicalAddressType
|
||||
{
|
||||
/// <summary>
|
||||
/// Bezeichnet eine Unicast-Adresse.
|
||||
/// </summary>
|
||||
Unicast,
|
||||
|
||||
/// <summary>
|
||||
/// Bezeichnet eine Multicast-Adresse
|
||||
/// </summary>
|
||||
Multicast
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
|
||||
[assembly: InternalsVisibleTo("WakeOnLan.Tests")]
|
||||
@@ -1,95 +0,0 @@
|
||||
namespace System.Net
|
||||
{
|
||||
/// <summary>Provides a SecureOn password.</summary>
|
||||
[Serializable]
|
||||
public sealed class SecureOnPassword
|
||||
{
|
||||
private readonly byte[] _password;
|
||||
|
||||
/// <summary>Initializes a new instance of <see cref="SecureOnPassword"/> with the given password.</summary>
|
||||
/// <param name="password">The password as <see cref="Byte"/> array.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The length of the <see cref="T:System.Byte" /> array password is not 6.</exception>
|
||||
public SecureOnPassword(byte[] password)
|
||||
{
|
||||
if (password == null)
|
||||
throw new ArgumentNullException(nameof(password));
|
||||
if (password.Length != 6)
|
||||
throw new ArgumentException(Localization.ArgumentExceptionInvalidPasswordLength);
|
||||
_password = password;
|
||||
}
|
||||
|
||||
/// <summary>Gets the buffer of the password.</summary>
|
||||
public byte[] GetPasswordBytes()
|
||||
{
|
||||
if (_password == null)
|
||||
return null;
|
||||
var buffer = new byte[_password.Length];
|
||||
Array.Copy(_password, buffer, 0);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>Initializes a new instance of <see cref="SecureOnPassword"/> with the given password.</summary>
|
||||
/// <param name="password">The password as <see cref="String"/>.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <remarks>Uses <see cref="Text.Encoding.Default" /> as encoding.</remarks>
|
||||
public SecureOnPassword(string password)
|
||||
: this(password, Text.Encoding.Default)
|
||||
{ }
|
||||
|
||||
|
||||
/// <summary>Initializes a new instance of <see cref="SecureOnPassword"/> with the given password.</summary>
|
||||
/// <param name="password">The password as <see cref="String"/>.</param>
|
||||
/// <param name="encoding">The <see cref="Text.Encoding"/> instance to use for the password.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="password"/> is null.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="encoding"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">The <see cref="Byte"/> array wich is created using the password has more elements than 6.</exception>
|
||||
public SecureOnPassword(string password, Text.Encoding encoding)
|
||||
{
|
||||
if (password == null)
|
||||
throw new ArgumentNullException(nameof(password));
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException(nameof(encoding));
|
||||
|
||||
if (string.IsNullOrEmpty(password))
|
||||
_password = new byte[6];
|
||||
|
||||
var bytes = encoding.GetBytes(password);
|
||||
if (bytes.Length > 6)
|
||||
throw new ArgumentException(Localization.ArgumentExceptionInvalidPasswordLength);
|
||||
|
||||
_password = new byte[6];
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
_password[i] = bytes[i];
|
||||
if (bytes.Length < 6)
|
||||
{
|
||||
for (int i = bytes.Length - 1; i < 6; i++)
|
||||
_password[i] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Converts the <see cref="SecureOnPassword"/> to dash notation.</summary>
|
||||
/// <returns>A <see cref="String"/> representing the <see cref="SecureOnPassword"/> as dash notation.</returns>
|
||||
public override string ToString() => ToString("X2");
|
||||
|
||||
/// <summary>Converts the <see cref="SecureOnPassword"/> to dash notation.</summary>
|
||||
/// <returns>A <see cref="String"/> representing the <see cref="SecureOnPassword"/> as dash notation.</returns>
|
||||
private string ToString(string format)
|
||||
{
|
||||
var f = new string[6];
|
||||
for (int i = 0; i < f.Length; i++)
|
||||
f[i] = _password[i].ToString(format);
|
||||
return string.Join("-", f);
|
||||
}
|
||||
|
||||
/// <summary>Converts the <see cref="SecureOnPassword"/> to dash notation.</summary>
|
||||
/// <returns>A <see cref="String"/> representing the <see cref="SecureOnPassword"/> as dash notation.</returns>
|
||||
public string ToString(IFormatProvider format)
|
||||
{
|
||||
var f = new string[6];
|
||||
for (int i = 0; i < f.Length; i++)
|
||||
f[i] = _password[i].ToString(format);
|
||||
return string.Join("-", f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
internal static class ByteArrayExtensions
|
||||
{
|
||||
internal static IEnumerable<bool> ToBitStream(this byte[] bytes, bool fromLeft)
|
||||
{
|
||||
if (bytes == null)
|
||||
throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
if (fromLeft)
|
||||
{
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
byte tmp = bytes[i].ReverseBits();
|
||||
for (int j = 0; j < 8; ++j)
|
||||
{
|
||||
yield return (tmp & 1) == 1;
|
||||
tmp >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = bytes.Length - 1; i >= 0; --i)
|
||||
{
|
||||
byte tmp = bytes[i];
|
||||
for (int j = 0; j < 8; ++j)
|
||||
{
|
||||
yield return (tmp & 1) == 1;
|
||||
tmp >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int CountFromSide(byte[] bits, bool value, bool fromleft)
|
||||
{
|
||||
int counter = 0;
|
||||
var str = bits.ToBitStream(fromleft);
|
||||
foreach (var bit in str)
|
||||
{
|
||||
if (bit == value)
|
||||
++counter;
|
||||
else return counter;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
internal static int CountFromLeft(this byte[] bits, bool value)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
return CountFromSide(bits, value, true);
|
||||
}
|
||||
|
||||
internal static int CountFromRight(this byte[] bits, bool value)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
return CountFromSide(bits, value, false);
|
||||
}
|
||||
|
||||
internal static string ToBinaryString(this byte[] bits, char separator)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
|
||||
const int radix = 2;
|
||||
const int padding = 8;
|
||||
const char paddingChar = '0';
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(Convert.ToString(bits[0], radix).PadLeft(padding, paddingChar)).Append(separator);
|
||||
sb.Append(Convert.ToString(bits[1], radix).PadLeft(padding, paddingChar)).Append(separator);
|
||||
sb.Append(Convert.ToString(bits[2], radix).PadLeft(padding, paddingChar)).Append(separator);
|
||||
sb.Append(Convert.ToString(bits[3], radix).PadLeft(padding, paddingChar));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal static string ToBinaryString(this byte[] bits)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
|
||||
const int radix = 2;
|
||||
const int padding = 8;
|
||||
const char paddingChar = '0';
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(Convert.ToString(bits[0], radix).PadLeft(padding, paddingChar));
|
||||
sb.Append(Convert.ToString(bits[1], radix).PadLeft(padding, paddingChar));
|
||||
sb.Append(Convert.ToString(bits[2], radix).PadLeft(padding, paddingChar));
|
||||
sb.Append(Convert.ToString(bits[3], radix).PadLeft(padding, paddingChar));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal static bool RepresentsValidNetMask(this byte[] bits)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
|
||||
int fromLeft = bits.CountFromLeft(true);
|
||||
int fromRight = bits.CountFromRight(false);
|
||||
|
||||
// Sum of all counted indexes schloud be equal the whole length
|
||||
return (fromLeft + fromRight) == (8 * NetMask.MaskLength);
|
||||
}
|
||||
|
||||
internal static byte[] And(this byte[] b1, byte[] b2)
|
||||
{
|
||||
if (b1 == null)
|
||||
throw new ArgumentNullException(nameof(b1));
|
||||
if (b2 == null)
|
||||
throw new ArgumentNullException(nameof(b2));
|
||||
|
||||
if (b1.Length == 1 && b2.Length == 1)
|
||||
{
|
||||
int ib1 = b1[0];
|
||||
int ib2 = b2[0];
|
||||
return new[] { (byte)(ib1 & ib2) };
|
||||
}
|
||||
if (b1.Length == 2 && b2.Length == 2)
|
||||
{
|
||||
var sb1 = BitConverter.ToInt16(b1, 0);
|
||||
var sb2 = BitConverter.ToInt16(b2, 0);
|
||||
return BitConverter.GetBytes((short)(sb1 & sb2));
|
||||
}
|
||||
if (b1.Length == 4 && b2.Length == 4)
|
||||
{
|
||||
var ib1 = BitConverter.ToInt32(b1, 0);
|
||||
var ib2 = BitConverter.ToInt32(b2, 0);
|
||||
return BitConverter.GetBytes(ib1 & ib2);
|
||||
}
|
||||
if (b1.Length != b2.Length)
|
||||
{
|
||||
// Or maybe throw exception?
|
||||
|
||||
int maxIndex = Math.Max(b1.Length, b2.Length);
|
||||
byte[] biggerArray = b1.Length > b2.Length ? b1 : b2;
|
||||
byte[] smallerArray = b1.Length <= b2.Length ? b1 : b2;
|
||||
|
||||
var paddedArray = new byte[maxIndex];
|
||||
|
||||
Buffer.BlockCopy(smallerArray, 0, paddedArray, 0, smallerArray.Length);
|
||||
|
||||
Debug.Assert(biggerArray.Length == paddedArray.Length);
|
||||
|
||||
return And(biggerArray, paddedArray);
|
||||
}
|
||||
|
||||
var targetIndex = b1.Length;
|
||||
var andedArray = new byte[targetIndex];
|
||||
Buffer.BlockCopy(b1, 0, andedArray, 0, andedArray.Length);
|
||||
|
||||
for (int i = 0; i < targetIndex; ++i)
|
||||
andedArray[i] &= b2[i];
|
||||
|
||||
return andedArray;
|
||||
}
|
||||
|
||||
internal static byte[] Or(this byte[] b1, byte[] b2)
|
||||
{
|
||||
if (b1 == null)
|
||||
throw new ArgumentNullException(nameof(b1));
|
||||
if (b2 == null)
|
||||
throw new ArgumentNullException(nameof(b2));
|
||||
|
||||
if (b1.Length == 1 && b2.Length == 1)
|
||||
{
|
||||
int ib1 = b1[0];
|
||||
int ib2 = b2[0];
|
||||
return new[] { (byte)(ib1 | ib2) };
|
||||
}
|
||||
if (b1.Length == 2 && b2.Length == 2)
|
||||
{
|
||||
var sb1 = BitConverter.ToInt16(b1, 0);
|
||||
var sb2 = BitConverter.ToInt16(b2, 0);
|
||||
return BitConverter.GetBytes((short)(sb1 | sb2));
|
||||
}
|
||||
if (b1.Length == 4 && b2.Length == 4)
|
||||
{
|
||||
var ib1 = BitConverter.ToInt32(b1, 0);
|
||||
var ib2 = BitConverter.ToInt32(b2, 0);
|
||||
return BitConverter.GetBytes(ib1 | ib2);
|
||||
}
|
||||
if (b1.Length != b2.Length)
|
||||
{
|
||||
// Or maybe throw exception?
|
||||
|
||||
int maxIndex = Math.Max(b1.Length, b2.Length);
|
||||
byte[] biggerArray = b1.Length > b2.Length ? b1 : b2;
|
||||
byte[] smallerArray = b1.Length <= b2.Length ? b1 : b2;
|
||||
|
||||
var paddedArray = new byte[maxIndex];
|
||||
|
||||
Buffer.BlockCopy(smallerArray, 0, paddedArray, 0, smallerArray.Length);
|
||||
|
||||
Debug.Assert(biggerArray.Length == paddedArray.Length);
|
||||
|
||||
return Or(biggerArray, paddedArray);
|
||||
}
|
||||
|
||||
var targetIndex = b1.Length;
|
||||
var oredArray = new byte[targetIndex];
|
||||
Buffer.BlockCopy(b1, 0, oredArray, 0, oredArray.Length);
|
||||
|
||||
for (int i = 0; i < targetIndex; ++i)
|
||||
oredArray[i] |= b2[i];
|
||||
|
||||
return oredArray;
|
||||
}
|
||||
|
||||
internal static byte[] Xor(this byte[] b1, byte[] b2)
|
||||
{
|
||||
if (b1 == null)
|
||||
throw new ArgumentNullException(nameof(b1));
|
||||
if (b2 == null)
|
||||
throw new ArgumentNullException(nameof(b2));
|
||||
|
||||
// TODO: Testing
|
||||
|
||||
if (b1.Length == 1 && b2.Length == 1)
|
||||
{
|
||||
int ib1 = b1[0];
|
||||
int ib2 = b2[0];
|
||||
return new[] { (byte)(ib1 ^ ib2) };
|
||||
}
|
||||
if (b1.Length == 2 && b2.Length == 2)
|
||||
{
|
||||
var sb1 = BitConverter.ToInt16(b1, 0);
|
||||
var sb2 = BitConverter.ToInt16(b2, 0);
|
||||
return BitConverter.GetBytes((short)(sb1 ^ sb2));
|
||||
}
|
||||
if (b1.Length == 4 && b2.Length == 4)
|
||||
{
|
||||
var ib1 = BitConverter.ToInt32(b1, 0);
|
||||
var ib2 = BitConverter.ToInt32(b2, 0);
|
||||
return BitConverter.GetBytes(ib1 ^ ib2);
|
||||
}
|
||||
if (b1.Length != b2.Length)
|
||||
{
|
||||
// Or maybe throw exception?
|
||||
|
||||
int maxIndex = Math.Max(b1.Length, b2.Length);
|
||||
byte[] biggerArray = b1.Length > b2.Length ? b1 : b2;
|
||||
byte[] smallerArray = b1.Length <= b2.Length ? b1 : b2;
|
||||
|
||||
var paddedArray = new byte[maxIndex];
|
||||
|
||||
Buffer.BlockCopy(smallerArray, 0, paddedArray, 0, smallerArray.Length);
|
||||
|
||||
Debug.Assert(biggerArray.Length == paddedArray.Length);
|
||||
|
||||
return Xor(biggerArray, paddedArray);
|
||||
}
|
||||
|
||||
var targetIndex = b1.Length;
|
||||
var xoredArray = new byte[targetIndex];
|
||||
Buffer.BlockCopy(b1, 0, xoredArray, 0, xoredArray.Length);
|
||||
|
||||
for (int i = 0; i < targetIndex; ++i)
|
||||
xoredArray[i] ^= b2[i];
|
||||
|
||||
return xoredArray;
|
||||
}
|
||||
|
||||
internal static byte[] Not(this byte[] bits)
|
||||
{
|
||||
if (bits == null)
|
||||
throw new ArgumentNullException(nameof(bits));
|
||||
|
||||
if (bits.Length == 4)
|
||||
{
|
||||
var i = BitConverter.ToInt32(bits, 0);
|
||||
return BitConverter.GetBytes(~i);
|
||||
}
|
||||
var newBytes = new byte[bits.Length];
|
||||
for (int i = 0; i < newBytes.Length; ++i)
|
||||
newBytes[i] = unchecked((byte)(~bits[i]));
|
||||
return newBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
internal static class ByteExtensions
|
||||
{
|
||||
public static byte[] BitReverseTable = {
|
||||
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
||||
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
||||
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
||||
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
||||
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
||||
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
||||
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
||||
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
||||
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
||||
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
||||
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
||||
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
||||
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
||||
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
||||
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
||||
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
||||
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
||||
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
||||
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
||||
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
||||
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
||||
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
||||
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
||||
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
||||
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
||||
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
||||
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
||||
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
||||
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
||||
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
||||
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
||||
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
||||
};
|
||||
|
||||
public static byte ReverseBits(this byte toReverse) => BitReverseTable[toReverse];
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
/// <summary>Provides an interface for IP net masks.</summary>
|
||||
public interface INetMask
|
||||
{
|
||||
/// <summary>Gets the length of the net mask in bits.</summary>
|
||||
int AddressLength { get; }
|
||||
|
||||
/// <summary>Gets the amount of set bits from the left side (used in CIDR-Notation of net masks).</summary>
|
||||
int Cidr { get; }
|
||||
|
||||
/// <summary>Gets the bits of the net mask instance as an BitArray object instance.</summary>
|
||||
/// <returns>The bits of the net mask instance as an BitArray object instance</returns>
|
||||
byte[] GetMaskBytes();
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
/// <summary>Provides extension methods for the <see cref="T:System.Net.IPAddress"/>.</summary>
|
||||
public static class IPAddressExtensions
|
||||
{
|
||||
private const string OnlyIPv4Supported = "Only IPv4 is currently supported";
|
||||
|
||||
/// <summary>Enumerates through the siblings of an <see cref="T:System.Net.IPAddress"/> in a network. Compliant to RFC 950 (2^n-2).</summary>
|
||||
/// <param name="address">The address</param>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
public static IEnumerable<IPAddress> GetSiblings(this IPAddress address, NetMask mask)
|
||||
{
|
||||
return GetSiblings(address, mask, SiblingOptions.ExcludeUnusable);
|
||||
}
|
||||
|
||||
/// <summary>Enumerates through the siblings of an <see cref="T:System.Net.IPAddress"/> in a network.</summary>
|
||||
/// <param name="address">The address</param>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <param name="options">Options which addresses to include an which not</param>
|
||||
public static IEnumerable<IPAddress> GetSiblings(this IPAddress address, NetMask mask, SiblingOptions options)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException(nameof(mask));
|
||||
if (address.AddressFamily != Sockets.AddressFamily.InterNetwork)
|
||||
throw new NotSupportedException(OnlyIPv4Supported);
|
||||
|
||||
bool includeSelf = BitHelper.IsOptionSet(options, SiblingOptions.IncludeSelf);
|
||||
bool includeBroadcast = BitHelper.IsOptionSet(options, SiblingOptions.IncludeBroadcast);
|
||||
bool includeNetworkIdentifier = BitHelper.IsOptionSet(options, SiblingOptions.IncludeNetworkIdentifier);
|
||||
|
||||
bool alreadyReturnedSelf = false;
|
||||
|
||||
var netPrefix = address.GetNetworkPrefix(mask);
|
||||
|
||||
if (includeNetworkIdentifier)
|
||||
{
|
||||
netPrefix = address.GetNetworkPrefix(mask);
|
||||
if (netPrefix.Equals(address))
|
||||
alreadyReturnedSelf = true;
|
||||
yield return netPrefix;
|
||||
}
|
||||
|
||||
var selfAddressBytes = address.GetAddressBytes();
|
||||
|
||||
var netPrefixBytes = netPrefix.GetAddressBytes();
|
||||
|
||||
int cidr = mask.Cidr;
|
||||
uint maxHosts = 0xFFFFFFFF;
|
||||
|
||||
if (cidr > 0)
|
||||
maxHosts = (uint)(1 << (8 * NetMask.MaskLength - cidr)) - 1;
|
||||
|
||||
var hostBytes = new byte[NetMask.MaskLength];
|
||||
for (int hostPart = 1; hostPart < maxHosts; ++hostPart)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
hostBytes[0] = (byte)(hostPart >> 24);
|
||||
hostBytes[1] = (byte)(hostPart >> 16);
|
||||
hostBytes[2] = (byte)(hostPart >> 8);
|
||||
hostBytes[3] = (byte)(hostPart >> 0);
|
||||
}
|
||||
|
||||
Debug.WriteLine("HostPart: " + hostPart.ToString("X2").PadLeft(8, '0') + " (" + BitConverter.ToString(hostBytes) + ")");
|
||||
|
||||
var nextIpBytes = netPrefixBytes.Or(hostBytes);
|
||||
var nextIp = new IPAddress(nextIpBytes);
|
||||
|
||||
if (!alreadyReturnedSelf)
|
||||
{
|
||||
if (includeSelf)
|
||||
{
|
||||
if (nextIpBytes[0] == selfAddressBytes[0]
|
||||
&& nextIpBytes[1] == selfAddressBytes[1]
|
||||
&& nextIpBytes[2] == selfAddressBytes[2]
|
||||
&& nextIpBytes[3] == selfAddressBytes[3])
|
||||
alreadyReturnedSelf = true;
|
||||
yield return nextIp;
|
||||
}
|
||||
else if (nextIpBytes[0] != selfAddressBytes[0]
|
||||
|| nextIpBytes[1] != selfAddressBytes[1]
|
||||
|| nextIpBytes[2] != selfAddressBytes[2]
|
||||
|| nextIpBytes[3] != selfAddressBytes[3])
|
||||
yield return nextIp;
|
||||
}
|
||||
else
|
||||
yield return nextIp;
|
||||
}
|
||||
|
||||
if (includeBroadcast)
|
||||
{
|
||||
var broadcastAddress = address.GetBroadcastAddress(mask);
|
||||
if (!address.Equals(broadcastAddress) || (address.Equals(broadcastAddress) && !alreadyReturnedSelf))
|
||||
yield return broadcastAddress;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets the network prefix of an <see cref="T:System.Net.IPAddress"/>.</summary>
|
||||
/// <param name="address">The address</param>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <returns>The network prefix of an <see cref="T:System.Net.IPAddress"/></returns>
|
||||
public static IPAddress GetNetworkPrefix(this IPAddress address, NetMask mask)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException(nameof(mask));
|
||||
|
||||
if (address.AddressFamily != Sockets.AddressFamily.InterNetwork)
|
||||
throw new NotSupportedException(OnlyIPv4Supported);
|
||||
|
||||
return mask & address;
|
||||
}
|
||||
|
||||
/// <summary>Gets the broadcast address of an <see cref="T:System.Net.IPAddress"/>.</summary>
|
||||
/// <param name="address">The address</param>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <returns>The broadcast address of an <see cref="T:System.Net.IPAddress"/></returns>
|
||||
public static IPAddress GetBroadcastAddress(this IPAddress address, NetMask mask)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException("address");
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException("mask");
|
||||
|
||||
if (address.AddressFamily != Sockets.AddressFamily.InterNetwork)
|
||||
throw new NotSupportedException(OnlyIPv4Supported);
|
||||
|
||||
// TODO: Test
|
||||
|
||||
var ipBytes = address.GetAddressBytes();
|
||||
var notMaskBytes = mask.GetMaskBytes().Not();
|
||||
|
||||
var broadcastAddressBytes = notMaskBytes.Or(ipBytes);
|
||||
return new IPAddress(broadcastAddressBytes);
|
||||
}
|
||||
|
||||
/// <summary>Gets the host identifier (rest) an <see cref="T:System.Net.IPAddress"/>.</summary>
|
||||
/// <param name="address">The address</param>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <returns>The host identifier (rest) an <see cref="T:System.Net.IPAddress"/></returns>
|
||||
public static IPAddress GetHostIdentifier(this IPAddress address, NetMask mask)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException(nameof(mask));
|
||||
if (address.AddressFamily != Sockets.AddressFamily.InterNetwork)
|
||||
throw new NotSupportedException(OnlyIPv4Supported);
|
||||
|
||||
var maskBits = mask.GetMaskBytes();
|
||||
var ipBits = address.GetAddressBytes();
|
||||
|
||||
// ~Mask & IP
|
||||
var retVal = maskBits.Not().And(ipBits);
|
||||
var bytes = new byte[NetMask.MaskLength];
|
||||
Buffer.BlockCopy(retVal, 0, bytes, 0, bytes.Length);
|
||||
|
||||
return new IPAddress(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
// TODO: Use Span<T> when available (instead of byte arrays)
|
||||
/// <summary>Represents an IPv4 net mask.</summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct NetMask : INetMask, IEquatable<NetMask>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
private readonly uint _mask;
|
||||
|
||||
#region byte-wise fields
|
||||
|
||||
// We are assuming here, that the byte-ordering is like on a normal x86 system
|
||||
|
||||
[FieldOffset(3)]
|
||||
private readonly byte _maskB0;
|
||||
[FieldOffset(2)]
|
||||
private readonly byte _maskB1;
|
||||
[FieldOffset(1)]
|
||||
private readonly byte _maskB2;
|
||||
[FieldOffset(0)]
|
||||
private readonly byte _maskB3;
|
||||
|
||||
#endregion
|
||||
|
||||
internal const int MaskLength = 4;
|
||||
|
||||
/// <summary>Represents an empty IPv4 NetMask (all bits set to 0).</summary>
|
||||
public static NetMask Empty { get; } = new NetMask();
|
||||
|
||||
/// <summary>Gets the length of the net mask in bits.</summary>
|
||||
public int AddressLength => MaskLength * 8;
|
||||
|
||||
/// <summary>Gets the amount of set bits from the left side (used in CIDR-Notation of net masks).</summary>
|
||||
public int Cidr => GetCidr(_mask);
|
||||
|
||||
#region Ctors
|
||||
|
||||
/// <summary>Creates a new instance of <see cref="T:System.Net.Topology.NetMask"/> cloning an existing instance of <see cref="T:System.Net.Topology.NetMask"/>.</summary>
|
||||
public NetMask(NetMask mask)
|
||||
{
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException(nameof(mask));
|
||||
_maskB0 = _maskB1 = _maskB2 = _maskB3 = 0;
|
||||
_mask = mask._mask;
|
||||
}
|
||||
|
||||
/// <summary>Creates a new instance of <see cref="T:System.Net.Topology.NetMask"/> from an array of <see cref="System.Byte"/>.</summary>
|
||||
public NetMask(byte[] value)
|
||||
{
|
||||
_maskB0 = _maskB1 = _maskB2 = _maskB3 = 0;
|
||||
_mask = 0;
|
||||
if (value == null || value.Length == 0) // maybe throw ArgumentNullException?
|
||||
return;
|
||||
|
||||
if (value.Length != MaskLength)
|
||||
throw new ArgumentException("Invalid mask length.");
|
||||
|
||||
CheckMaskBytes(value); // check if passed mask are a valid mask. if not, throw Exception
|
||||
_maskB0 = value[0];
|
||||
_maskB1 = value[1];
|
||||
_maskB2 = value[2];
|
||||
_maskB3 = value[3];
|
||||
}
|
||||
|
||||
/// <summary>Creates a new instance of <see cref="T:System.Net.Topology.NetMask"/> from a given <see cref="T:System.Net.IPAddress"/>.</summary>
|
||||
/// <param name="address">The IPv4 address.</param>
|
||||
public NetMask(IPAddress address)
|
||||
: this(address == null ? null : address.GetAddressBytes())
|
||||
{ }
|
||||
|
||||
/// <summary>Creates a new instance of <see cref="T:System.Net.Topology.NetMask"/>.</summary>
|
||||
/// <param name="m0">The first byte.</param>
|
||||
/// <param name="m1">The second byte.</param>
|
||||
/// <param name="m2">The third byte.</param>
|
||||
/// <param name="m3">The fourth byte.</param>
|
||||
public NetMask(byte m0, byte m1, byte m2, byte m3)
|
||||
: this(new[] { m0, m1, m2, m3 })
|
||||
{ }
|
||||
|
||||
/// <summary>Creates a new instance of <see cref="T:System.Net.Topology.NetMask"/>.</summary>
|
||||
/// <param name="cidr">The mask represented by the CIDR notation integer.</param>
|
||||
public NetMask(byte cidr)
|
||||
{
|
||||
// maybe change parameter type interpretation to CIDR?
|
||||
if (cidr > MaskLength * 8)
|
||||
throw new ArgumentException("Invalid CIDR length");
|
||||
_maskB0 = _maskB1 = _maskB2 = _maskB3 = 0; // to keep init checks happy
|
||||
_mask = GetUIntFromCidrValue(cidr);
|
||||
}
|
||||
|
||||
private NetMask(uint ipv4Mask)
|
||||
{
|
||||
_maskB0 = _maskB1 = _maskB2 = _maskB3 = 0; // to keep init checks happy
|
||||
_mask = ipv4Mask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void CheckMaskBytes(byte[] bytes)
|
||||
{
|
||||
if (!bytes.RepresentsValidNetMask())
|
||||
throw new ArgumentException("The passed mask do not represent a valid net mask.");
|
||||
}
|
||||
|
||||
/// <summary>Gets the bits of the net mask instance as an BitArray object instance.</summary>
|
||||
/// <returns>The bits of the net mask instance as an BitArray object instance.</returns>
|
||||
public byte[] GetMaskBytes() => new[] { _maskB0, _maskB1, _maskB2, _maskB3 };
|
||||
|
||||
private static int GetCidr(uint mask)
|
||||
{
|
||||
Debug.Assert(sizeof(uint) == MaskLength);
|
||||
return mask.CountOnesFromLeft();
|
||||
}
|
||||
|
||||
/// <summary>Extends the current <see cref="T:System.Net.Topology.NetMask"/> instance by a given value (CIDR-wise).</summary>
|
||||
/// <param name="mask">The mask to use as a reference.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <remarks>Because <see cref="T:System.Net.Topology.NetMask"/> is a reference type, this method is static. If it were not like this, you could change the value of <see cref="T:System.Net.Topology.NetMask"/>.Empty, for example.</remarks>
|
||||
public static NetMask Extend(NetMask mask, int value)
|
||||
{
|
||||
int currentCidr = mask.Cidr;
|
||||
if (currentCidr >= MaskLength * 8)
|
||||
return new NetMask(mask);
|
||||
if (currentCidr <= 0)
|
||||
currentCidr = 0;
|
||||
|
||||
int newLength = Math.Max(Math.Min(currentCidr + value, 32), 0);
|
||||
|
||||
var m = BytesFromCidrValue(newLength);
|
||||
|
||||
return new NetMask(m);
|
||||
}
|
||||
|
||||
/// <summary>Abbreviates the current <see cref="T:System.Net.Topology.NetMask"/> instance by a given value (CIDR-wise).</summary>
|
||||
/// <param name="mask">The mask to use as a reference.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <remarks>Because <see cref="T:System.Net.Topology.NetMask"/> is a reference type, this method is static. If it were not like this, you could change the value of <see cref="T:System.Net.Topology.NetMask"/>.Empty, for example.</remarks>
|
||||
public static NetMask Abbreviate(NetMask mask, int value)
|
||||
{
|
||||
int currentCidr = mask.Cidr;
|
||||
if (currentCidr < 1)
|
||||
return new NetMask(mask);
|
||||
if (currentCidr >= MaskLength * 8)
|
||||
currentCidr = MaskLength * 8;
|
||||
|
||||
int newLength = Math.Max(Math.Min(currentCidr - value, 32), 0);
|
||||
|
||||
var m = BytesFromCidrValue(newLength);
|
||||
return new NetMask(m);
|
||||
}
|
||||
|
||||
/// <summary>Returns a value indicating whether the given array of <see cref="T:System.Byte"/> represents a valid net mask.</summary>
|
||||
/// <returns>True if the given array of <see cref="T:System.Byte"/> represents a valid net mask, otherwise false.</returns>
|
||||
public static bool GetIsValidNetMask(byte[] mask) => mask.RepresentsValidNetMask();
|
||||
|
||||
// TODO: Testing(!)
|
||||
[Obsolete]
|
||||
private static byte[] BytesFromCidrValue(int cidr)
|
||||
{
|
||||
int target = MaskLength * 8 - cidr;
|
||||
int mask = 0;
|
||||
for (int i = 0; i < target; ++i)
|
||||
{
|
||||
mask >>= 1;
|
||||
mask |= unchecked((int)0x80000000);
|
||||
}
|
||||
var bytes = BitConverter.GetBytes(~mask);
|
||||
return new[] {
|
||||
bytes[0].ReverseBits(),
|
||||
bytes[1].ReverseBits(),
|
||||
bytes[2].ReverseBits(),
|
||||
bytes[3].ReverseBits()
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Testing(!)
|
||||
private static uint GetUIntFromCidrValue(int cidr) => UIntExtensions.CreateWithOnesFromLeft(cidr);
|
||||
|
||||
#region Operators
|
||||
|
||||
#region Equality
|
||||
|
||||
/// <summary>Returns a other indicating whether two instances of <see cref="T:System.Net.Topology.NetMask" /> are equal.</summary>
|
||||
/// <param name="n1">The first other to compare.</param>
|
||||
/// <param name="n2">The second other to compare.</param>
|
||||
/// <returns>true if <paramref name="n1" /> and <paramref name="n2" /> are equal; otherwise, false.</returns>
|
||||
public static bool operator ==(NetMask n1, NetMask n2)
|
||||
{
|
||||
if (ReferenceEquals(n1, n2))
|
||||
return true;
|
||||
if (((object)n1 == null) || ((object)n2 == null))
|
||||
return false;
|
||||
return n1.Equals(n2);
|
||||
}
|
||||
|
||||
/// <summary>Returns a other indicating whether two instances of <see cref="T:System.Net.Topology.NetMask" /> are not equal.</summary>
|
||||
/// <param name="n1">The first other to compare. </param>
|
||||
/// <param name="n2">The second other to compare. </param>
|
||||
/// <returns>true if <paramref name="n1" /> and <paramref name="n2" /> are not equal; otherwise, false.</returns>
|
||||
public static bool operator !=(NetMask n1, NetMask n2) => !(n1 == n2); // Problem solved
|
||||
|
||||
#endregion
|
||||
#region And
|
||||
|
||||
/// <summary>Bitwise combines a <see cref="T:System.Net.Topology.NetMask" /> instance and an <see cref="T:System.Net.IPAddress"/> the AND operation.</summary>
|
||||
/// <param name="mask">The net mask.</param>
|
||||
/// <param name="address">The IPAddress.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static IPAddress operator &(IPAddress address, NetMask mask) => mask & address;
|
||||
|
||||
/// <summary>Bitwise combines a <see cref="T:System.Net.Topology.NetMask" /> instance and an <see cref="T:System.Net.IPAddress"/> the AND operation.</summary>
|
||||
/// <param name="mask">The net mask.</param>
|
||||
/// <param name="address">The IPAddress.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static IPAddress BitwiseAnd(IPAddress address, NetMask mask) => mask & address;
|
||||
|
||||
/// <summary>Bitwise combines a <see cref="T:System.Net.Topology.NetMask" /> instance and an <see cref="T:System.Net.IPAddress"/> the AND operation.</summary>
|
||||
/// <param name="mask">The net mask.</param>
|
||||
/// <param name="address">The IPAddress.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static IPAddress operator &(NetMask mask, IPAddress address)
|
||||
{
|
||||
var ipBytes = address == null
|
||||
? new byte[MaskLength]
|
||||
: address.GetAddressBytes();
|
||||
var maskBytes = mask == null
|
||||
? new byte[MaskLength]
|
||||
: new byte[] { mask._maskB0, mask._maskB1, mask._maskB2, mask._maskB3 };
|
||||
|
||||
byte[] combinedBytes = maskBytes.And(ipBytes);
|
||||
return new IPAddress(combinedBytes);
|
||||
}
|
||||
|
||||
/// <summary>Bitwise combines a <see cref="T:System.Net.Topology.NetMask" /> instance and an <see cref="T:System.Net.IPAddress"/> the AND operation.</summary>
|
||||
/// <param name="mask">The net mask.</param>
|
||||
/// <param name="address">The IPAddress.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static IPAddress BitwiseAnd(NetMask mask, IPAddress address) => mask & address;
|
||||
|
||||
/// <summary>Bitwise combines the two instances of <see cref="T:System.Net.Topology.NetMask" /> using the AND operation.</summary>
|
||||
/// <param name="n1">The first other.</param>
|
||||
/// <param name="n2">The second other.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static NetMask operator &(NetMask n1, NetMask n2) => new NetMask(n1._mask & n2._mask);
|
||||
|
||||
/// <summary>Bitwise combines the two instances of <see cref="T:System.Net.Topology.NetMask" /> using the AND operation.</summary>
|
||||
/// <param name="n1">The first other.</param>
|
||||
/// <param name="n2">The second other.</param>
|
||||
/// <returns>The bitwised combination using the AND operation.</returns>
|
||||
public static NetMask BitwiseAnd(NetMask n1, NetMask n2) => n1 & n2;
|
||||
|
||||
#endregion
|
||||
#region Or
|
||||
|
||||
/// <summary>Bitwise combines the two instances of <see cref="T:System.Net.Topology.NetMask" /> using the OR operation.</summary>
|
||||
/// <param name="n1">The first other.</param>
|
||||
/// <param name="n2">The second other.</param>
|
||||
/// <returns>The bitwised combination using the OR operation.</returns>
|
||||
public static NetMask operator |(NetMask n1, NetMask n2) => new NetMask(n1._mask | n2._mask);
|
||||
|
||||
/// <summary>Bitwise combines the two instances of <see cref="T:System.Net.Topology.NetMask" /> using the OR operation.</summary>
|
||||
/// <param name="n1">The first other.</param>
|
||||
/// <param name="n2">The second other.</param>
|
||||
/// <returns>The bitwised combination using the OR operation.</returns>
|
||||
public static NetMask BitwiseOr(NetMask n1, NetMask n2) => n1 | n2;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Common overrides
|
||||
|
||||
/// <summary>Converts the other of this instance to its equivalent string representation.</summary>
|
||||
/// <returns>A string that represents the other of this instance.</returns>
|
||||
/// <filterpriority>1</filterpriority>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder(4 * 3 + 3 * 3 + 32 + 3 + 3); // 255.255.255.255 (11111111111111111111111111111111)
|
||||
|
||||
var arr = new byte[] { _maskB0, _maskB1, _maskB2, _maskB3 };
|
||||
var asString = arr.ToBinaryString('.');
|
||||
|
||||
sb.Append(arr[0]).Append('.').Append(arr[1]).Append('.').Append(arr[2]).Append('.').Append(arr[3]).Append(" (");
|
||||
sb.Append(asString).Append(')');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>Returns a value indicating whether this instance and a specified <see cref="T:System.Object" /> represent the same type and other.</summary>
|
||||
/// <returns>true if <paramref name="obj" /> is a <see cref="T:System.Net.Topology.NetMask" /> and equal to this instance; otherwise, false.</returns>
|
||||
/// <param name="obj">The object to compare with this instance. </param>
|
||||
/// <filterpriority>2</filterpriority>
|
||||
public override bool Equals(object obj) => obj != null && obj is NetMask && Equals((NetMask)obj);
|
||||
|
||||
/// <summary>Returns a value indicating whether this instance and a specified <see cref="T:System.Net.Topology.NetMask" /> object represent the same other.</summary>
|
||||
/// <returns>true if <paramref name="other" /> is equal to this instance; otherwise, false.</returns>
|
||||
/// <param name="other">An object to compare to this instance.</param>
|
||||
/// <filterpriority>2</filterpriority>
|
||||
public bool Equals(NetMask other) => other._mask == _mask;
|
||||
|
||||
/// <summary>Returns the hash code for this instance.</summary>
|
||||
/// <returns>A 32-bit signed integer hash code.</returns>
|
||||
/// <filterpriority>2</filterpriority>
|
||||
public override int GetHashCode() => unchecked((int)_mask);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
/// <summary>Provides extension methods for the <see cref="T:System.Net.Topology.NetMask"/>.</summary>
|
||||
public static class NetMaskExtensions
|
||||
{
|
||||
/// <summary>Gets the number of siblings an <see cref="T:System.Net.IPAddress"/> can have in a given network. Compliant to RFC 950 (2^n-2).</summary>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <returns>The number of siblings an <see cref="T:System.Net.IPAddress"/> can have in the given network.</returns>
|
||||
public static int GetSiblingCount(this NetMask mask) => GetSiblingCount(mask, SiblingOptions.ExcludeUnusable);
|
||||
|
||||
/// <summary>Gets the number of siblings an <see cref="T:System.Net.IPAddress"/> can have in a given network.</summary>
|
||||
/// <param name="mask">The net mask of the network</param>
|
||||
/// <param name="options">Options which addresses to include an which not</param>
|
||||
/// <returns>The number of siblings an <see cref="T:System.Net.IPAddress"/> can have in the given network.</returns>
|
||||
public static int GetSiblingCount(this NetMask mask, SiblingOptions options)
|
||||
{
|
||||
if (mask == null)
|
||||
throw new ArgumentNullException(nameof(mask));
|
||||
|
||||
bool includeSelf = BitHelper.IsOptionSet(options, SiblingOptions.IncludeSelf);
|
||||
bool includeBroadcast = BitHelper.IsOptionSet(options, SiblingOptions.IncludeBroadcast);
|
||||
bool includeNetworkIdentifier = BitHelper.IsOptionSet(options, SiblingOptions.IncludeNetworkIdentifier);
|
||||
|
||||
var hostPartBits = mask.GetMaskBytes().CountFromRight(false);
|
||||
var total = 1 << hostPartBits;
|
||||
total -= includeSelf ? 0 : 1;
|
||||
total -= includeBroadcast ? 0 : 1;
|
||||
total -= includeNetworkIdentifier ? 0 : 1;
|
||||
|
||||
// TODO: Testing
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
/// <summary>Provides options for doing network sibling calculations using a net mask.</summary>
|
||||
[Flags]
|
||||
public enum SiblingOptions
|
||||
{
|
||||
/// <summary>Do not include the broadcast or net address neither the addess passed to the method.</summary>
|
||||
ExcludeAll = 0,
|
||||
/// <summary>Include the addess passed to the method.</summary>
|
||||
IncludeSelf = 1,
|
||||
/// <summary>Include the addess passed to the method. Compliant to RFC 950 (2^n-2).</summary>
|
||||
ExcludeUnusable = IncludeSelf,
|
||||
/// <summary>Include the broadcast address.</summary>
|
||||
IncludeBroadcast = 2,
|
||||
/// <summary>Include the net address.</summary>
|
||||
IncludeNetworkIdentifier = 4,
|
||||
/// <summary>Include all addresses possible. RFC 1878 (2^n).</summary>
|
||||
IncludeAll = IncludeSelf | IncludeBroadcast | IncludeNetworkIdentifier
|
||||
}
|
||||
|
||||
internal static class BitHelper
|
||||
{
|
||||
[Runtime.TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] // as if NGen will ever compile this assembly ;)
|
||||
[Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
internal static bool IsOptionSet(SiblingOptions value, SiblingOptions testValue) => (value & testValue) == testValue;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
internal static class StringExtensions
|
||||
{
|
||||
// TODO: The following method uses unsafe stuff. We don't want to pass the /unsafe flag to the compiler, so we use a simple, safe method instead.
|
||||
// As soon as .NET Standard with Span<T> and the new String.Create is available, we can make this faster and safe.
|
||||
/*
|
||||
internal static unsafe string Reverse(this string input)
|
||||
{
|
||||
int len = input.Length;
|
||||
|
||||
// Why allocate a char[] array on the heap when you won't use it
|
||||
// outside of this method? Use the stack.
|
||||
char* reversed = stackalloc char[len];
|
||||
|
||||
// Avoid bounds-checking performance penalties.
|
||||
fixed (char* str = input)
|
||||
{
|
||||
int i = 0;
|
||||
int j = i + len - 1;
|
||||
while (i < len)
|
||||
reversed[i++] = str[j--];
|
||||
}
|
||||
|
||||
// Need to use this overload for the System.String constructor
|
||||
// as providing just the char* pointer could result in garbage
|
||||
// at the end of the string (no guarantee of null terminator).
|
||||
return new string(reversed, 0, len);
|
||||
}
|
||||
*/
|
||||
internal static string Reverse(this string input)
|
||||
{
|
||||
char[] chars = input.ToCharArray();
|
||||
Array.Reverse(chars);
|
||||
return new string(chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Net.Topology
|
||||
{
|
||||
internal static class UIntExtensions
|
||||
{
|
||||
// TODO: Tests
|
||||
public static int CountOnesFromLeft(this uint value)
|
||||
{
|
||||
var occurences = 0;
|
||||
for (uint i = 1u << 31; i >= 0; i >>= 1)
|
||||
{
|
||||
if ((i & value) != 0)
|
||||
++occurences;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return occurences;
|
||||
}
|
||||
|
||||
// TODO: Tests
|
||||
public static uint CreateWithOnesFromLeft(int count)
|
||||
{
|
||||
if (count > 32)
|
||||
throw new ArgumentException("Cannot set more than 32 bits to one!");
|
||||
|
||||
var value = 0u;
|
||||
|
||||
var mask = 1u << 31;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
value |= mask;
|
||||
mask >>= 1;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Authors>Niklas Mollenhauer</Authors>
|
||||
<PackageVersion>2.0.2</PackageVersion>
|
||||
<Description>Library for Sending magic packets and performing IP address operations.</Description>
|
||||
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/nikeee/wake-on-lan</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/nikeee/wake-on-lan.git</RepositoryUrl>
|
||||
<PackageTags>WakeOnLan, magic packets</PackageTags>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<RootNamespace>System.Net</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
|
||||
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user