1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Implemented admin rights.

This commit is contained in:
SpoinkyNL 2016-03-09 19:17:55 +01:00
parent 9a583764c5
commit d154e61607
9 changed files with 140 additions and 9 deletions

View File

@ -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;

View File

@ -118,6 +118,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="Autofac, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.0.0-rc1-177\lib\net45\Autofac.dll</HintPath>
@ -344,6 +345,7 @@
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
<Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\LogitechDll\DllManager.cs" />
<Compile Include="Utilities\Memory\GamePointer.cs" />
<Compile Include="Utilities\Memory\Memory.cs" />
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
@ -463,6 +465,7 @@
</Content>
<Resource Include="Resources\logo.ico" />
<Resource Include="Resources\logo-disabled.ico" />
<None Include="Resources\LogitechLED.dll" />
<Content Include="Resources\Witcher3\playerWitcher.txt" />
<Content Include="Resources\Witcher3\artemis.txt" />
<Resource Include="Resources\Entypo.ttf" />

View File

@ -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();
}

View File

@ -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...

View File

@ -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("")]

View File

@ -113,6 +113,16 @@ namespace Artemis.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] LogitechLED {
get {
object obj = ResourceManager.GetObject("LogitechLED", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View File

@ -127,6 +127,9 @@
<data name="gamestateConfiguration" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\counterstrike\gamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="LogitechLED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LogitechLED.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

View File

@ -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");
}
}
}