1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00
This commit is contained in:
Logan Saso 2016-03-10 01:04:56 -08:00
commit f60fb8d1a6
11 changed files with 121 additions and 73 deletions

View File

@ -1,9 +1,7 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
using System.Windows;
using System.Windows.Threading;
using Artemis.Utilities;
using WpfExceptionViewer;
namespace Artemis
@ -15,42 +13,14 @@ 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);
}
if (!GeneralHelpers.IsRunAsAdministrator())
GeneralHelpers.RunAsAdministrator();
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

@ -163,6 +163,10 @@
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="NamedPipeWrapper, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NamedPipeWrapper.1.4.0\lib\net40\NamedPipeWrapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.7.3\lib\net35\NAudio.dll</HintPath>
<Private>True</Private>
@ -271,12 +275,15 @@
<DependentUpon>AmbientLightningEffectView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\Effects\AmbientLightning\AmbientLightningEffectViewModel.cs" />
<Compile Include="Modules\Effects\AmbientLightning\ScreenCapture.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualization.Designer.cs">
<DependentUpon>AudioVisualization.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\Utilities\FftEventArgs.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\Utilities\SampleAggregator.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectModel.cs" />
<Compile Include="Modules\Effects\TypeHole\TypeHoleModel.cs" />
<Compile Include="Modules\Effects\TypeWave\TypeWave.Designer.cs">
@ -346,21 +353,20 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Offsets.settings</DependentUpon>
</Compile>
<Compile Include="Utilities\Audio\FftEventArgs.cs" />
<Compile Include="Utilities\Audio\SampleAggregator.cs" />
<Compile Include="Utilities\ColorHelpers.cs" />
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
<Compile Include="Utilities\GeneralHelpers.cs" />
<Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\LogitechDll\DllManager.cs" />
<Compile Include="Utilities\LogitechDll\LogitechNamedPipe.cs" />
<Compile Include="Utilities\Memory\GamePointer.cs" />
<Compile Include="Utilities\Memory\Memory.cs" />
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
<Compile Include="Utilities\Memory\Win32.cs" />
<Compile Include="Utilities\Keyboard\Key.cs" />
<Compile Include="Utilities\Keyboard\KeyboardRectangle.cs" />
<Compile Include="Utilities\ScreenCapture.cs" />
<Compile Include="Utilities\ShellLink.cs" />
<Compile Include="Utilities\Updater.cs" />
<Compile Include="ViewModels\Abstract\EffectViewModel.cs" />

View File

@ -1,14 +1,13 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using Artemis.Utilities;
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;
@ -18,8 +17,10 @@ namespace Artemis
{
public ArtemisBootstrapper()
{
//CheckDuplicateInstances();
DllManager.RestoreDll();
CheckDuplicateInstances();
if (DllManager.RestoreDll())
GeneralHelpers.RunAsAdministrator();
Initialize();
}

View File

@ -13,7 +13,7 @@ using MapFlags = SharpDX.DXGI.MapFlags;
using Resource = SharpDX.DXGI.Resource;
using ResultCode = SharpDX.DXGI.ResultCode;
namespace Artemis.Utilities
namespace Artemis.Modules.Effects.AmbientLightning
{
internal class ScreenCapture : IDisposable
{

View File

@ -5,8 +5,8 @@ using System.Drawing.Drawing2D;
using System.Linq;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Modules.Effects.AudioVisualizer.Utilities;
using Artemis.Utilities;
using Artemis.Utilities.Audio;
using Artemis.Utilities.Keyboard;
using NAudio.CoreAudioApi;
using NAudio.Wave;

View File

@ -1,8 +1,8 @@
using System;
using System.Diagnostics;
using NAudio.Dsp;
namespace Artemis.Utilities.Audio
using System;
using System.Diagnostics;
using NAudio.Dsp;
namespace Artemis.Modules.Effects.AudioVisualizer.Utilities
{
public class FftEventArgs : EventArgs
{

View File

@ -1,7 +1,7 @@
using System;
using NAudio.Dsp;
namespace Artemis.Utilities.Audio
using System;
using NAudio.Dsp;
namespace Artemis.Modules.Effects.AudioVisualizer.Utilities
{ // The Complex and FFT are here!
public class SampleAggregator

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Artemis.Utilities
{
public static class GeneralHelpers
{
public static void RunAsAdministrator()
{
var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)
{
UseShellExecute = true,
Verb = "runas"
};
// The following properties run the new process as administrator
// 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);
}
public static bool IsRunAsAdministrator()
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);
return wp.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}

View File

@ -6,16 +6,20 @@ namespace Artemis.Utilities.LogitechDll
{
internal static class DllManager
{
public static void RestoreDll()
private const string LogitechPath = @"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\";
public static bool RestoreDll()
{
if (!BackupAvailable())
return;
if (!File.Exists(LogitechPath + @"\LogitechLed.dll.bak"))
return false;
// Get rid of our own DLL
File.Delete(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll");
File.Delete(LogitechPath + @"\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");
File.Move(LogitechPath + @"\LogitechLed.dll.bak",
LogitechPath + @"\LogitechLed.dll");
return true;
}
public static void PlaceDll()
@ -24,19 +28,19 @@ namespace Artemis.Utilities.LogitechDll
return;
// Create directory structure, just in case
Directory.CreateDirectory(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64");
Directory.CreateDirectory(LogitechPath + @"");
// Remove old backups if they are there
if (BackupAvailable())
File.Delete(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLed.dll.bak");
if (File.Exists(LogitechPath + @"\LogitechLed.dll.bak"))
File.Delete(LogitechPath + @"\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");
if (File.Exists(LogitechPath + @"\LogitechLed.dll"))
File.Move(LogitechPath + @"\LogitechLed.dll",
LogitechPath + @"\LogitechLed.dll.bak");
// Copy our own DLL in place
File.WriteAllBytes(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64\LogitechLED.dll",
File.WriteAllBytes(LogitechPath + @"\LogitechLED.dll",
Resources.LogitechLED);
// If the user doesn't have a Logitech device, the CLSID will be missing
@ -47,17 +51,12 @@ namespace Artemis.Utilities.LogitechDll
public static bool DllPlaced()
{
if (!Directory.Exists(@"C:\Program Files\Logitech Gaming Software\SDK\LED\x64"))
if (!Directory.Exists(LogitechPath + @""))
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");
return File.Exists(LogitechPath + @"\LogitechLed.dll");
}
private static bool RegistryKeyPlaced()
@ -73,7 +72,7 @@ namespace Artemis.Utilities.LogitechDll
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");
key?.SetValue(null, LogitechPath + @"\LogitechLed.dll");
}
}
}

View File

@ -0,0 +1,23 @@
using System.Diagnostics;
using NamedPipeWrapper;
namespace Artemis.Utilities.LogitechDll
{
public class LogitechNamedPipe
{
public LogitechNamedPipe()
{
LogitechPipe = new NamedPipeServer<string>("ArtemisLogitech");
LogitechPipe.ClientMessage += LogitechPipeOnClientMessage;
LogitechPipe.Start();
}
public NamedPipeServer<string> LogitechPipe { get; set; }
private void LogitechPipeOnClientMessage(NamedPipeConnection<string, string> connection, string message)
{
Debug.WriteLine(message);
}
}
}

View File

@ -12,6 +12,7 @@
<package id="log4net" version="2.0.5" targetFramework="net452" />
<package id="MahApps.Metro" version="1.2.4.0" targetFramework="net452" />
<package id="MahApps.Metro.Resources" version="0.4.0.0" targetFramework="net452" />
<package id="NamedPipeWrapper" version="1.4.0" targetFramework="net452" />
<package id="NAudio" version="1.7.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
<package id="SharpDX" version="3.0.1" targetFramework="net452" />