-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from luttje/feature-cmd-line
Command-Line + Installer (v0.6.0)
- Loading branch information
Showing
244 changed files
with
4,191 additions
and
1,506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,7 @@ | |
* `Left` | ||
* `Right` | ||
* `Middle` | ||
* `XButton1` | ||
* `XButton2` | ||
* `WheelUp` | ||
* `WheelDown` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> | ||
</startup> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.2" newVersion="6.0.0.2" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using CommandLine; | ||
using System; | ||
using Key2Joy.Interop; | ||
|
||
namespace Key2Joy.Cmd | ||
{ | ||
[Verb("disable", HelpText = "Disable whichever mapping profile is active.")] | ||
internal class DisableOptions : Options | ||
{ | ||
public override void Handle() | ||
{ | ||
try | ||
{ | ||
InteropClient.Instance.SendCommand(new DisableCommand()); | ||
|
||
Console.WriteLine("Commanded Key2Joy to disable the active profile."); | ||
} | ||
catch (TimeoutException) | ||
{ | ||
SafelyRetry(() => | ||
{ | ||
Console.WriteLine("Key2Joy is not running, starting it now..."); | ||
Key2JoyManager.StartKey2Joy(); | ||
Handle(); | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using CommandLine; | ||
using System; | ||
using Key2Joy.Interop; | ||
using Key2Joy.Mapping; | ||
|
||
namespace Key2Joy.Cmd | ||
{ | ||
[Verb("enable", HelpText = "Enable the provided mapping profile.")] | ||
internal class EnableOptions : Options | ||
{ | ||
[Option( | ||
shortName: 'p', | ||
longName: "profile", | ||
Required = false, | ||
HelpText = "Path of the profile to load or modify. Path can be relative to profile directory. By default the last used profile is selected (if available)." | ||
)] | ||
public string ProfilePath { get; set; } | ||
|
||
public override void Handle() | ||
{ | ||
MappingProfile profile; | ||
|
||
if (ProfilePath != null) | ||
profile = MappingProfile.Load(ProfilePath); | ||
else | ||
profile = MappingProfile.RestoreLastLoaded(); | ||
|
||
try | ||
{ | ||
InteropClient.Instance.SendCommand(new EnableCommand | ||
{ | ||
ProfilePath = profile.FilePath | ||
}); | ||
|
||
Console.WriteLine($"Commanded Key2Joy to enable the profile: {profile.FilePath}"); | ||
} | ||
catch(TimeoutException) | ||
{ | ||
SafelyRetry(() => | ||
{ | ||
Console.WriteLine("Key2Joy is not running, starting it now..."); | ||
Key2JoyManager.StartKey2Joy(); | ||
Handle(); | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?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>{FF955F62-E00D-46F4-A945-6677DF10FCA2}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>Key2Joy.Cmd</RootNamespace> | ||
<AssemblyName>Key2Joy.Cmd</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\bin\Debug\Key2Joy.Cmd\</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\Key2Joy.Cmd\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>Resources\app-icons.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>..\bin\x86\Debug\Key2Joy.Cmd\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<LangVersion>latest</LangVersion> | ||
<ErrorReport>prompt</ErrorReport> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> | ||
<OutputPath>..\bin\x86\Release\Key2Joy.Cmd\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<LangVersion>latest</LangVersion> | ||
<ErrorReport>prompt</ErrorReport> | ||
<Prefer32Bit>true</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CommandLine, Version=2.9.1.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<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="DisableOptions.cs" /> | ||
<Compile Include="EnableOptions.cs" /> | ||
<Compile Include="Options.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Key2Joy\Key2Joy.Core.csproj"> | ||
<Project>{1a961914-67b8-4b11-80d4-280323bc7b25}</Project> | ||
<Name>Key2Joy.Core</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\app-icons.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace Key2Joy.Cmd | ||
{ | ||
internal abstract class Options | ||
{ | ||
const int MAX_RETRIES = 1; | ||
|
||
abstract public void Handle(); | ||
|
||
protected int retries = 0; | ||
|
||
protected void SafelyRetry(Action value) | ||
{ | ||
if (++retries > MAX_RETRIES) | ||
return; | ||
|
||
value(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Key2Joy.Config; | ||
using System; | ||
using System.Linq; | ||
using CommandLine; | ||
using System.Reflection; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
|
||
namespace Key2Joy.Cmd | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var types = LoadVerbs(); | ||
|
||
Parser.Default.ParseArguments(args, types) | ||
.WithParsed(Run); | ||
} | ||
|
||
private static Type[] LoadVerbs() | ||
{ | ||
return Assembly.GetExecutingAssembly().GetTypes() | ||
.Where(t => t.GetCustomAttribute<VerbAttribute>() != null).ToArray(); | ||
} | ||
|
||
private static void Run(object obj) | ||
{ | ||
if (obj is Options options) | ||
{ | ||
options.Handle(); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Unknown command"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
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("Key2Joy (CLI)")] | ||
[assembly: AssemblyDescription("Control Key2Joy from the command line")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Lutt.online")] | ||
[assembly: AssemblyProduct("Key2Joy")] | ||
[assembly: AssemblyCopyright("Copyright © 2022 - 2023 Luttje")] | ||
[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("ff955f62-e00d-46f4-a945-6677df10fca2")] | ||
|
||
// 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("0.6.0.0")] | ||
[assembly: AssemblyFileVersion("0.6.0.0")] | ||
[assembly: NeutralResourcesLanguage("en")] |
Oops, something went wrong.