Browse Source

Initial commit

master
Burathar 5 years ago
commit
e00adcc37f
  1. 225
      .gitignore
  2. 25
      ChromaEffectsImporter.sln
  3. 6
      ChromaEffectsImporter/App.config
  4. 86
      ChromaEffectsImporter/ChromaEffectsImporter.csproj
  5. 209
      ChromaEffectsImporter/ChromaEffectsReader.cs
  6. 50
      ChromaEffectsImporter/ColoreOutput.cs
  7. 30
      ChromaEffectsImporter/EffectRegion.cs
  8. 20
      ChromaEffectsImporter/Program.cs
  9. 35
      ChromaEffectsImporter/Properties/AssemblyInfo.cs
  10. 1243
      ChromaEffectsImporter/Resources/ChromaEffects.xml
  11. 11
      ChromaEffectsImporter/packages.config

225
.gitignore vendored

@ -0,0 +1,225 @@
# The following command works for downloading when using Git for Windows:
# curl -LOf http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
#
# Download this file using PowerShell v3 under Windows with the following comand:
# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore
#
# or wget:
# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/
# build folder is nowadays used for build scripts and should not be ignored
#build/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# OS generated files #
.DS_Store*
Icon?
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
modulesbin/
tempbin/
# EPiServer Site file (VPP)
AppData/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# vim
*.txt~
*.swp
*.swo
# Temp files when opening LibreOffice on ubuntu
.~lock.*
# svn
.svn
# CVS - Source Control
**/CVS/
# Remainings from resolving conflicts in Source Control
*.orig
# SQL Server files
**/App_Data/*.mdf
**/App_Data/*.ldf
**/App_Data/*.sdf
#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
# SASS Compiler cache
.sass-cache
# Visual Studio 2014 CTP
**/*.sln.ide
# Visual Studio temp something
.vs/
# dotnet stuff
project.lock.json
# VS 2015+
*.vc.vc.opendb
*.vc.db
# Rider
.idea/
# Visual Studio Code
.vscode/
# Output folder used by Webpack or other FE stuff
**/node_modules/*
**/wwwroot/*
# SpecFlow specific
*.feature.cs
*.feature.xlsx.*
*.Specs_*.html
#####
# End of core ignore list, below put you custom 'per project' settings (patterns or path)
#####

25
ChromaEffectsImporter.sln

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChromaEffectsImporter", "ChromaEffectsImporter\ChromaEffectsImporter.csproj", "{E3050745-702E-4143-A41D-FD549C8C46F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E3050745-702E-4143-A41D-FD549C8C46F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3050745-702E-4143-A41D-FD549C8C46F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3050745-702E-4143-A41D-FD549C8C46F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3050745-702E-4143-A41D-FD549C8C46F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6D4C95F-CE6C-4DE5-99DA-A1DCB951EC84}
EndGlobalSection
EndGlobal

6
ChromaEffectsImporter/App.config

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

86
ChromaEffectsImporter/ChromaEffectsImporter.csproj

@ -0,0 +1,86 @@
<?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')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E3050745-702E-4143-A41D-FD549C8C46F9}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ChromaEffectsImporter</RootNamespace>
<AssemblyName>ChromaEffectsImporter</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="Colore, Version=6.0.0.5, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Colore.6.0.0-rc0005\lib\net451\Colore.dll</HintPath>
</Reference>
<Reference Include="JetBrains.Annotations, Version=11.1.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<HintPath>..\packages\JetBrains.Annotations.11.1.0\lib\net20\JetBrains.Annotations.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ChromaEffectsReader.cs" />
<Compile Include="ColoreOutput.cs" />
<Compile Include="EffectRegion.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
</Project>

209
ChromaEffectsImporter/ChromaEffectsReader.cs

@ -0,0 +1,209 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Colore.Data;
using Colore.Effects.Keyboard;
namespace ChromaEffectsImporter
{
internal class ChromaEffectsReader
{
public EffectRegion[] ReadFirstStatic(string filePath)
{
XDocument root = XDocument.Load(filePath);
IEnumerable<XElement> effectLayers = root.Descendants("EffectLayer").Where(x => x.Descendants("Effect").First().Value == "static");
return effectLayers.SelectMany(layer => layer.Descendants("EffectRegion").Select(region =>
{
return new EffectRegion(
GetKeys(region),
GetColor(region));
})).ToArray();
}
private Key[] GetKeys(XElement region)
{
IEnumerable<XElement> deviceCells = region.Descendants("DeviceCell");
List<RazerKey> keys = new List<RazerKey>();
foreach (XElement cell in deviceCells)
{
int row = Convert.ToInt32(cell.Descendants("Row").First().Value);
int column = Convert.ToInt32(cell.Descendants("Col").First().Value);
keys.Add((RazerKey)column + row * 256);
}
return keys.Select(razerKey => (Key)Enum.Parse(typeof(Key), razerKey.ToString())).ToArray();
}
private Color GetColor(XElement region)
{
XElement rzColor = region.Descendants("RzColor").First();
int red = 0, green = 0, blue = 0;
foreach (XElement element in rzColor.Descendants())
{
switch (element.Name.ToString())
{
case "Red":
red = Convert.ToInt32(element.Value);
break;
case "Green":
green = Convert.ToInt32(element.Value);
break;
case "Blue":
blue = Convert.ToInt32(element.Value);
break;
default:
throw new ArgumentException("Argument value not expected", "element");
}
}
return Color.FromRgb((uint)((red << 16) | (green << 8) | blue));
}
}
/// <summary>
/// Definition of almost all keyboard keys, with id's matching the Razer Synapse Grid.
/// Keys not present on the US-International are not tested, and so commented out. If you need these, just test where they should be using a known ChromaEffects map.
/// </summary>
internal enum RazerKey
{
Escape = 1,
F1 = 4,
F2 = 5,
F3 = 6,
F4 = 7,
F5 = 8,
F6 = 9,
F7 = 10,
F8 = 11,
F9 = 12,
F10 = 13,
F11 = 14,
F12 = 15,
PrintScreen = 16,
Scroll = 17,
Pause = 18,
//JpnYen = 21,
//KorPipe = 21,
Macro1 = 256,
OemTilde = 257,
D1 = 258,
D2 = 259,
D3 = 260,
D4 = 261,
D5 = 262,
D6 = 263,
D7 = 264,
D8 = 265,
D9 = 266,
D0 = 267,
OemMinus = 268,
OemEquals = 269,
Backspace = 270,
Insert = 272,
Home = 273,
PageUp = 274,
NumLock = 275,
NumDivide = 276,
NumMultiply = 277,
NumSubtract = 278,
Macro2 = 512,
Tab = 513,
Q = 514,
W = 515,
E = 516,
R = 517,
T = 518,
Y = 519,
U = 520,
I = 521,
O = 522,
P = 523,
OemLeftBracket = 524,
OemRightBracket = 525,
OemBackslash = 526,
Delete = 528,
End = 529,
PageDown = 530,
Num7 = 531,
Num8 = 532,
Num9 = 533,
NumAdd = 534,
Macro3 = 768,
CapsLock = 770,
A = 771,
S = 772,
D = 773,
F = 774,
G = 775,
H = 776,
J = 777,
K = 778,
L = 779,
OemSemicolon = 780,
OemApostrophe = 781,
//EurPound = 782,
//Kor2 = 782,
Enter = 782,
Num4 = 787,
Num5 = 788,
Num6 = 789,
Macro4 = 1024,
//EurBackslash = 1025,
//Kor3 = 1025,
LeftShift = 1026,
Z = 1027,
X = 1028,
C = 1029,
V = 1039,
B = 1031,
N = 1032,
M = 1033,
OemComma = 1034,
OemPeriod = 1035,
OemSlash = 1036,
//JpnSlash = 1037,
//Kor4 = 1037,
RightShift = 1038,
Up = 1041,
Num1 = 1043,
Num2 = 1044,
Num3 = 1045,
Macro5 = 1280,
LeftControl = 1281,
LeftWindows = 1282,
LeftAlt = 1283,
//Jpn3 = 1284,
//Kor5 = 1284,
Space = 1287,
//Jpn4 = 1289,
//Kor6 = 1289,
//Jpn5 = 1290,
//Kor7 = 1290,
RightAlt = 1292,
Function = 1293,
RightMenu = 1294,
RightControl = 1295,
Left = 1296,
Down = 1297,
Right = 1298,
Num0 = 1300,
NumDecimal = 1301,
NumEnter = 1302,
Logo = 1548,
Invalid = 65535
}
}

50
ChromaEffectsImporter/ColoreOutput.cs

@ -0,0 +1,50 @@
using Colore;
using Colore.Data;
using Colore.Effects.Keyboard;
using System;
using System.Threading;
namespace ChromaEffectsImporter
{
internal class ColoreOutput
{
private IChroma chroma;
private string ChromaEffectPath;
public ColoreOutput(string chromaEffectPath)
{
ChromaEffectPath = chromaEffectPath;
}
public void Start()
{
Setup();
LoadChromaEffect(ChromaEffectPath);
Thread.Sleep(1000);
chroma.Keyboard.SetKeyAsync(Key.End, Color.Red, false);
Loop();
}
private void LoadChromaEffect(string path)
{
ChromaEffectsReader reader = new ChromaEffectsReader();
EffectRegion[] regions = reader.ReadFirstStatic(path);
Array.ForEach(regions, x => x.Show(chroma));
}
private async void Setup()
{
chroma = await ColoreProvider.CreateNativeAsync();
}
private void Loop()
{
while (true)
{
Thread.Sleep(100);
}
chroma.UninitializeAsync();
}
}
}

30
ChromaEffectsImporter/EffectRegion.cs

@ -0,0 +1,30 @@
using Colore;
using Colore.Data;
using Colore.Effects.Keyboard;
using System;
namespace ChromaEffectsImporter
{
internal class EffectRegion
{
public Key[] Keys { get; private set; }
public Color Color { get; private set; }
public EffectRegion(Key[] keys, Color color)
{
Keys = keys;
Color = color;
}
public EffectRegion(Key keys, Color color)
{
Keys = new Key[] { keys };
Color = color;
}
internal void Show(IChroma chroma)
{
Array.ForEach(Keys, x => chroma.Keyboard.SetKeyAsync(x, Color, false));
}
}
}

20
ChromaEffectsImporter/Program.cs

@ -0,0 +1,20 @@
using System;
using System.IO;
namespace ChromaEffectsImporter
{
internal class Program
{
private static void Main(string[] args)
{
ColoreOutput coloreOutput = new ColoreOutput(ChromaEffects());
coloreOutput.Start();
}
private static string ChromaEffects()
{
string root = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\"));
return Path.Combine(root, "Resources\\ChromaEffects.xml");
}
}
}

35
ChromaEffectsImporter/Properties/AssemblyInfo.cs

@ -0,0 +1,35 @@
using System.Reflection;
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("ChromaEffectsImporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChromaEffectsImporter")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[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("e3050745-702e-4143-a41d-fd549c8c46f9")]
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

1243
ChromaEffectsImporter/Resources/ChromaEffects.xml

File diff suppressed because it is too large Load Diff

11
ChromaEffectsImporter/packages.config

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Colore" version="6.0.0-rc0005" targetFramework="net472" />
<package id="JetBrains.Annotations" version="11.1.0" targetFramework="net472" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net472" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net472" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net472" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net472" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net472" />
</packages>
Loading…
Cancel
Save