summaryrefslogtreecommitdiff
path: root/wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'wrapper')
-rw-r--r--wrapper/AssemblyInfo.cpp12
-rw-r--r--wrapper/resource.h14
-rw-r--r--wrapper/wrapper.cpp107
-rw-r--r--wrapper/wrapper.rc100
-rw-r--r--wrapper/wrapper.vcxproj19
-rw-r--r--wrapper/wrapper.vcxproj.filters11
-rw-r--r--wrapper/wrapper_io.cpp34
-rw-r--r--wrapper/wrapper_io.hpp8
8 files changed, 282 insertions, 23 deletions
diff --git a/wrapper/AssemblyInfo.cpp b/wrapper/AssemblyInfo.cpp
new file mode 100644
index 0000000..4854fd4
--- /dev/null
+++ b/wrapper/AssemblyInfo.cpp
@@ -0,0 +1,12 @@
+#include <rawaccel-version.h>
+
+using namespace System;
+using namespace System::Reflection;
+using namespace System::Runtime::CompilerServices;
+using namespace System::Runtime::InteropServices;
+using namespace System::Security::Permissions;
+
+[assembly: AssemblyVersion(RA_VER_STRING)]
+
+[assembly:ComVisible(false)] ;
+[assembly:CLSCompliantAttribute(true)] ;
diff --git a/wrapper/resource.h b/wrapper/resource.h
new file mode 100644
index 0000000..e41cd50
--- /dev/null
+++ b/wrapper/resource.h
@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by wrapper.rc
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index ee88112..acd0dbf 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -3,11 +3,15 @@
#include <type_traits>
#include <rawaccel.hpp>
+#include <rawaccel-version.h>
#include "wrapper_io.hpp"
using namespace System;
using namespace System::Runtime::InteropServices;
+using namespace System::Reflection;
+
+using namespace Windows::Forms;
using namespace Newtonsoft::Json;
@@ -129,9 +133,11 @@ using error_list_t = Collections::Generic::List<String^>;
error_list_t^ get_accel_errors(AccelMode mode, AccelArgs^ args)
{
- accel_mode m = (accel_mode)mode;
+ accel_mode mode_native = (accel_mode)mode;
- auto is_mode = [m](auto... modes) { return ((m == modes) || ...); };
+ auto is_mode = [mode_native](auto... modes) {
+ return ((mode_native == modes) || ...);
+ };
using am = accel_mode;
@@ -142,7 +148,7 @@ error_list_t^ get_accel_errors(AccelMode mode, AccelArgs^ args)
else if (args->acceleration == 0 && is_mode(am::naturalgain))
error_list->Add("acceleration must be positive");
else if (args->acceleration < 0) {
- bool additive = m < am::power;
+ bool additive = mode_native < am::power;
if (additive) error_list->Add("acceleration can not be negative, use a negative weight to compensate");
else error_list->Add("acceleration can not be negative");
}
@@ -161,6 +167,9 @@ error_list_t^ get_accel_errors(AccelMode mode, AccelArgs^ args)
if (args->midpoint <= 0)
error_list->Add("midpoint must be positive");
+ if (args->offset < 0)
+ error_list->Add("offset can not be negative");
+
return error_list;
}
@@ -172,7 +181,36 @@ public:
bool Empty()
{
- return x->Count == 0 && y->Count == 0;
+ return (x == nullptr || x->Count == 0) &&
+ (y == nullptr || y->Count == 0);
+ }
+
+ virtual String^ ToString() override
+ {
+ if (x == nullptr) throw;
+
+ Text::StringBuilder^ sb = gcnew Text::StringBuilder();
+
+ if (y == nullptr) // assume combineMagnitudes
+ {
+ for each (String^ str in x)
+ {
+ sb->AppendLine(str);
+ }
+ }
+ else
+ {
+ for each (String^ str in x)
+ {
+ sb->AppendFormat("x: {0}\n", str);
+ }
+ for each (String^ str in y)
+ {
+ sb->AppendFormat("y: {0}\n", str);
+ }
+ }
+
+ return sb->ToString();
}
};
@@ -202,8 +240,9 @@ public ref struct DriverInterop
errors->x = get_accel_errors(args->modes.x, args->args.x);
- if (args->combineMagnitudes) errors->y = gcnew error_list_t();
- else errors->y = get_accel_errors(args->modes.y, args->args.y);
+ if (!args->combineMagnitudes) {
+ errors->y = get_accel_errors(args->modes.y, args->args.y);
+ }
return errors;
}
@@ -274,3 +313,59 @@ public:
return active;
}
};
+
+public ref struct RawAccelVersion
+{
+ literal String^ value = RA_VER_STRING;
+};
+
+public ref struct VersionException : public Exception
+{
+public:
+ VersionException() {}
+ VersionException(String^ what) : Exception(what) {}
+};
+
+Version^ convert(rawaccel::version_t v)
+{
+ return gcnew Version(v.major, v.minor, v.patch, 0);
+}
+
+public ref struct VersionHelper
+{
+
+ static Version^ ValidateAndGetDriverVersion(Version^ wrapperTarget)
+ {
+ Version^ wrapperActual = VersionHelper::typeid->Assembly->GetName()->Version;
+
+ if (wrapperTarget != wrapperActual) {
+ throw gcnew VersionException("version mismatch, expected wrapper.dll v" + wrapperActual);
+ }
+
+ version_t drv_ver;
+
+ try {
+ wrapper_io::getDriverVersion(drv_ver);
+ }
+ catch (DriverNotInstalledException^ ex) {
+ throw gcnew VersionException(ex->Message);
+ }
+ catch (DriverIOException^) {
+ // Assume version ioctl is unimplemented (driver version < v1.3.0)
+ throw gcnew VersionException("driver version is out of date, run installer.exe to reinstall");
+ }
+
+ Version^ drv_ver_managed = convert(drv_ver);
+
+ if (drv_ver_managed < convert(min_driver_version)) {
+ throw gcnew VersionException("driver version is out of date, run installer.exe to reinstall");
+ }
+ else if (drv_ver_managed > wrapperActual) {
+ throw gcnew VersionException("newer driver version is installed");
+ }
+ else {
+ return drv_ver_managed;
+ }
+ }
+
+};
diff --git a/wrapper/wrapper.rc b/wrapper/wrapper.rc
new file mode 100644
index 0000000..edb90d2
--- /dev/null
+++ b/wrapper/wrapper.rc
@@ -0,0 +1,100 @@
+// Microsoft Visual C++ generated resource script.
+//
+#pragma code_page(65001)
+
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "winres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (United States) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""winres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+#include <rawaccel-version.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION RA_VER_MAJOR, RA_VER_MINOR, RA_VER_PATCH
+ PRODUCTVERSION RA_VER_MAJOR, RA_VER_MINOR, RA_VER_PATCH
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "managed interop & I/O"
+ VALUE "FileVersion", RA_VER_STRING
+ VALUE "OriginalFilename", "wrapper.dll"
+ VALUE "ProductName", "Raw Accel"
+ VALUE "ProductVersion", RA_VER_STRING
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+#endif // English (United States) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj
index 6c85a57..4f8ed1c 100644
--- a/wrapper/wrapper.vcxproj
+++ b/wrapper/wrapper.vcxproj
@@ -46,7 +46,12 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@@ -56,6 +61,9 @@
<Link>
<AdditionalDependencies />
</Link>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>$(SolutionDir)/common;</AdditionalIncludeDirectories>
+ </ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -70,11 +78,16 @@
<Command>copy /Y "$(TargetPath)" "$(SolutionDir)signed\$(TargetFileName)" &amp;
copy /Y "$(TargetDir)Newtonsoft.Json.dll" "$(SolutionDir)signed\Newtonsoft.Json.dll"</Command>
</PostBuildEvent>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>$(SolutionDir)/common;</AdditionalIncludeDirectories>
+ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="resource.h" />
<ClInclude Include="wrapper_io.hpp" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="wrapper.cpp" />
<ClCompile Include="wrapper_io.cpp" />
</ItemGroup>
@@ -82,6 +95,10 @@ copy /Y "$(TargetDir)Newtonsoft.Json.dll" "$(SolutionDir)signed\Newtonsoft.Json.
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
+ <Reference Include="System.Windows.Forms" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="wrapper.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/wrapper/wrapper.vcxproj.filters b/wrapper/wrapper.vcxproj.filters
index 88e539f..f265d72 100644
--- a/wrapper/wrapper.vcxproj.filters
+++ b/wrapper/wrapper.vcxproj.filters
@@ -18,6 +18,9 @@
<ClInclude Include="wrapper_io.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="resource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="wrapper.cpp">
@@ -26,5 +29,13 @@
<ClCompile Include="wrapper_io.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="AssemblyInfo.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="wrapper.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/wrapper/wrapper_io.cpp b/wrapper/wrapper_io.cpp
index 0f257bf..4b77174 100644
--- a/wrapper/wrapper_io.cpp
+++ b/wrapper/wrapper_io.cpp
@@ -3,11 +3,10 @@
#include <rawaccel-io.hpp>
#include "wrapper_io.hpp"
-void wrapper_io::writeToDriver(const settings& args)
-{
- try
+auto with_managed_ex = [](auto fn) {
+ try
{
- write(args);
+ fn();
}
catch (const install_error&)
{
@@ -17,20 +16,25 @@ void wrapper_io::writeToDriver(const settings& args)
{
throw gcnew DriverIOException(gcnew String(e.what()));
}
+};
+
+void wrapper_io::writeToDriver(const settings& args)
+{
+ with_managed_ex([&] {
+ write(args);
+ });
}
void wrapper_io::readFromDriver(settings& args)
{
- try
- {
+ with_managed_ex([&] {
args = read();
- }
- catch (const install_error&)
- {
- throw gcnew DriverNotInstalledException();
- }
- catch (const std::system_error& e)
- {
- throw gcnew DriverIOException(gcnew String(e.what()));
- }
+ });
+}
+
+void wrapper_io::getDriverVersion(version_t& ver)
+{
+ with_managed_ex([&] {
+ ver = get_version();
+ });
}
diff --git a/wrapper/wrapper_io.hpp b/wrapper/wrapper_io.hpp
index 19f096f..6b94e46 100644
--- a/wrapper/wrapper_io.hpp
+++ b/wrapper/wrapper_io.hpp
@@ -1,6 +1,8 @@
#pragma once
+#include <rawaccel-error.hpp>
#include <rawaccel-settings.h>
+#include <rawaccel-version.h>
using namespace rawaccel;
using namespace System;
@@ -8,6 +10,7 @@ using namespace System;
struct wrapper_io {
static void writeToDriver(const settings&);
static void readFromDriver(settings&);
+ static void getDriverVersion(version_t&);
};
public ref struct DriverIOException : public IO::IOException {
@@ -16,4 +19,7 @@ public:
DriverIOException(String^ what) : IO::IOException(what) {}
};
-public ref struct DriverNotInstalledException : public DriverIOException {};
+public ref struct DriverNotInstalledException : public DriverIOException {
+ DriverNotInstalledException() :
+ DriverIOException(gcnew String(install_error().what())) {}
+};