Skip to content

Commit

Permalink
Merge pull request #29 from luttje/feature-cmd-line
Browse files Browse the repository at this point in the history
Command-Line + Installer (v0.6.0)
  • Loading branch information
luttje authored Mar 4, 2023
2 parents 6ae254d + ddb0ee4 commit fe638f3
Show file tree
Hide file tree
Showing 244 changed files with 4,191 additions and 1,506 deletions.
2 changes: 1 addition & 1 deletion BuildDocumentation.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

SET LOCAL=%~dp0
set TARGET=bin\Release
%LOCAL%BuildMarkdownDocs\%TARGET%\BuildMarkdownDocs.exe %LOCAL%Key2Joy\%TARGET%\Key2Joy.xml %LOCAL%Docs --filter markdown-doc
%LOCAL%BuildMarkdownDocs\%TARGET%\BuildMarkdownDocs.exe %LOCAL%bin\Release\Key2Joy\Key2Joy.xml %LOCAL%Docs --filter markdown-doc
26 changes: 23 additions & 3 deletions BuildMarkdownDocs/BuildMarkdownDocs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -67,9 +87,9 @@
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Key2Joy\Key2Joy.csproj">
<Project>{808ba609-806d-4d55-857b-6fb4e16e13f1}</Project>
<Name>Key2Joy</Name>
<ProjectReference Include="..\Key2Joy\Key2Joy.Core.csproj">
<Project>{1a961914-67b8-4b11-80d4-280323bc7b25}</Project>
<Name>Key2Joy.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion BuildMarkdownDocs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void Main(string[] args)
}

// TODO: This is hacky, but it works.
TypeUtil.NotifyAssemblyRelation(typeof(Key2Joy.Program));
TypeUtil.NotifyAssemblyRelation(typeof(Key2Joy.Key2JoyManager));

MarkdownDocs.Build(xmlFile, outputDirectory, template, filter);
}
Expand Down
4 changes: 2 additions & 2 deletions BuildMarkdownDocs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
2 changes: 2 additions & 0 deletions Docs/Api/Enumerations/Buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
* `Left`
* `Right`
* `Middle`
* `XButton1`
* `XButton2`
* `WheelUp`
* `WheelDown`
18 changes: 18 additions & 0 deletions Key2Joy.Cmd/App.config
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>
29 changes: 29 additions & 0 deletions Key2Joy.Cmd/DisableOptions.cs
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();
});
}
}
}
}
48 changes: 48 additions & 0 deletions Key2Joy.Cmd/EnableOptions.cs
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();
});
}
}
}
}
105 changes: 105 additions & 0 deletions Key2Joy.Cmd/Key2Joy.Cmd.csproj
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>
21 changes: 21 additions & 0 deletions Key2Joy.Cmd/Options.cs
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();
}
}
}
39 changes: 39 additions & 0 deletions Key2Joy.Cmd/Program.cs
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");
}
}
}
}
38 changes: 38 additions & 0 deletions Key2Joy.Cmd/Properties/AssemblyInfo.cs
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")]
Loading

0 comments on commit fe638f3

Please sign in to comment.