mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented admin rights.
This commit is contained in:
parent
9a583764c5
commit
d154e61607
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Security.Principal;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using WpfExceptionViewer;
|
using WpfExceptionViewer;
|
||||||
@ -12,11 +15,42 @@ namespace Artemis
|
|||||||
{
|
{
|
||||||
public App()
|
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();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DoHandle { get; set; }
|
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)
|
private void Application_Startup(object sender, StartupEventArgs e)
|
||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
|
|||||||
@ -118,6 +118,7 @@
|
|||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Autofac, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
|
<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>
|
<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\GameState\GameStateWebServer.cs" />
|
||||||
<Compile Include="Utilities\ImageUtilities.cs" />
|
<Compile Include="Utilities\ImageUtilities.cs" />
|
||||||
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
|
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
|
||||||
|
<Compile Include="Utilities\LogitechDll\DllManager.cs" />
|
||||||
<Compile Include="Utilities\Memory\GamePointer.cs" />
|
<Compile Include="Utilities\Memory\GamePointer.cs" />
|
||||||
<Compile Include="Utilities\Memory\Memory.cs" />
|
<Compile Include="Utilities\Memory\Memory.cs" />
|
||||||
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
|
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
|
||||||
@ -463,6 +465,7 @@
|
|||||||
</Content>
|
</Content>
|
||||||
<Resource Include="Resources\logo.ico" />
|
<Resource Include="Resources\logo.ico" />
|
||||||
<Resource Include="Resources\logo-disabled.ico" />
|
<Resource Include="Resources\logo-disabled.ico" />
|
||||||
|
<None Include="Resources\LogitechLED.dll" />
|
||||||
<Content Include="Resources\Witcher3\playerWitcher.txt" />
|
<Content Include="Resources\Witcher3\playerWitcher.txt" />
|
||||||
<Content Include="Resources\Witcher3\artemis.txt" />
|
<Content Include="Resources\Witcher3\artemis.txt" />
|
||||||
<Resource Include="Resources\Entypo.ttf" />
|
<Resource Include="Resources\Entypo.ttf" />
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Artemis.Utilities.LogitechDll;
|
||||||
using Artemis.ViewModels;
|
using Artemis.ViewModels;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using Caliburn.Micro.Autofac;
|
using Caliburn.Micro.Autofac;
|
||||||
|
using Microsoft.Win32;
|
||||||
using Application = System.Windows.Application;
|
using Application = System.Windows.Application;
|
||||||
using MessageBox = System.Windows.Forms.MessageBox;
|
using MessageBox = System.Windows.Forms.MessageBox;
|
||||||
|
|
||||||
@ -15,7 +18,8 @@ namespace Artemis
|
|||||||
{
|
{
|
||||||
public ArtemisBootstrapper()
|
public ArtemisBootstrapper()
|
||||||
{
|
{
|
||||||
CheckDuplicateInstances();
|
//CheckDuplicateInstances();
|
||||||
|
DllManager.RestoreDll();
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,9 +24,7 @@ namespace Artemis.KeyboardProviders.Logitech
|
|||||||
int majorNum = 0, minorNum = 0, buildNum = 0;
|
int majorNum = 0, minorNum = 0, buildNum = 0;
|
||||||
|
|
||||||
LogitechGSDK.LogiLedInit();
|
LogitechGSDK.LogiLedInit();
|
||||||
LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(KeyboardNames.A, 100, 100, 100);
|
|
||||||
LogitechGSDK.LogiLedGetSdkVersion(ref majorNum, ref minorNum, ref buildNum);
|
LogitechGSDK.LogiLedGetSdkVersion(ref majorNum, ref minorNum, ref buildNum);
|
||||||
LogitechGSDK.LogiLedRestoreLighting();
|
|
||||||
LogitechGSDK.LogiLedShutdown();
|
LogitechGSDK.LogiLedShutdown();
|
||||||
|
|
||||||
// Turn it into one long number...
|
// Turn it into one long number...
|
||||||
|
|||||||
@ -7,11 +7,11 @@ using System.Windows;
|
|||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
|
|
||||||
[assembly: AssemblyTitle("Artemis")]
|
[assembly: AssemblyTitle("Artemis")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("Adds third-party support for RGB keyboards to games")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("Artemis developers")]
|
||||||
[assembly: AssemblyProduct("Artemis")]
|
[assembly: AssemblyProduct("Artemis")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
|||||||
10
Artemis/Artemis/Properties/Resources.Designer.cs
generated
10
Artemis/Artemis/Properties/Resources.Designer.cs
generated
@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -127,6 +127,9 @@
|
|||||||
<data name="gamestateConfiguration" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<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>
|
<value>..\resources\counterstrike\gamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
</data>
|
</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">
|
<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>
|
<value>..\Resources\logo.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
BIN
Artemis/Artemis/Resources/LogitechLED.dll
Normal file
BIN
Artemis/Artemis/Resources/LogitechLED.dll
Normal file
Binary file not shown.
79
Artemis/Artemis/Utilities/LogitechDll/DllManager.cs
Normal file
79
Artemis/Artemis/Utilities/LogitechDll/DllManager.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user