diff --git a/Artemis/Artemis/App.xaml.cs b/Artemis/Artemis/App.xaml.cs
index 29b2f9489..4dc135af8 100644
--- a/Artemis/Artemis/App.xaml.cs
+++ b/Artemis/Artemis/App.xaml.cs
@@ -1,4 +1,7 @@
using System;
+using System.Diagnostics;
+using System.Reflection;
+using System.Security.Principal;
using System.Windows;
using System.Windows.Threading;
using WpfExceptionViewer;
@@ -12,11 +15,42 @@ namespace Artemis
{
public App()
{
+ if (!IsRunAsAdministrator())
+ {
+ var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
+
+ // The following properties run the new process as administrator
+ processInfo.UseShellExecute = true;
+ processInfo.Verb = "runas";
+
+ // Start the new process
+ try
+ {
+ Process.Start(processInfo);
+ }
+ catch (Exception)
+ {
+ // The user did not allow the application to run as administrator
+ MessageBox.Show("Sorry, this application must be run as Administrator.");
+ }
+
+ // Shut down the current process
+ Environment.Exit(0);
+ }
+
InitializeComponent();
}
public bool DoHandle { get; set; }
+ private bool IsRunAsAdministrator()
+ {
+ var wi = WindowsIdentity.GetCurrent();
+ var wp = new WindowsPrincipal(wi);
+
+ return wp.IsInRole(WindowsBuiltInRole.Administrator);
+ }
+
private void Application_Startup(object sender, StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj
index 16aba318b..7962bd8fc 100644
--- a/Artemis/Artemis/Artemis.csproj
+++ b/Artemis/Artemis/Artemis.csproj
@@ -118,6 +118,7 @@
MinimumRecommendedRules.ruleset
true
+
..\packages\Autofac.4.0.0-rc1-177\lib\net45\Autofac.dll
@@ -344,6 +345,7 @@
+
@@ -463,6 +465,7 @@
+
diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs
index e6f178e51..934a41e27 100644
--- a/Artemis/Artemis/ArtemisBootstrapper.cs
+++ b/Artemis/Artemis/ArtemisBootstrapper.cs
@@ -1,11 +1,14 @@
-using System.Diagnostics;
+using System;
+using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
+using Artemis.Utilities.LogitechDll;
using Artemis.ViewModels;
using Autofac;
using Caliburn.Micro;
using Caliburn.Micro.Autofac;
+using Microsoft.Win32;
using Application = System.Windows.Application;
using MessageBox = System.Windows.Forms.MessageBox;
@@ -15,7 +18,8 @@ namespace Artemis
{
public ArtemisBootstrapper()
{
- CheckDuplicateInstances();
+ //CheckDuplicateInstances();
+ DllManager.RestoreDll();
Initialize();
}
diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs
index 3bd6fdb74..ffdf2bba0 100644
--- a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs
+++ b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs
@@ -10,9 +10,9 @@ namespace Artemis.KeyboardProviders.Logitech
public Orion()
{
Name = "Logitech G910 RGB";
- CantEnableText = "Couldn't connect to your Logitech G910.\n " +
+ CantEnableText = "Couldn't connect to your Logitech G910.\n" +
"Please check your cables and updating the Logitech Gaming Software\n" +
- "A minimum version of 8.81.15 is required).\n\n " +
+ "A minimum version of 8.81.15 is required).\n\n" +
"If needed, you can select a different keyboard in Artemis under settings.";
Height = 6;
Width = 21;
@@ -24,9 +24,7 @@ namespace Artemis.KeyboardProviders.Logitech
int majorNum = 0, minorNum = 0, buildNum = 0;
LogitechGSDK.LogiLedInit();
- LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(KeyboardNames.A, 100, 100, 100);
LogitechGSDK.LogiLedGetSdkVersion(ref majorNum, ref minorNum, ref buildNum);
- LogitechGSDK.LogiLedRestoreLighting();
LogitechGSDK.LogiLedShutdown();
// Turn it into one long number...
diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs
index e40d120b9..9ae859273 100644
--- a/Artemis/Artemis/Properties/AssemblyInfo.cs
+++ b/Artemis/Artemis/Properties/AssemblyInfo.cs
@@ -7,11 +7,11 @@ using System.Windows;
// associated with an assembly.
[assembly: AssemblyTitle("Artemis")]
-[assembly: AssemblyDescription("")]
+[assembly: AssemblyDescription("Adds third-party support for RGB keyboards to games")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
+[assembly: AssemblyCompany("Artemis developers")]
[assembly: AssemblyProduct("Artemis")]
-[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/Artemis/Artemis/Properties/Resources.Designer.cs b/Artemis/Artemis/Properties/Resources.Designer.cs
index 1d5940ce5..11d05e356 100644
--- a/Artemis/Artemis/Properties/Resources.Designer.cs
+++ b/Artemis/Artemis/Properties/Resources.Designer.cs
@@ -113,6 +113,16 @@ namespace Artemis.Properties {
}
}
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] LogitechLED {
+ get {
+ object obj = ResourceManager.GetObject("LogitechLED", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
///
diff --git a/Artemis/Artemis/Properties/Resources.resx b/Artemis/Artemis/Properties/Resources.resx
index 1fa4c4c83..e1b6a705c 100644
--- a/Artemis/Artemis/Properties/Resources.resx
+++ b/Artemis/Artemis/Properties/Resources.resx
@@ -127,6 +127,9 @@
..\resources\counterstrike\gamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
+
+ ..\Resources\LogitechLED.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
..\Resources\logo.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
diff --git a/Artemis/Artemis/Resources/LogitechLED.dll b/Artemis/Artemis/Resources/LogitechLED.dll
new file mode 100644
index 000000000..9ecba3c77
Binary files /dev/null and b/Artemis/Artemis/Resources/LogitechLED.dll differ
diff --git a/Artemis/Artemis/Utilities/LogitechDll/DllManager.cs b/Artemis/Artemis/Utilities/LogitechDll/DllManager.cs
new file mode 100644
index 000000000..af0782908
--- /dev/null
+++ b/Artemis/Artemis/Utilities/LogitechDll/DllManager.cs
@@ -0,0 +1,79 @@
+using System.IO;
+using Artemis.Properties;
+using Microsoft.Win32;
+
+namespace Artemis.Utilities.LogitechDll
+{
+ internal static class DllManager
+ {
+ public static void RestoreDll()
+ {
+ if (!BackupAvailable())
+ return;
+
+ // Get rid of our own DLL
+ File.Delete(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll");
+ // Restore the backup
+ File.Move(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll.bak",
+ @"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll");
+ }
+
+ public static void PlaceDll()
+ {
+ if (DllPlaced())
+ return;
+
+ // Create directory structure, just in case
+ Directory.CreateDirectory(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64");
+
+ // Remove old backups if they are there
+ if (BackupAvailable())
+ File.Delete(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll.bak");
+
+ // Backup the existing DLL
+ if (File.Exists(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll"))
+ File.Move(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll",
+ @"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll.bak");
+
+ // Copy our own DLL in place
+ File.WriteAllBytes(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLED.dll",
+ Resources.LogitechLED);
+
+ // If the user doesn't have a Logitech device, the CLSID will be missing
+ // and we should create it ourselves.
+ if (!RegistryKeyPlaced())
+ PlaceRegistryKey();
+ }
+
+ public static bool DllPlaced()
+ {
+ if (!Directory.Exists(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64"))
+ return false;
+ if (!RegistryKeyPlaced())
+ return false;
+
+ return File.Exists(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll");
+ }
+
+ private static bool BackupAvailable()
+ {
+ return File.Exists(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll.bak");
+ }
+
+ private static bool RegistryKeyPlaced()
+ {
+ var key = Registry
+ .LocalMachine.OpenSubKey(
+ @"SOFTWARE\Classes\CLSID\{a6519e67-7632-4375-afdf-caa889744403}\ServerBinary");
+ return key != null;
+ }
+
+ private static void PlaceRegistryKey()
+ {
+ var key = Registry
+ .LocalMachine.OpenSubKey(
+ @"SOFTWARE\Classes\CLSID\{a6519e67-7632-4375-afdf-caa889744403}\ServerBinary", true);
+ key?.SetValue(null, @"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll");
+ }
+ }
+}
\ No newline at end of file